Skip to content

Commit 179e701

Browse files
authored
feat: option to skip special chars escape (#144)
1 parent 12394ab commit 179e701

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ files:
173173
cleanup_mode: true
174174
```
175175

176+
It's also possible to disable escaping special characters (`=`, `:`, `!` and `#`):
177+
178+
```yml
179+
files:
180+
- source: "**/values/strings.xml"
181+
translation: "/values-%two_letters_code%/%original_file_name%"
182+
escape_special_characters: 0
183+
```
184+
176185
##### Translations upload options
177186

178187
The following properties can be used to configure the import options for uploaded translations:

src/main/java/com/crowdin/client/config/CrowdinPropertiesLoader.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class CrowdinPropertiesLoader {
3737
private static final String PROPERTY_FILES_CLEANUP_MODE = "cleanup_mode";
3838
private static final String PROPERTY_FILES_UPDATE_STRINGS = "update_strings";
3939
private static final String PROPERTY_EXCLUDED_TARGET_LANGUAGES = "excluded_target_languages";
40+
private static final String PROPERTY_ESCAPE_SPECIAL_CHARACTERS = "escape_special_characters";
4041

4142
private static final Pattern BASE_URL_PATTERN = Pattern.compile("^(https://([a-zA-Z0-9_-]+\\.(api\\.)?)?crowdin\\.com/?|http://(.+)\\.dev\\.crowdin\\.com/?)$");
4243

@@ -182,6 +183,7 @@ private static List<FileBean> getSourcesWithTranslations(Map<String, Object> pro
182183
String translation = getStringProperty(file, PROPERTY_FILES_TRANSLATION);
183184
Boolean updateStrings = getBooleanProperty(file, PROPERTY_FILES_UPDATE_STRINGS);
184185
Boolean cleanupMode = getBooleanProperty(file, PROPERTY_FILES_CLEANUP_MODE);
186+
Integer escapeSpecialCharacters = getIntegerProperty(file, PROPERTY_ESCAPE_SPECIAL_CHARACTERS);
185187
List<String> labels = getListStringsProperty(file, PROPERTY_LABELS);
186188
List<String> excludedTargetLanguages = getListStringsProperty(file, PROPERTY_EXCLUDED_TARGET_LANGUAGES);
187189

@@ -193,6 +195,7 @@ private static List<FileBean> getSourcesWithTranslations(Map<String, Object> pro
193195
fb.setExcludedTargetLanguages(excludedTargetLanguages);
194196
fb.setUpdateStrings(updateStrings);
195197
fb.setCleanupMode(cleanupMode);
198+
fb.setEscapeSpecialCharacters(escapeSpecialCharacters);
196199
fileBeans.add(fb);
197200
} else if (StringUtils.isEmpty(source)) {
198201
errors.add(String.format(MESSAGES_BUNDLE.getString("errors.config.missing_property"), PROPERTY_FILES_SOURCE));
@@ -209,6 +212,10 @@ private static String getStringProperty(Map<String, Object> map, String property
209212
return getProperty(map, property, String.class);
210213
}
211214

215+
private static Integer getIntegerProperty(Map<String, Object> map, String property) {
216+
return getProperty(map, property, Integer.class);
217+
}
218+
212219
private static List<String> getListStringsProperty(Map<String, Object> map, String property) {
213220
List list = getProperty(map, property, List.class);
214221
if (list == null) {

src/main/java/com/crowdin/client/config/FileBean.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class FileBean {
1111
private List<String> labels;
1212
private Boolean cleanupMode;
1313
private Boolean updateStrings;
14+
private Integer escapeSpecialCharacters;
1415

1516
public String getSource() {
1617
return source;
@@ -60,17 +61,25 @@ public void setUpdateStrings(Boolean updateStrings) {
6061
this.updateStrings = updateStrings;
6162
}
6263

64+
public Integer getEscapeSpecialCharacters() {
65+
return escapeSpecialCharacters;
66+
}
67+
68+
public void setEscapeSpecialCharacters(Integer escapeSpecialCharacters) {
69+
this.escapeSpecialCharacters = escapeSpecialCharacters;
70+
}
71+
6372
@Override
6473
public boolean equals(Object o) {
6574
if (this == o) return true;
6675
if (o == null || getClass() != o.getClass()) return false;
6776
FileBean fileBean = (FileBean) o;
68-
return Objects.equals(source, fileBean.source) && Objects.equals(translation, fileBean.translation) && Objects.equals(excludedTargetLanguages, fileBean.excludedTargetLanguages) && Objects.equals(labels, fileBean.labels) && Objects.equals(cleanupMode, fileBean.cleanupMode) && Objects.equals(updateStrings, fileBean.updateStrings);
77+
return Objects.equals(source, fileBean.source) && Objects.equals(translation, fileBean.translation) && Objects.equals(excludedTargetLanguages, fileBean.excludedTargetLanguages) && Objects.equals(labels, fileBean.labels) && Objects.equals(cleanupMode, fileBean.cleanupMode) && Objects.equals(updateStrings, fileBean.updateStrings) && Objects.equals(escapeSpecialCharacters, fileBean.escapeSpecialCharacters);
6978
}
7079

7180
@Override
7281
public int hashCode() {
73-
return Objects.hash(source, translation, excludedTargetLanguages, labels, cleanupMode, updateStrings);
82+
return Objects.hash(source, translation, excludedTargetLanguages, labels, cleanupMode, updateStrings, escapeSpecialCharacters);
7483
}
7584

7685
@Override
@@ -82,6 +91,7 @@ public String toString() {
8291
", labels=" + labels +
8392
", cleanupMode=" + cleanupMode +
8493
", updateStrings=" + updateStrings +
94+
", escapeSpecialCharacters=" + escapeSpecialCharacters +
8595
'}';
8696
}
8797
}

src/main/java/com/crowdin/logic/SourceLogic.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@
66
import com.crowdin.client.core.model.PatchRequest;
77
import com.crowdin.client.labels.model.Label;
88
import com.crowdin.client.languages.model.Language;
9-
import com.crowdin.client.sourcefiles.model.AddDirectoryRequest;
10-
import com.crowdin.client.sourcefiles.model.AddFileRequest;
11-
import com.crowdin.client.sourcefiles.model.Branch;
12-
import com.crowdin.client.sourcefiles.model.Directory;
13-
import com.crowdin.client.sourcefiles.model.FileInfo;
14-
import com.crowdin.client.sourcefiles.model.GeneralFileExportOptions;
15-
import com.crowdin.client.sourcefiles.model.UpdateFileRequest;
9+
import com.crowdin.client.sourcefiles.model.*;
1610
import com.crowdin.client.sourcestrings.model.UploadStringsProgress;
1711
import com.crowdin.client.sourcestrings.model.UploadStringsRequest;
1812
import com.crowdin.service.CrowdinProjectCacheProvider;
@@ -102,7 +96,7 @@ public void uploadSource(VirtualFile source, FileBean fileBean, boolean preserve
10296
try {
10397
VirtualFile pathToPattern = FileUtil.getBaseDir(source, fileBean.getSource());
10498

105-
GeneralFileExportOptions exportOptions = new GeneralFileExportOptions();
99+
PropertyFileExportOptions exportOptions = new PropertyFileExportOptions();
106100

107101
String path;
108102
String parentPath;
@@ -120,6 +114,10 @@ public void uploadSource(VirtualFile source, FileBean fileBean, boolean preserve
120114
exportOptions.setExportPattern(sepAtStart(fileBean.getTranslation()));
121115
}
122116

117+
if (fileBean.getEscapeSpecialCharacters() != null) {
118+
exportOptions.setEscapeSpecialCharacters(fileBean.getEscapeSpecialCharacters());
119+
}
120+
123121
String outputName = FileUtil.noSepAtStart(path);
124122
FileInfo foundFile = filePaths.get(path);
125123
if (foundFile != null) {

0 commit comments

Comments
 (0)