Skip to content

Commit

Permalink
refactor: adjust review feedbacks
Browse files Browse the repository at this point in the history
- Update LanguageCode.getLanguageCodeByName
    - add null check at first
    - move a migration heuristics code from MapRule
- Update MapRule javadoc descriptions

Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Nov 2, 2024
1 parent b0c3e17 commit d144d42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/org/omegat/core/segmentation/LanguageCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,20 @@ public static boolean isLanguageCodeKnown(String code) {
}

public static String getLanguageCodeByName(String name) {
if (name == null) {
return null;
}
for (Map.Entry<String, String> entry : codeKeyHash.entrySet()) {
if (OStrings.getString(entry.getValue()).equals(name)) {
return entry.getKey();
}
}
// migration heuristics: Germany translation changed in v5.5.
// See:
// https://github.com/omegat-org/omegat/pull/1158#issuecomment-2448788253
if (name.contains("Textdateien")) {
return LanguageCodes.F_TEXT_CODE;
}
return null;
}

Expand Down
28 changes: 12 additions & 16 deletions src/org/omegat/core/segmentation/MapRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ public class MapRule implements Serializable {
/** Language Name */
private String languageCode;

/** creates a new empty MapRule */
/**
* Creates a new empty MapRule.
* <p>
* When SRX.loadSrxFile loads segmentation.conf, java.beans.XMLDecoder
* create an empty object, then calls setLanguage and setPattern methods.
* </p>
*/
public MapRule() {
}

Expand Down Expand Up @@ -97,28 +103,18 @@ public void setLanguage(String code) {
* defined as "LanguageCodes.*_CODE". The behavior was changed in OmegaT
* 6.0.0 release in 2023. We first detect whether the argument is
* standard code. If the code is not a standard code, then try to find a
* localized name of the language name. When you read the comment long
* after OmegaT 6.x, and you believe all the OmegaT 4.x and 5.x users
* are migrated to OmegaT 6.x or later, you may want to remove the chunk
* below.
* localized name of the language name. When you believe all the OmegaT
* 4.x and 5.x users are migrated to OmegaT 6.x or later, you may want
* to remove the workaround here.
*/
if (!LanguageCodes.isLanguageCodeKnown(code)) {
String alt = LanguageCodes.getLanguageCodeByName(code);
if (alt != null) {
languageCode = alt;
return;
} else {
// migration heuristics: Germany translation changed in v5.5.
// See:
// https://github.com/omegat-org/omegat/pull/1158#issuecomment-2448788253
if (code != null && code.contains("Textdateien")) {
languageCode = LanguageCodes.F_TEXT_CODE;
} else {
LOGGER.atDebug().setMessage("Unknown language code '{}' specified").addArgument(code)
.log();
languageCode = code;
}
LOGGER.atDebug().setMessage("Unknown languagerulename '{}'").addArgument(code).log();
}
return;
}
languageCode = code;
}
Expand Down

0 comments on commit d144d42

Please sign in to comment.