Skip to content

Commit

Permalink
#315 download sources with double asterisk
Browse files Browse the repository at this point in the history
  • Loading branch information
yzerk committed Mar 3, 2023
1 parent 6cb77f4 commit fd9af16
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/crowdin/cli/utils/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ static Stream<Arguments> 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%"),
Expand Down

0 comments on commit fd9af16

Please sign in to comment.