Skip to content

Commit

Permalink
8298808: Check script code on detecting the base locales
Browse files Browse the repository at this point in the history
Reviewed-by: joehw
  • Loading branch information
naotoj committed Dec 16, 2022
1 parent 81e23ab commit 0eeaeb8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java
Expand Up @@ -633,7 +633,7 @@ static String getLanguageCode(String id) {
/**
* Examine if the id includes the country (territory) code. If it does, it returns
* the country code.
* Otherwise, it returns null. eg. when the id is "zh_Hans_SG", it return "SG".
* Otherwise, it returns null. eg. when the id is "zh_Hans_SG", it returns "SG".
* It does NOT return UN M.49 code, e.g., '001', as those three digit numbers cannot
* be translated into package names.
*/
Expand All @@ -645,13 +645,21 @@ static String getCountryCode(String id) {
/**
* Examine if the id includes the region code. If it does, it returns
* the region code.
* Otherwise, it returns null. eg. when the id is "zh_Hans_SG", it return "SG".
* Otherwise, it returns null. eg. when the id is "zh_Hans_SG", it returns "SG".
* It DOES return UN M.49 code, e.g., '001', as well as ISO 3166 two letter country codes.
*/
static String getRegionCode(String id) {
return Locale.forLanguageTag(id.replaceAll("_", "-")).getCountry();
}

/**
* Examine if the id includes the script code. If it does, it returns
* the script code.
*/
static String getScriptCode(String id) {
return Locale.forLanguageTag(id.replaceAll("_", "-")).getScript();
}

private static class KeyComparator implements Comparator<String> {
static KeyComparator INSTANCE = new KeyComparator();

Expand Down Expand Up @@ -1020,6 +1028,7 @@ private static String toLocaleName(String tag) {
private static void setupBaseLocales(String localeList) {
Arrays.stream(localeList.split(","))
.map(Locale::forLanguageTag)
.map(l -> new Locale.Builder().setLocale(l).setScript("Latn").build())
.map(l -> Control.getControl(Control.FORMAT_DEFAULT)
.getCandidateLocales("", l))
.forEach(BASE_LOCALES::addAll);
Expand Down
Expand Up @@ -417,11 +417,11 @@ public Map<Locale, String[]> parentLocales() {
private static final Locale.Builder LOCALE_BUILDER = new Locale.Builder();
private static boolean isBaseLocale(String localeID) {
localeID = localeID.replaceAll("-", "_");
// ignore script here
Locale locale = LOCALE_BUILDER
.clear()
.setLanguage(CLDRConverter.getLanguageCode(localeID))
.setRegion(CLDRConverter.getRegionCode(localeID))
.setScript(CLDRConverter.getScriptCode(localeID))
.build();
return CLDRConverter.BASE_LOCALES.contains(locale);
}
Expand Down

1 comment on commit 0eeaeb8

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.