diff --git a/src/main/java/com/crowdin/cli/commands/functionality/TranslationsUtils.java b/src/main/java/com/crowdin/cli/commands/functionality/TranslationsUtils.java index cb7b143ed..4c5e98c50 100644 --- a/src/main/java/com/crowdin/cli/commands/functionality/TranslationsUtils.java +++ b/src/main/java/com/crowdin/cli/commands/functionality/TranslationsUtils.java @@ -27,8 +27,9 @@ public static String replaceDoubleAsterisk(String sourcePattern, String translat sourcePattern = StringUtils.removeStart(sourcePattern, Utils.PATH_SEPARATOR); String[] sourceNodes = sourcePattern.split("\\*\\*"); for (int i = 0; i < sourceNodes.length; i++) { - if (sourceFile.startsWith(sourceNodes[i])) { - sourceFile = sourceFile.replaceFirst(Utils.regexPath(sourceNodes[i]), ""); + if (sourceFile.contains(sourceNodes[i])) { + sourceFile = StringUtils.substring(sourceFile, sourceFile.indexOf(Utils.regexPath(sourceNodes[i])), sourceFile.length()-1) + .replaceFirst(Utils.regexPath(sourceNodes[i]), ""); } else if (sourceNodes.length - 1 == i) { if (sourceNodes[i].contains(Utils.PATH_SEPARATOR)) { String[] sourceNodesTmp = sourceNodes[i].split(Utils.PATH_SEPARATOR_REGEX); @@ -50,7 +51,7 @@ public static String replaceDoubleAsterisk(String sourcePattern, String translat } } } - translationPattern = translationPattern.replace(sourceNodes[0] + "**", sourceFile); + translationPattern = translationPattern.replace("**", sourceFile); translationPattern = translationPattern.replaceAll(Utils.PATH_SEPARATOR_REGEX + "+", Utils.PATH_SEPARATOR_REGEX); return translationPattern; } diff --git a/src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java b/src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java index a1b90f254..a7a5c4da4 100644 --- a/src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java +++ b/src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java @@ -187,8 +187,11 @@ public String replaceFileDependentPlaceholders(String toFormat, File file) { toFormat = toFormat.contains(PLACEHOLDER_ORIGINAL_PATH) ? toFormat.replace(PLACEHOLDER_ORIGINAL_PATH, fileParent) : toFormat; if (toFormat.contains("**")) { - String replacement = fileParent.substring(fileParent.lastIndexOf(Utils.noSepAtEnd(Utils.noSepAtStart(StringUtils.substringBefore(toFormat, "**"))))); - toFormat = toFormat.replace(toFormat.substring(0, toFormat.indexOf("**")+2), replacement.isEmpty() ? fileParent : replacement); + String prefix = StringUtils.substringBefore(toFormat, "**"); + prefix = prefix.length()>1 && file.getPath().contains(prefix) ? StringUtils.substringBefore(fileParent,prefix) : ""; + String doubleAsterisks = + StringUtils.removeStart(StringUtils.removeStart(fileParent, prefix), Utils.noSepAtEnd(Utils.noSepAtStart(StringUtils.substringBefore(toFormat, "**")))); + toFormat = toFormat.replace("**", doubleAsterisks); } toFormat = toFormat.replaceAll("[\\\\/]+", Utils.PATH_SEPARATOR_REGEX); diff --git a/src/test/java/com/crowdin/cli/commands/functionality/TranslationsUtilsTest.java b/src/test/java/com/crowdin/cli/commands/functionality/TranslationsUtilsTest.java index 6196eb4a1..c5c1839b3 100644 --- a/src/test/java/com/crowdin/cli/commands/functionality/TranslationsUtilsTest.java +++ b/src/test/java/com/crowdin/cli/commands/functionality/TranslationsUtilsTest.java @@ -41,6 +41,11 @@ static Stream testReplaceDoubleAsterisk() { Utils.normalizePath("/%locale%/%original_file_name%"), Utils.normalizePath("f1/android.xml"), Utils.normalizePath("/%locale%/%original_file_name%")), + arguments( + Utils.normalizePath("/folder1/folder2/**/messages.properties"), + Utils.normalizePath("/folder1/folder2/**/%file_name%_%two_letters_code%.properties"), + Utils.normalizePath("/folder_on_crowdin/folder1/folder2/folder3/folder4/messages.properties"), + Utils.normalizePath("/folder1/folder2/folder3/folder4/%file_name%_%two_letters_code%.properties")), arguments( Utils.normalizePath("/home/daanya/Documents/**/*.txt"), Utils.normalizePath("/**/%locale%/%original_file_name%"),