Skip to content

Commit

Permalink
fix: work around for JRE 8 l10n bug
Browse files Browse the repository at this point in the history
- JRE 8 has a localization bug in Chinese
  - Locale class has wrong display name for
    ZA, SD, SD_IN and SD_PK
- The problem is reported at
  OmegaT-L10N/zh_CN#4
  and
  OmegaT-L10N/zh_CN#5

Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Mar 3, 2023
1 parent f195304 commit 916d57a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/org/omegat/util/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,31 @@ public Language(String str) {
}
}

private final static String ZA_IN_ZH= "\u58EE\u8BED";
private final static String SD_IN_ZH= "\u4FE1\u5FB7\u6587";
private final static String SD_IN_IN_ZH= "\u4FE1\u5FB7\u6587(\u5370\u5EA6)";
private final static String SD_PK_IN_ZH= "\u4FE1\u5FB7\u6587(\u5DF4\u57FA\u65AF\u5766)";

/**
* Returns a name for the language that is appropriate for display to the
* user.
*/
public String getDisplayName() {
if (Platform.getJavaVersion() == 8) {
// work around for java 8 JRE localization bug
// see https://github.com/OmegaT-L10N/zh_CN/issues/5
if (Locale.getDefault().equals(Locale.SIMPLIFIED_CHINESE)) {
if (this.equals(new Language("ZA"))) {
return ZA_IN_ZH;
} else if (this.equals(new Language("SD"))) {
return SD_IN_ZH;
} else if (locale.equals(new Locale("sd", "IN"))) {
return SD_IN_IN_ZH;
} else if (locale.equals(new Locale("sd", "PK"))) {
return SD_PK_IN_ZH;
}
}
}
return locale.getDisplayName();
}

Expand Down
12 changes: 12 additions & 0 deletions src/org/omegat/util/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,16 @@ public static boolean is64Bit() {
}
return false;
}

public static int getJavaVersion() {
String[] versionElements = System.getProperty("java.version").split("\\.");
int discard = Integer.parseInt(versionElements[0]);
int version;
if (discard == 1) {
version = Integer.parseInt(versionElements[1]);
} else {
version = discard;
}
return version;
}
}

0 comments on commit 916d57a

Please sign in to comment.