diff --git a/src/org/omegat/core/segmentation/LanguageCodes.java b/src/org/omegat/core/segmentation/LanguageCodes.java index 8deaff107e..b585b9cb21 100644 --- a/src/org/omegat/core/segmentation/LanguageCodes.java +++ b/src/org/omegat/core/segmentation/LanguageCodes.java @@ -158,11 +158,20 @@ public static boolean isLanguageCodeKnown(String code) { } public static String getLanguageCodeByName(String name) { + if (name == null) { + return null; + } for (Map.Entry 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; } diff --git a/src/org/omegat/core/segmentation/MapRule.java b/src/org/omegat/core/segmentation/MapRule.java index 1688b2472c..f9032c0256 100644 --- a/src/org/omegat/core/segmentation/MapRule.java +++ b/src/org/omegat/core/segmentation/MapRule.java @@ -51,7 +51,13 @@ public class MapRule implements Serializable { /** Language Name */ private String languageCode; - /** creates a new empty MapRule */ + /** + * Creates a new empty MapRule. + *

+ * When SRX.loadSrxFile loads segmentation.conf, java.beans.XMLDecoder + * create an empty object, then calls setLanguage and setPattern methods. + *

+ */ public MapRule() { } @@ -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; }