Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ files:
cleanup_mode: true
```

It's also possible to disable escaping special characters (`=`, `:`, `!` and `#`):

```yml
files:
- source: "**/values/strings.xml"
translation: "/values-%two_letters_code%/%original_file_name%"
escape_special_characters: 0
```

##### Translations upload options

The following properties can be used to configure the import options for uploaded translations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CrowdinPropertiesLoader {
private static final String PROPERTY_FILES_CLEANUP_MODE = "cleanup_mode";
private static final String PROPERTY_FILES_UPDATE_STRINGS = "update_strings";
private static final String PROPERTY_EXCLUDED_TARGET_LANGUAGES = "excluded_target_languages";
private static final String PROPERTY_ESCAPE_SPECIAL_CHARACTERS = "escape_special_characters";

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

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

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

private static Integer getIntegerProperty(Map<String, Object> map, String property) {
return getProperty(map, property, Integer.class);
}

private static List<String> getListStringsProperty(Map<String, Object> map, String property) {
List list = getProperty(map, property, List.class);
if (list == null) {
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/crowdin/client/config/FileBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class FileBean {
private List<String> labels;
private Boolean cleanupMode;
private Boolean updateStrings;
private Integer escapeSpecialCharacters;

public String getSource() {
return source;
Expand Down Expand Up @@ -60,17 +61,25 @@ public void setUpdateStrings(Boolean updateStrings) {
this.updateStrings = updateStrings;
}

public Integer getEscapeSpecialCharacters() {
return escapeSpecialCharacters;
}

public void setEscapeSpecialCharacters(Integer escapeSpecialCharacters) {
this.escapeSpecialCharacters = escapeSpecialCharacters;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FileBean fileBean = (FileBean) o;
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);
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);
}

@Override
public int hashCode() {
return Objects.hash(source, translation, excludedTargetLanguages, labels, cleanupMode, updateStrings);
return Objects.hash(source, translation, excludedTargetLanguages, labels, cleanupMode, updateStrings, escapeSpecialCharacters);
}

@Override
Expand All @@ -82,6 +91,7 @@ public String toString() {
", labels=" + labels +
", cleanupMode=" + cleanupMode +
", updateStrings=" + updateStrings +
", escapeSpecialCharacters=" + escapeSpecialCharacters +
'}';
}
}
14 changes: 6 additions & 8 deletions src/main/java/com/crowdin/logic/SourceLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
import com.crowdin.client.core.model.PatchRequest;
import com.crowdin.client.labels.model.Label;
import com.crowdin.client.languages.model.Language;
import com.crowdin.client.sourcefiles.model.AddDirectoryRequest;
import com.crowdin.client.sourcefiles.model.AddFileRequest;
import com.crowdin.client.sourcefiles.model.Branch;
import com.crowdin.client.sourcefiles.model.Directory;
import com.crowdin.client.sourcefiles.model.FileInfo;
import com.crowdin.client.sourcefiles.model.GeneralFileExportOptions;
import com.crowdin.client.sourcefiles.model.UpdateFileRequest;
import com.crowdin.client.sourcefiles.model.*;
import com.crowdin.client.sourcestrings.model.UploadStringsProgress;
import com.crowdin.client.sourcestrings.model.UploadStringsRequest;
import com.crowdin.service.CrowdinProjectCacheProvider;
Expand Down Expand Up @@ -102,7 +96,7 @@ public void uploadSource(VirtualFile source, FileBean fileBean, boolean preserve
try {
VirtualFile pathToPattern = FileUtil.getBaseDir(source, fileBean.getSource());

GeneralFileExportOptions exportOptions = new GeneralFileExportOptions();
PropertyFileExportOptions exportOptions = new PropertyFileExportOptions();

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

if (fileBean.getEscapeSpecialCharacters() != null) {
exportOptions.setEscapeSpecialCharacters(fileBean.getEscapeSpecialCharacters());
}

String outputName = FileUtil.noSepAtStart(path);
FileInfo foundFile = filePaths.get(path);
if (foundFile != null) {
Expand Down
Loading