diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/GenerateLanguageData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/GenerateLanguageData.java index a70b51ff04e..31657d699b8 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/GenerateLanguageData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/GenerateLanguageData.java @@ -15,6 +15,7 @@ import org.unicode.cldr.util.Counter2; import org.unicode.cldr.util.Factory; import org.unicode.cldr.util.LanguageTagParser; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.StandardCodes; import org.unicode.cldr.util.SupplementalDataInfo; import org.unicode.cldr.util.SupplementalDataInfo.OfficialStatus; @@ -44,8 +45,9 @@ private void run() throws IOException { // Counter2 langToGDP = new Counter2(); LanguageTagParser ltp = new LanguageTagParser(); Map languageNameToCode = new TreeMap<>(); + NameGetter nameGetter = english.nameGetter(); for (String languageCode : info.getLanguages()) { - languageNameToCode.put(english.getName(languageCode), languageCode); + languageNameToCode.put(nameGetter.getNameFromBCP47(languageCode), languageCode); } out.println("\n@sheet:CLDR County Data"); out.println("code\tgdp\tlit-pop\tpopulation\tliteracy"); @@ -71,7 +73,7 @@ private void run() throws IOException { Map> langToCountriesOfficial = new TreeMap<>(); for (String languageCode : info.getLanguages()) { - String languageName = english.getName(languageCode); + String languageName = nameGetter.getNameFromBCP47(languageCode); String baseLanguage = languageCode; ltp.set(languageCode); @@ -90,7 +92,8 @@ private void run() throws IOException { // ); for (String territory : territories) { PopulationData terrData = info.getPopulationDataForTerritory(territory); - String territoryName = english.getName(CLDRFile.TERRITORY_NAME, territory); + String territoryName = + nameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, territory); PopulationData data = info.getLanguageAndTerritoryPopulationData(languageCode, territory); @@ -156,7 +159,7 @@ private void run() throws IOException { } // for (String language :langToPopulation.keySet()) { // out.println( - // english.getName(language) + // english.nameGetter().getName(language) // + "\t" + language // + "\t" + langToPopulation.getCount(language) // + "\t" + langToGDP.getCount(language) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/Misc.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/Misc.java index 369f9da9190..b7455bfab2a 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/Misc.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/Misc.java @@ -138,7 +138,8 @@ private static void showDefaultContent(String... strings) { break; } } - System.out.println(string + "\t" + defCon + "\t" + english.getName(defCon)); + System.out.println( + string + "\t" + defCon + "\t" + english.nameGetter().getNameFromBCP47(defCon)); } } @@ -328,7 +329,7 @@ private static void showExemplarSize() { if (temp != null) { baseLanguage = temp.get0().get(0); } - String englishName = english.getName(baseLanguage); + String englishName = english.nameGetter().getNameFromBCP47(baseLanguage); CLDRFile cldrFile = factory.make(baseLanguage, false); UnicodeSet set = cldrFile.getExemplarSet("", WinningChoice.WINNING); int script = -1; @@ -339,7 +340,7 @@ private static void showExemplarSize() { break; } } - String nativeName = cldrFile.getName(baseLanguage); + String nativeName = cldrFile.nameGetter().getNameFromBCP47(baseLanguage); nameAndInfo.add( englishName + "\t" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/XLocaleDistance.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/XLocaleDistance.java index 6e5f7b96da3..d5fccb9020f 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/XLocaleDistance.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/XLocaleDistance.java @@ -969,21 +969,29 @@ private static String fixedName(List match) { if (region.equals("*") || region.startsWith("$")) { result.append(region); } else { - result.append(english.getName(CLDRFile.TERRITORY_NAME, region)); + result.append( + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, region)); } case 2: String script = alt.get(1); if (script.equals("*")) { result.insert(0, script); } else { - result.insert(0, english.getName(CLDRFile.TERRITORY_NAME, script)); + result.insert( + 0, + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, script)); } case 1: String language = alt.get(0); if (language.equals("*")) { result.insert(0, language); } else { - result.insert(0, english.getName(CLDRFile.TERRITORY_NAME, language)); + result.insert( + 0, + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, language)); } } return Joiner.on("; ").join(alt); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/CLDRTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/CLDRTest.java index 004432f3958..53ee224c548 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/CLDRTest.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/CLDRTest.java @@ -413,7 +413,7 @@ public String getLocaleName(String locale) { String name = localeNameCache.get(locale); if (name != null) return name; if (english == null) english = cldrFactory.make("en", true); - String result = english.getName(locale); + String result = english.nameGetter().getNameFromBCP47(locale); /* * Collection c = Utility.splitList(locale, '_', false, null); * String[] pieces = new String[c.size()]; @@ -1047,7 +1047,11 @@ public Object transform(Object source) { @Override public Object transform(Object source) { if (english == null) english = cldrFactory.make("en", true); - return english.getName("currency", source.toString()) + " (" + source + ")"; + return english.nameGetter() + .getNameFromTypestrCode("currency", source.toString()) + + " (" + + source + + ")"; } }; @@ -1189,7 +1193,7 @@ public void TestSupplementalData() { logln("Missing English currency names"); for (Iterator it = legalCurrencies.iterator(); it.hasNext(); ) { String currency = it.next(); - String name = english.getName("currency", currency); + String name = english.nameGetter().getNameFromTypestrCode("currency", currency); if (name == null) { String standardName = sc.getFullData("currency", currency).get(0); logln("\t\t\t"); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java index 86ac980006d..e2c9793d101 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java @@ -1985,7 +1985,8 @@ private static String getEnglishPathValue(String path) { * @return */ private static String getLocaleAndName(String locale) { - String localizedName = CheckCLDR.getDisplayInformation().getName(locale); + String localizedName = + CheckCLDR.getDisplayInformation().nameGetter().getNameFromBCP47(locale); if (localizedName == null || localizedName.equals(locale)) return locale; return locale + " [" + localizedName + "]"; } @@ -1998,7 +1999,8 @@ private static String getLocaleAndName(String locale) { * @return */ private static String getNameAndLocale(String locale, boolean linkToXml) { - String localizedName = CheckCLDR.getDisplayInformation().getName(locale); + String localizedName = + CheckCLDR.getDisplayInformation().nameGetter().getNameFromBCP47(locale); if (localizedName == null || localizedName.equals(locale)) return locale; if (linkToXml) { locale = @@ -2012,7 +2014,8 @@ private static String getNameAndLocale(String locale, boolean linkToXml) { } private static String getLocaleName(String locale) { - String localizedName = CheckCLDR.getDisplayInformation().getName(locale); + String localizedName = + CheckCLDR.getDisplayInformation().nameGetter().getNameFromBCP47(locale); if (localizedName == null || localizedName.equals(locale)) return locale; return localizedName; } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/EmojiSubdivisionNames.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/EmojiSubdivisionNames.java index 9008b63bfed..80ec98f243d 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/EmojiSubdivisionNames.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/EmojiSubdivisionNames.java @@ -21,6 +21,7 @@ import org.unicode.cldr.util.EmojiConstants; import org.unicode.cldr.util.LanguageGroup; import org.unicode.cldr.util.LocaleIDParser; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.Organization; import org.unicode.cldr.util.StandardCodes; @@ -130,6 +131,7 @@ public static void main(String[] args) { System.out.println(); CLDRFile english = CLDRConfig.getInstance().getEnglish(); Set locales = new HashSet<>(); + NameGetter nameGetter = english.nameGetter(); for (String filename : SUBDIVISION_FILE_NAMES) { if (filename.endsWith(".xml")) { String locale = filename.substring(0, filename.length() - 4); @@ -140,7 +142,13 @@ public static void main(String[] args) { LanguageGroup group = LanguageGroup.get(ulocale); int rank = LanguageGroup.rankInGroup(ulocale); System.out.print( - group + "\t" + rank + "\t" + english.getName(locale) + "\t" + locale); + group + + "\t" + + rank + + "\t" + + nameGetter.getNameFromBCP47(locale) + + "\t" + + locale); for (String sd : SUBDIVISIONS) { System.out.print('\t'); System.out.print(map.get(sd)); @@ -161,7 +169,13 @@ public static void main(String[] args) { LanguageGroup group = LanguageGroup.get(ulocale); int rank = LanguageGroup.rankInGroup(ulocale); System.out.println( - group + "\t" + rank + "\t" + english.getName(locale) + "\t" + locale); + group + + "\t" + + rank + + "\t" + + english.nameGetter().getNameFromBCP47(locale) + + "\t" + + locale); } // System.out.println(getSubdivisionIdToName("fr")); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java index 9d3a458ba7c..9fb7a6d7d64 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java @@ -68,6 +68,7 @@ import org.unicode.cldr.util.ICUServiceBuilder; import org.unicode.cldr.util.LanguageTagParser; import org.unicode.cldr.util.Level; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.PathDescription; import org.unicode.cldr.util.PatternCache; import org.unicode.cldr.util.PluralSamples; @@ -752,11 +753,12 @@ private void handlePersonName(XPathParts parts, String value, List examp final CLDRFile cldrFile2 = getCldrFile(); switch (parts.getElement(2)) { case "nameOrderLocales": + NameGetter nameGetter2 = cldrFile2.nameGetter(); for (String localeId : PersonNameFormatter.SPLIT_SPACE.split(value)) { final String name = localeId.equals("und") ? "«any other»" - : cldrFile2.getName(localeId); + : nameGetter2.getNameFromBCP47(localeId); examples.add(localeId + " = " + name); } break; @@ -2408,12 +2410,22 @@ private void handleTimeZoneName(XPathParts parts, String value, List exa return; // fail, skip } } else { - result = setBackground(cldrFile.getName(CLDRFile.TERRITORY_NAME, countryCode)); + result = + setBackground( + cldrFile.nameGetter() + .getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, countryCode)); } } else if (parts.contains("zone")) { // {0} Time result = value; // trivial -- is this beneficial? } else if (parts.contains("regionFormat")) { // {0} Time - result = format(value, setBackground(cldrFile.getName(CLDRFile.TERRITORY_NAME, "JP"))); + result = + format( + value, + setBackground( + cldrFile.nameGetter() + .getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, "JP"))); result = addExampleResult( format( @@ -3101,10 +3113,11 @@ private void handleDisplayNames( element.equals("localeKeyTypePattern") ? "uz-Arab-u-tz-etadd" : "uz-Arab-AF"); locales.add("uz-Arab-AF-u-tz-etadd-nu-arab"); // String[] examples = new String[locales.size()]; + NameGetter nameGetter = cldrFile.nameGetter(); for (int i = 0; i < locales.size(); i++) { examples.add( invertBackground( - cldrFile.getName( + nameGetter.getNameFromBCP47Etc( locales.get(i), false, localeKeyTypePattern, diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/QuickCheck.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/QuickCheck.java index 1c0fb678607..da0f4c9d30c 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/QuickCheck.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/QuickCheck.java @@ -208,7 +208,7 @@ private static void checkPaths() { DisplayAndInputProcessor displayAndInputProcessor = new DisplayAndInputProcessor(file, false); - System.out.println(locale + "\t-\t" + english.getName(locale)); + System.out.println(locale + "\t-\t" + english.nameGetter().getNameFromBCP47(locale)); DtdType dtdType = null; for (Iterator it = file.iterator(); it.hasNext(); ) { diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestMisc.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestMisc.java index 1a40a28e44d..89d24824692 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestMisc.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestMisc.java @@ -38,6 +38,7 @@ import org.unicode.cldr.util.Iso639Data; import org.unicode.cldr.util.Iso639Data.Scope; import org.unicode.cldr.util.Level; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.Pair; import org.unicode.cldr.util.PatternCache; import org.unicode.cldr.util.SimpleFactory; @@ -236,8 +237,9 @@ private static void testWeights() { int vote = Level.getDefaultWeight("google", desiredLocale); rel.add(new Pair<>(vote, desiredLocale)); } + NameGetter nameGetter = english.nameGetter(); for (Pair p : rel) { - System.out.println(p + "\t" + english.getName(p.getSecond())); + System.out.println(p + "\t" + nameGetter.getNameFromBCP47(p.getSecond())); } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestSupplementalData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestSupplementalData.java index 80422753c5d..60c3b3c9d91 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestSupplementalData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestSupplementalData.java @@ -16,6 +16,7 @@ import org.unicode.cldr.util.CLDRPaths; import org.unicode.cldr.util.CldrUtility; import org.unicode.cldr.util.Factory; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.Pair; import org.unicode.cldr.util.PatternCache; import org.unicode.cldr.util.StandardCodes; @@ -152,6 +153,7 @@ static void checkAgainstLanguageScript() { } } // compare them, listing differences + NameGetter nameGetter = english.nameGetter(); for (String territory : sc.getGoodAvailableCodes("territory")) { Set languages = supplementalData.getTerritoryToLanguages(territory); Set otherLanguages = otherTerritoryToLanguages.getAll(territory); @@ -161,10 +163,11 @@ static void checkAgainstLanguageScript() { languagesLeftover.removeAll(otherLanguages); Set otherLanguagesLeftover = new TreeSet<>(otherLanguages); otherLanguagesLeftover.removeAll(languages); - String territoryString = english.getName(CLDRFile.TERRITORY_NAME, territory); + String territoryString = + nameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, territory); if (otherLanguagesLeftover.size() != 0) { for (String other : otherLanguagesLeftover) { - String name = english.getName(other); + String name = nameGetter.getNameFromBCP47(other); System.out.println( territoryString + "\t" + territory + "\t" + name + "\t" + other); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartAnnotations.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartAnnotations.java index 1ce8358bd11..3609c4ae6f7 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartAnnotations.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartAnnotations.java @@ -32,6 +32,7 @@ import org.unicode.cldr.util.LanguageGroup; import org.unicode.cldr.util.LanguageTagParser; import org.unicode.cldr.util.LocaleIDParser; +import org.unicode.cldr.util.NameGetter; public class ChartAnnotations extends Chart { @@ -159,6 +160,7 @@ public void writeSubcharts(Anchors anchors) throws IOException { Multimap localeToSub = TreeMultimap.create(); LanguageTagParser ltp = new LanguageTagParser(); + NameGetter nameGetter = ENGLISH.nameGetter(); for (String locale : locales) { ltp.set(locale); if (locale.equals("root")) { @@ -176,7 +178,7 @@ public void writeSubcharts(Anchors anchors) throws IOException { if (locale.startsWith("en")) { int debug = 0; } - String name = ENGLISH.getName(locale, true); + String name = nameGetter.getNameFromBCP47Bool(locale, true); int baseEnd = locale.indexOf('_'); ULocale loc = new ULocale(baseEnd < 0 ? locale : locale.substring(0, baseEnd)); LanguageGroup group = LanguageGroup.get(loc); @@ -187,7 +189,7 @@ public void writeSubcharts(Anchors anchors) throws IOException { for (Entry>> groupPairs : groupToNameAndCodeSorted.keyValuesSet()) { LanguageGroup group = groupPairs.getKey(); - String ename = ENGLISH.getName("en", true); + String ename = nameGetter.getNameFromBCP47Bool("en", true); nameToCode.clear(); nameToCode.put(ename, "en"); // always have english first @@ -300,7 +302,8 @@ public static int getRegionalIndicator(int firstCodepoint) { // int ri1 = getRegionalIndicator(cp.codePointAt(0)); // if (ri1 >= 0) { // int ri2 = getRegionalIndicator(cp.codePointAt(2)); - // return ENGLISH.getName(CLDRFile.TERRITORY_NAME, String.valueOf((char) ri1) + + // return ENGLISH.nameGetter().getName(CLDRFile.TERRITORY_NAME, String.valueOf((char) + // ri1) + // String.valueOf((char) ri2)); // } // String result = NAMES80.get(cp); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartCollation.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartCollation.java index 425cf126feb..77c3836466e 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartCollation.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartCollation.java @@ -228,7 +228,11 @@ public void writeSubcharts(Anchors anchors) throws IOException { if (!data.containsKey("standard")) { addCollator(data, "standard", (RuleBasedCollator) null); } - new Subchart(ENGLISH.getName(locale, true, CLDRFile.SHORT_ALTS), locale, data) + new Subchart( + ENGLISH.nameGetter() + .getNameFromBCP47BoolAlt(locale, true, CLDRFile.SHORT_ALTS), + locale, + data) .writeChart(anchors); } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDayPeriods.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDayPeriods.java index 83f42e71f19..3ade180472c 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDayPeriods.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDayPeriods.java @@ -92,7 +92,7 @@ public void writeContents(FormattedFileWriter pw) throws IOException { tablePrinter .addRow() .addCell(group) - .addCell(ENGLISH.getName(locale)) + .addCell(ENGLISH.nameGetter().getNameFromBCP47(locale)) .addCell(locale) // .addCell(type) .addCell(df.format(time)) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDelta.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDelta.java index 0636d60f293..1dee949d50b 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDelta.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDelta.java @@ -1011,7 +1011,7 @@ private void writeDiffs( .addCell(coverageLevel) .finishRow(); } - String title = ENGLISH.getName(file) + " " + chartNameCap; + String title = ENGLISH.nameGetter().getNameFromBCP47(file) + " " + chartNameCap; writeTable(anchors, file, tablePrinter, title, tsvFile); diff.clear(); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartGrammaticalForms.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartGrammaticalForms.java index d3dfaefcd18..37a5c68cf32 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartGrammaticalForms.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartGrammaticalForms.java @@ -166,7 +166,7 @@ private TablePrinter getFormattedGrammarInfo(Set localeIds) { } Set failures = new LinkedHashSet<>(); GrammarInfo grammarInfo = SDI.getGrammarInfo(localeId, false); - String localeName = CONFIG.getEnglish().getName(localeId); + String localeName = CONFIG.getEnglish().nameGetter().getNameFromBCP47(localeId); for (GrammaticalFeature feature : GrammaticalFeature.values()) { Map> scopeToValues = grammarInfo.get(GrammaticalTarget.nominal, feature); @@ -905,7 +905,7 @@ public void writeSubcharts(Anchors anchors) throws IOException { powerTable)); if (!info.isEmpty()) { - String name = ENGLISH.getName(locale); + String name = ENGLISH.nameGetter().getNameFromBCP47(locale); new Subchart(name + ": Unit Grammar Info", locale, info).writeChart(anchors); } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartLanguageGroups.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartLanguageGroups.java index a7d4d8e5ff2..3e8d4ffc021 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartLanguageGroups.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartLanguageGroups.java @@ -181,7 +181,8 @@ private String getLangName(String langCode) { ? "All" : langCode.equals("zh") ? "Mandarin Chinese" - : ENGLISH.getName(CLDRFile.LANGUAGE_NAME, langCode) + : ENGLISH.nameGetter() + .getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, langCode) .replace(" (Other)", "") .replace(" languages", ""); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartLanguageMatching.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartLanguageMatching.java index abbb33c2a08..7fc3a5b4b97 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartLanguageMatching.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartLanguageMatching.java @@ -63,7 +63,7 @@ public void writeContents(FormattedFileWriter pw) throws IOException { tablePrinter .addRow() - // .addCell(ENGLISH.getName(locale)) + // .addCell(ENGLISH.nameGetter().getName(locale)) .addCell(getName(row.get0(), true)) .addCell(getName(row.get1(), false)) .addCell(row.get0()) @@ -79,7 +79,8 @@ public void writeContents(FormattedFileWriter pw) throws IOException { private String getName(String codeWithStars, boolean user) { if (!codeWithStars.contains("*") && !codeWithStars.contains("$")) { - return ENGLISH.getName(codeWithStars, true, CLDRFile.SHORT_ALTS); + return ENGLISH.nameGetter() + .getNameFromBCP47BoolAlt(codeWithStars, true, CLDRFile.SHORT_ALTS); } String[] parts = codeWithStars.split("_"); if (parts[0].equals("*")) { @@ -97,7 +98,10 @@ private String getName(String codeWithStars, boolean user) { parts[2] = "XY"; } } - String result = ENGLISH.getName(String.join("_", parts), true, CLDRFile.SHORT_ALTS); + String result = + ENGLISH.nameGetter() + .getNameFromBCP47BoolAlt( + String.join("_", parts), true, CLDRFile.SHORT_ALTS); if (user) { result = result.replace("Xxxx", "any-script") diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartPersonName.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartPersonName.java index a21c7308e5d..8c665759606 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartPersonName.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartPersonName.java @@ -34,7 +34,7 @@ public String getDirectory() { @Override public String getTitle() { - return ENGLISH.getName(locale) + ": Person Names"; + return ENGLISH.nameGetter().getNameFromBCP47(locale) + ": Person Names"; } @Override diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSubdivisionNames.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSubdivisionNames.java index a4cf2a7f3ea..ac4c356b27b 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSubdivisionNames.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSubdivisionNames.java @@ -101,7 +101,7 @@ public void writeSubcharts(Anchors anchors) throws IOException { if (locale.startsWith("en")) { int debug = 0; } - String name = ENGLISH.getName(locale, true); + String name = ENGLISH.nameGetter().getNameFromBCP47Bool(locale, true); int baseEnd = locale.indexOf('_'); ULocale loc = new ULocale(baseEnd < 0 ? locale : locale.substring(0, baseEnd)); LanguageGroup group = LanguageGroup.get(loc); @@ -112,7 +112,7 @@ public void writeSubcharts(Anchors anchors) throws IOException { for (Entry>> groupPairs : groupToNameAndCodeSorted.keyValuesSet()) { LanguageGroup group = groupPairs.getKey(); - String ename = ENGLISH.getName("en", true); + String ename = ENGLISH.nameGetter().getNameFromBCP47Bool("en", true); nameToCode.clear(); nameToCode.put(ename, "en"); // always have english first @@ -165,9 +165,10 @@ public void writeSubcharts(Anchors anchors) throws IOException { tablePrinter .addRow() .addCell( - english.getName( - CLDRFile.TERRITORY_NAME, - code.substring(0, 2).toUpperCase(Locale.ENGLISH))) + english.nameGetter() + .getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, + code.substring(0, 2).toUpperCase(Locale.ENGLISH))) .addCell(code); for (Entry nameAndLocale : nameToCode.entrySet()) { String name = nameAndLocale.getKey(); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSubdivisions.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSubdivisions.java index 167ffe4b5b2..63acf45c88d 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSubdivisions.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSubdivisions.java @@ -124,7 +124,9 @@ public void writeContents(FormattedFileWriter pw) throws IOException { } tablePrinter .addRow() - .addCell(ENGLISH.getName(CLDRFile.TERRITORY_NAME, region)) + .addCell( + ENGLISH.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, region)) .addCell(region) .addCell(name1) // .addCell(type) @@ -139,7 +141,9 @@ public void writeContents(FormattedFileWriter pw) throws IOException { Set regionAliases = inverseAliases.get(region); tablePrinter .addRow() - .addCell(ENGLISH.getName(CLDRFile.TERRITORY_NAME, region)) + .addCell( + ENGLISH.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, region)) .addCell(region) .addCell( regionAliases == null diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSupplemental.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSupplemental.java index 68bb805d43f..6a12e82218a 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSupplemental.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartSupplemental.java @@ -34,7 +34,7 @@ public String getDirectory() { @Override public String getTitle() { - return ENGLISH.getName(locale) + ": Overall Errors"; + return ENGLISH.nameGetter().getNameFromBCP47(locale) + ": Overall Errors"; } @Override diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CheckEnglishCurrencyNames.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CheckEnglishCurrencyNames.java index 09d15538bdd..809b3d07110 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CheckEnglishCurrencyNames.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CheckEnglishCurrencyNames.java @@ -10,6 +10,7 @@ import org.unicode.cldr.util.CLDRFile; import org.unicode.cldr.util.CLDRPaths; import org.unicode.cldr.util.Factory; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.StandardCodes; import org.unicode.cldr.util.SupplementalDataInfo; import org.unicode.cldr.util.SupplementalDataInfo.CurrencyDateInfo; @@ -22,6 +23,7 @@ public class CheckEnglishCurrencyNames { static StandardCodes sc = StandardCodes.make(); static Factory cldrFactory = Factory.make(CLDRPaths.MAIN_DIRECTORY, ".*"); static CLDRFile english = cldrFactory.make("en", true); + static NameGetter englishNameGetter = english.nameGetter(); public static void main(String[] args) { Date now = new Date(); @@ -63,14 +65,20 @@ public static void main(String[] args) { } System.out.println("Modern Codes: " + modernCurrencyCodes2territory); for (String currency : modernCurrencyCodes2territory.keySet()) { - final String name = english.getName(CLDRFile.CURRENCY_NAME, currency).toLowerCase(); + final String name = + englishNameGetter + .getNameFromTypenumCode(CLDRFile.CURRENCY_NAME, currency) + .toLowerCase(); if (name.contains("new") || name.contains("old")) { System.out.println(currency + "\t" + name); } } System.out.println("Non-Modern Codes (with dates): " + currencyCodesWithDates); for (String currency : currencyCodesWithDates.keySet()) { - final String name = english.getName(CLDRFile.CURRENCY_NAME, currency).toLowerCase(); + final String name = + englishNameGetter + .getNameFromTypenumCode(CLDRFile.CURRENCY_NAME, currency) + .toLowerCase(); if (name.contains("new") || name.contains("old")) { System.out.println(currency + "\t" + name); } @@ -131,19 +139,24 @@ public static void main(String[] args) { String symbol = nativeLanguage == null ? "N/A" - : nativeLanguage.getName(CLDRFile.CURRENCY_SYMBOL, currency); + : nativeLanguage + .nameGetter() + .getNameFromTypenumCode( + CLDRFile.CURRENCY_SYMBOL, currency); System.out.println( currency + "\t" - + english.getName(CLDRFile.CURRENCY_NAME, currency) + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.CURRENCY_NAME, currency) + "\t" + territory + "\t" - + english.getName(CLDRFile.TERRITORY_NAME, territory) + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, territory) + "\t" + language + "\t" - + english.getName(language) + + englishNameGetter.getNameFromBCP47(language) + "\t" + symbol); // TODO add script @@ -166,7 +179,10 @@ public static void main(String[] args) { System.out.format("No official languages\n"); for (String territory : noOfficialLanguages) { System.out.println( - territory + "\t" + english.getName(CLDRFile.TERRITORY_NAME, territory)); + territory + + "\t" + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, territory)); } System.out.format("Collected usage data\n"); for (Entry> currencyAndSymbols : currency2symbols.keyValuesSet()) { @@ -175,7 +191,8 @@ public static void main(String[] args) { System.out.println( currency + "\t" - + english.getName(CLDRFile.CURRENCY_NAME, currency) + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.CURRENCY_NAME, currency) + "\t" + symbols.size() + "\t" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CheckLanguageNameCoverage.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CheckLanguageNameCoverage.java index 6bec6ab0c89..0bf838b9378 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CheckLanguageNameCoverage.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CheckLanguageNameCoverage.java @@ -37,7 +37,11 @@ public static void main(String[] args) { String path = CLDRFile.getKey(CLDRFile.LANGUAGE_NAME, langCode); Level level = coverages.getLevel(path); System.out.println( - langCode + "\t" + level + "\t" + config.getEnglish().getName(langCode)); + langCode + + "\t" + + level + + "\t" + + config.getEnglish().nameGetter().getNameFromBCP47(langCode)); } for (String langCode : map.keySet()) { String path = CLDRFile.getKey(CLDRFile.LANGUAGE_NAME, langCode); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CompareOyster.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CompareOyster.java index 139272cda7b..ca5e77e25c1 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CompareOyster.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CompareOyster.java @@ -23,7 +23,8 @@ public static void main(String[] args) { + "\t" + itemRegion + "\t" - + file.getName(CLDRFile.TERRITORY_NAME, itemRegion)); + + file.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, itemRegion)); } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CompareSuppress.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CompareSuppress.java index 5052b2253b1..a5cd4da429f 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CompareSuppress.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CompareSuppress.java @@ -107,10 +107,12 @@ public static void main(String[] args) { } public static String langAndName(CLDRFile english, String base) { - return base + "\t" + english.getName(base); + return base + "\t" + english.nameGetter().getNameFromBCP47(base); } public static String scriptAndName(CLDRFile english, String suppressScript) { - return suppressScript + "\t" + english.getName(CLDRFile.SCRIPT_NAME, suppressScript); + return suppressScript + + "\t" + + english.nameGetter().getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, suppressScript); } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ConvertLanguageData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ConvertLanguageData.java index 08e61d4f566..53a1245509e 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ConvertLanguageData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ConvertLanguageData.java @@ -50,6 +50,7 @@ import org.unicode.cldr.util.LanguageTagParser; import org.unicode.cldr.util.LocaleIDParser; import org.unicode.cldr.util.LocaleIDParser.Level; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.Pair; import org.unicode.cldr.util.PatternCache; import org.unicode.cldr.util.SpreadSheet; @@ -119,6 +120,7 @@ public class ConvertLanguageData { static Factory cldrFactory = Factory.make(CLDRPaths.MAIN_DIRECTORY, ".*"); static CLDRFile english = cldrFactory.make("en", true); + static final NameGetter englishNameGetter = english.nameGetter(); static SupplementalDataInfo supplementalData = SupplementalDataInfo.getInstance(CLDRPaths.DEFAULT_SUPPLEMENTAL_DIRECTORY); @@ -260,7 +262,7 @@ public static void main(String[] args) throws IOException, ParseException { public static String getLanguageCodeAndName(String code) { if (code == null) return null; - return english.getName(code) + " [" + code + "]"; + return englishNameGetter.getNameFromBCP47(code) + " [" + code + "]"; } private static String getReplacement(String oldDefault, Set defaultLocaleContent) { @@ -380,7 +382,9 @@ private static void writeNewBasicData2(PrintWriter out, Set sortedInput warnings.add( BadItem.DETAIL.toString( "changing ", - languageSubtag + "\t" + english.getName(languageSubtag), + languageSubtag + + "\t" + + englishNameGetter.getNameFromBCP47(languageSubtag), problem)); } } @@ -439,7 +443,9 @@ private static List compare( temp.append("[") .append(s) .append(":") - .append(english.getName(s.length() == 4 ? "script" : "region", s)) + .append( + englishNameGetter.getNameFromTypestrCode( + s.length() == 4 ? "script" : "region", s)) .append("] "); if (oldValue == null) { temp.append(" added as ").append(newValue); @@ -988,7 +994,8 @@ public String getLanguageCode() { static Map oldToFixed = new HashMap<>(); public String getLanguageName() { - String cldrResult = getExcelQuote(english.getName(languageCode, true)); + String cldrResult = + getExcelQuote(englishNameGetter.getNameFromBCP47Bool(languageCode, true)); // String result = getLanguageName2(); // if (!result.equalsIgnoreCase(cldrResult)) { // if (null == oldToFixed.put(result, cldrResult)) { @@ -1062,7 +1069,10 @@ public static String getExcelQuote(String comment) { public static String getCountryCodeAndName(String code) { if (code == null) return null; - return english.getName(CLDRFile.TERRITORY_NAME, code) + " [" + code + "]"; + return englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, code) + + " [" + + code + + "]"; } static class RowComparator implements Comparator { @@ -2576,17 +2586,17 @@ private static String fixCountryCode(String countryCode, List row) { } private static String getULocaleLocaleName(String languageCode) { - return english.getName(languageCode, true); + return englishNameGetter.getNameFromBCP47Bool(languageCode, true); // return new ULocale(languageCode).getDisplayName(); } private static String getULocaleScriptName(String scriptCode) { - return english.getName(CLDRFile.SCRIPT_NAME, scriptCode); + return englishNameGetter.getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, scriptCode); // return ULocale.getDisplayScript("und_" + scriptCode, ULocale.ENGLISH); } private static String getULocaleCountryName(String countryCode) { - return english.getName(CLDRFile.TERRITORY_NAME, countryCode); + return englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, countryCode); // return ULocale.getDisplayCountry("und_" + countryCode, ULocale.ENGLISH); } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CountItems.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CountItems.java index a0200b9ad3c..3a9ab4d5560 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CountItems.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/CountItems.java @@ -52,6 +52,7 @@ import org.unicode.cldr.util.IsoRegionData; import org.unicode.cldr.util.Level; import org.unicode.cldr.util.Log; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.Organization; import org.unicode.cldr.util.Pair; import org.unicode.cldr.util.PatternCache; @@ -478,13 +479,16 @@ private static Map getCountryToContinent( } // convert to map Map results = new TreeMap<>(); + NameGetter nameGetter = english.nameGetter(); for (String item : countryToContinent.keySet()) { final Set containees = countryToContinent.getAll(item); if (containees.size() != 1) { throw new IllegalArgumentException(item + "\t" + containees); } results.put( - item, english.getName(CLDRFile.TERRITORY_NAME, containees.iterator().next())); + item, + nameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, containees.iterator().next())); } return results; } @@ -496,10 +500,12 @@ private static void writeZonePrettyPath( Set masked = new HashSet<>(); Map zoneNew_Old = new TreeMap<>(col); String lastZone = "XXX"; + NameGetter nameGetter = english.nameGetter(); for (String zone : new TreeSet<>(zone_country.keySet())) { String[] parts = zone.split("/"); String newPrefix = - zone_country.get(zone); // english.getName("tzid", zone_country.get(zone), + zone_country.get( + zone); // english.nameGetter().getName("tzid", zone_country.get(zone), // false).replace(' ', '_'); if (newPrefix.equals("001")) { newPrefix = "ZZ"; @@ -553,7 +559,10 @@ private static void writeZonePrettyPath( String newCountry = newName.split("/")[0]; if (!newCountry.equals(lastCountry)) { Log.println( - "# " + newCountry + "\t" + english.getName("territory", newCountry)); + "# " + + newCountry + + "\t" + + nameGetter.getNameFromTypestrCode("territory", newCountry)); lastCountry = newCountry; } Log.println("\t'" + oldName + "'\t>\t'" + newName + "';"); @@ -821,7 +830,10 @@ public String transform(String region) { String tech = row.get0(); String bib = row.get1(); String lang = row.get2(); - String name = Iso639Data.getNames(lang).iterator().next(); // english.getName(lang); + String name = + Iso639Data.getNames(lang) + .iterator() + .next(); // english.nameGetter().getName(lang); if ((bib != null && !lang.equals(bib)) || (tech != null && !lang.equals(tech))) { System.out.println( " { \"" + bib + "\", \"" + tech + "\", \"" + lang + "\" }, // " + name); @@ -977,6 +989,7 @@ private static void addRegions( Set missingRegions = new TreeSet<>(); Set exceptionSet = new HashSet<>(Arrays.asList(exceptions)); List duplicateDestroyer = new ArrayList<>(); + NameGetter nameGetter = english.nameGetter(); for (String region : availableCodes) { if (exceptionSet.contains(region)) continue; @@ -993,7 +1006,7 @@ private static void addRegions( } else { result = region; } - String name = english.getName(CLDRFile.TERRITORY_NAME, result); + String name = nameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, result); if (!(duplicateDestroyer.contains(alpha3 + result + name))) { duplicateDestroyer.add(alpha3 + result + name); System.out.println( @@ -1007,7 +1020,7 @@ private static void addRegions( } } for (String region : missingRegions) { - String name = english.getName(CLDRFile.TERRITORY_NAME, region); + String name = nameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, region); System.err.println("ERROR: Missing " + codeType + " code for " + region + "\t" + name); } } @@ -1084,10 +1097,15 @@ public static void showZoneInfo() throws IOException { Map onlyLocales = platform_locale_status.get(Organization.ibm); Set locales = onlyLocales.keySet(); CLDRFile english = cldrFactory.make("en", true); + NameGetter nameGetter = english.nameGetter(); for (Iterator it = locales.iterator(); it.hasNext(); ) { String locale = it.next(); System.out.println( - locale + "\t" + english.getName(locale) + "\t" + onlyLocales.get(locale)); + locale + + "\t" + + nameGetter.getNameFromBCP47(locale) + + "\t" + + onlyLocales.get(locale)); } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/DeriveScripts.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/DeriveScripts.java index 6354b55a84d..c8b820f3bbb 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/DeriveScripts.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/DeriveScripts.java @@ -150,7 +150,8 @@ public static void showLine(String language, String scriptField, String status) + ";\t" + scriptField + "\t# " - + english.getName(CLDRFile.LANGUAGE_NAME, language) + + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, language) + ";\t" + status + ";\t" @@ -205,13 +206,13 @@ public static void main(String[] args) { + "\t" + lang + "\t" - + english.getName(lang) + + english.nameGetter().getNameFromBCP47(lang) + "\t" + scripts + "\t" + likelyScript // + "\t" + script + "\t" + - // english.getName(CLDRFile.SCRIPT_NAME, script) + // english.nameGetter().getName(CLDRFile.SCRIPT_NAME, script) ); } System.out.println("#total:\t" + i); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/DiffWithParent.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/DiffWithParent.java index 1d0731f3e19..1b447671161 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/DiffWithParent.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/DiffWithParent.java @@ -35,7 +35,8 @@ public static void main(String[] args) throws IOException { PrettyPath pp = new PrettyPath(); for (String locale : cldrFactory.getAvailable()) { if (fileMatcher.reset(locale).matches()) { - System.out.println(locale + "\t" + english.getName(locale)); + System.out.println( + locale + "\t" + english.nameGetter().getNameFromBCP47(locale)); CLDRFile file = cldrFactory.make(locale, false); String parentLocale = LocaleIDParser.getParent(locale); CLDRFile parent = cldrFactory.make(parentLocale, true); // use @@ -74,7 +75,11 @@ public static void main(String[] args) throws IOException { PrintWriter out = FileUtilities.openUTF8Writer( CLDRPaths.GEN_DIRECTORY, locale + "_diff.html"); - String title = locale + " " + english.getName(locale) + " Diff with Parent"; + String title = + locale + + " " + + english.nameGetter().getNameFromBCP47(locale) + + " Diff with Parent"; out.println( "" + title diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ExtractMessages.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ExtractMessages.java index ef1bfc29ab3..88efa24cd5c 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ExtractMessages.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ExtractMessages.java @@ -90,7 +90,7 @@ public static void main(String[] args) throws IOException { "Skipping, no CLDR locale file: " + name + "\t" - + english.getName(name) + + english.nameGetter().getNameFromBCP47(name) + "\t" + e1.getClass().getName() + "\t" @@ -158,7 +158,10 @@ public static void main(String[] args) throws IOException { for (String name : skipped) { System.out.println( - "\tSkipping, no CLDR locale file: " + name + "\t" + english.getName(name)); + "\tSkipping, no CLDR locale file: " + + name + + "\t" + + english.nameGetter().getNameFromBCP47(name)); } double deltaTime = System.currentTimeMillis() - startTime; System.out.println("Elapsed: " + deltaTime / 1000.0 + " seconds"); @@ -448,7 +451,7 @@ public void addName(String name, String code, boolean skipMessage) { switch (type) { case LANGUAGE: for (String code : sc.getAvailableCodes("language")) { - String name = english.getName("language", code); + String name = english.nameGetter().getNameFromTypestrCode("language", code); if (name == null) { // System.out.println("Missing name for: " + code); continue; @@ -489,7 +492,8 @@ public void addName(String name, String code, boolean skipMessage) { break; case REGION: for (String code : sc.getAvailableCodes("territory")) { - String name = english.getName("territory", code); + String name = + english.nameGetter().getNameFromTypestrCode("territory", code); if (name == null) { // System.out.println("Missing name for: " + code); continue; @@ -528,7 +532,7 @@ public void addName(String name, String code, boolean skipMessage) { break; case CURRENCY: for (String code : sc.getAvailableCodes("currency")) { - String name = english.getName("currency", code); + String name = english.nameGetter().getNameFromTypestrCode("currency", code); if (name == null) { // System.out.println("Missing name for: " + code); continue; @@ -670,7 +674,7 @@ public void addName(String name, String code, boolean skipMessage) { public String getCldrValue(CLDRFile cldrFile, String id) { String result = cldrFile.getStringValue(getPath(id)); - // cldrFile.getName(CLDRFile.LANGUAGE_NAME, id, false); + // cldrFile.nameGetter().getName(CLDRFile.LANGUAGE_NAME, id, false); if (result == null && type == Type.TIMEZONE) { String[] parts = id.split("/"); result = parts[parts.length - 1].replace("_", " "); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindHardInheritance.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindHardInheritance.java index 7bd53198214..9f62a365724 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindHardInheritance.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindHardInheritance.java @@ -82,7 +82,8 @@ public String toString() { public static void main(String[] args) { // for (String localeId : CLDRConfig.getInstance().getCldrFactory().getAvailable()) { - // String name = CLDRConfig.getInstance().getEnglish().getName(localeId); + // String name = + // CLDRConfig.getInstance().getEnglish().nameGetter().getName(localeId); // System.out.println(localeId + "\t" + name); // } // if (true) return; diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindPluralDifferences.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindPluralDifferences.java index 5da449bf1de..1b19d1d6437 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindPluralDifferences.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindPluralDifferences.java @@ -134,7 +134,10 @@ public static void diff() { + "➞" + newVersion + "\t" - + ToolConfig.getToolInstance().getEnglish().getName(locale) + + ToolConfig.getToolInstance() + .getEnglish() + .nameGetter() + .getNameFromBCP47(locale) + "\t" + locale + "\t" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindPreferredHours.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindPreferredHours.java index c8dfeba32d0..6991bbe1d84 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindPreferredHours.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FindPreferredHours.java @@ -237,7 +237,7 @@ public static void main(String[] args) { // else { // if (!haveFirst) { // System.out.print("*** Conflict in\t" + region + "\t" + - // ENGLISH.getName("territory", region) + + // ENGLISH.nameGetter().getName("territory", region) + // "\twith\t"); // System.out.println(preferred + "\t" + locales); // haveFirst = true; @@ -267,15 +267,15 @@ public static void main(String[] args) { + "\t" + region + "\t" - + ENGLISH.getName("territory", region) + + ENGLISH.nameGetter().getNameFromTypestrCode("territory", region) + "\t" + subcontinent + "\t" - + ENGLISH.getName("territory", subcontinent) + + ENGLISH.nameGetter().getNameFromTypestrCode("territory", subcontinent) + "\t" + continent + "\t" - + ENGLISH.getName("territory", continent) + + ENGLISH.nameGetter().getNameFromTypestrCode("territory", continent) + "\t" + showInfo(preferredSet)); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FixTransformNames.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FixTransformNames.java index 756ef0e2f9b..4dac25e3942 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FixTransformNames.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/FixTransformNames.java @@ -41,7 +41,7 @@ public static void main(String[] args) { private void run(String[] args) { CLDRFile file = testInfo.getEnglish(); for (String lang : StandardCodes.make().getAvailableCodes(CodeType.language)) { - String name = file.getName(lang); + String name = file.nameGetter().getNameFromBCP47(lang); if (!name.equals(lang)) { fieldToCode.put(name, lang); languageCodes.add(lang); @@ -251,7 +251,7 @@ private String getName(String target) { } return result; } - return english.getName(target.replace('-', '_')); + return english.nameGetter().getNameFromBCP47(target.replace('-', '_')); } private String add(String result, int type, String code) { @@ -261,7 +261,7 @@ private String add(String result, int type, String code) { if (result.length() != 0) { result += ", "; } - String temp = english.getName(type, code); + String temp = english.nameGetter().getNameFromTypenumCode(type, code); if (type == CLDRFile.SCRIPT_NAME && fieldToCode.containsKey(temp)) { temp += "*"; } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateChangeChart.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateChangeChart.java index 4700cea23ae..57c8432061d 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateChangeChart.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateChangeChart.java @@ -104,7 +104,12 @@ public static void main(String[] args) throws IOException { data.add(key); counter.add(ph.getSectionId(), 1); } - final String summaryLine = locale + "\t" + ENGLISH.getName(locale) + "\t" + counter; + final String summaryLine = + locale + + "\t" + + ENGLISH.nameGetter().getNameFromBCP47(locale) + + "\t" + + counter; System.out.println(summaryLine); out.println(summaryLine); } @@ -225,7 +230,7 @@ void add( String newValue, String engValue, int votes) { - final String name = ENGLISH.getName(locale.toString()); + final String name = ENGLISH.nameGetter().getNameFromBCP47(locale.toString()); PageId pageId = pathHeader.getPageId(); String header = pathHeader.getHeader(); String code = pathHeader.getCode(); @@ -296,7 +301,7 @@ void add( String newValue, String engValue, int votes) { - final String name = ENGLISH.getName(locale.toString()); + final String name = ENGLISH.nameGetter().getNameFromBCP47(locale.toString()); PageId pageId = pathHeader.getPageId(); String header = pathHeader.getHeader(); String code = pathHeader.getCode(); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateComparison.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateComparison.java index 4019c5ba1b8..14a8385d0b4 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateComparison.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateComparison.java @@ -106,7 +106,7 @@ public static void main(String[] args) throws IOException { unifiedList.addAll(newList); Set<R2<String, String>> pairs = new TreeSet<>(); for (String code : unifiedList) { - pairs.add(Row.of(english.getName(code), code)); + pairs.add(Row.of(english.nameGetter().getNameFromBCP47(code), code)); } prettyPathMaker = new PrettyPath(); @@ -197,7 +197,7 @@ public static void main(String[] args) throws IOException { // TODO Sort by the pretty form // Set<R2<String,String>> pathPairs = new TreeSet(); // for (String code : unifiedList) { - // pairs.add(Row.make(code, english.getName(code))); + // pairs.add(Row.make(code, english.nameGetter().getName(code))); // } // Initialize sets @@ -205,7 +205,7 @@ public static void main(String[] args) throws IOException { // href='likely_subtags.html#und_{0}'>{0}</a>", // "class='source'", true) - final String localeDisplayName = english.getName(locale); + final String localeDisplayName = english.nameGetter().getNameFromBCP47(locale); TablePrinter table = new TablePrinter() .setCaption("Changes in " + localeDisplayName + " (" + locale + ")") diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateCoverageLevels.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateCoverageLevels.java index 77f82011625..e3008a1386f 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateCoverageLevels.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateCoverageLevels.java @@ -33,6 +33,7 @@ import org.unicode.cldr.util.Factory; import org.unicode.cldr.util.LanguageTagParser; import org.unicode.cldr.util.Level; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.SupplementalDataInfo; import org.unicode.cldr.util.SupplementalDataInfo.PluralType; import org.unicode.cldr.util.XPathParts; @@ -56,6 +57,7 @@ public class GenerateCoverageLevels { private static final Factory cldrFactory = Factory.make(MAIN_DIRECTORY, FILES); private static final Comparator<String> attributeComparator = CLDRFile.getAttributeOrdering(); private static final CLDRFile english = cldrFactory.make("en", true); + private static final NameGetter englishNameGetter = english.nameGetter(); private static SupplementalDataInfo supplementalData = CLDRConfig.getInstance().getSupplementalDataInfo(); // SupplementalDataInfo.getInstance(english.getSupplementalDirectory()); @@ -340,7 +342,7 @@ private static void summarizeCoverage( localesFound.clear(); for (String locale : rbnfFactory.getAvailable()) { if (localeFilter.skipLocale(locale, null)) continue; - System.out.println(locale + "\t" + english.getName(locale)); + System.out.println(locale + "\t" + englishNameGetter.getNameFromBCP47(locale)); getRBNFData(locale, rbnfFactory.make(locale, true), ordinals, spellout, localesFound); } markData( @@ -378,7 +380,7 @@ private static void summarizeCoverage( localesFound.clear(); for (String locale : collationFactory.getAvailable()) { if (localeFilter.skipLocale(locale, null)) continue; - System.out.println(locale + "\t" + english.getName(locale)); + System.out.println(locale + "\t" + englishNameGetter.getNameFromBCP47(locale)); getCollationData(locale, collationFactory.make(locale, true), localesFound); } markData( @@ -392,7 +394,7 @@ private static void summarizeCoverage( System.out.println("gathering main data"); for (String locale : mainAvailable) { - System.out.println(locale + "\t" + english.getName(locale)); + System.out.println(locale + "\t" + englishNameGetter.getNameFromBCP47(locale)); LevelData levelData = mapLevelData.get(locale); getMainData(locale, levelData, cldrFactory.make(locale, true)); } @@ -418,17 +420,19 @@ private static void summarizeCoverage( new StringBuilder( script + "\t" - + english.getName(CLDRFile.SCRIPT_NAME, script) + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.SCRIPT_NAME, script) + "\t" + lang + "\t" - + english.getName(CLDRFile.LANGUAGE_NAME, lang)); + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.LANGUAGE_NAME, lang)); if (header != null) { header.append("Code\tScript\tCode\tLocale"); } // Now print the information samples2.println(); - samples2.println(locale + "\t" + english.getName(locale)); + samples2.println(locale + "\t" + englishNameGetter.getNameFromBCP47(locale)); double weightedFound = 0; double weightedMissing = 0; long missingCountTotal = 0; @@ -492,7 +496,12 @@ private static void summarizeCoverage( + "\t" + percent.format(foundCount / (foundCount + missingCount)); samples2.println(summaryLine); - summary.println(locale + "\t" + english.getName(locale) + "\t" + summaryLine2); + summary.println( + locale + + "\t" + + englishNameGetter.getNameFromBCP47(locale) + + "\t" + + summaryLine2); if (header != null) { counts.println(header); header = null; @@ -552,7 +561,12 @@ private static void markData( mapLevelData.get(locale).found.add(level, weight); } else { System.out.println( - locale + "\t" + english.getName(locale) + "\t" + "missing " + title); + locale + + "\t" + + englishNameGetter.getNameFromBCP47(locale) + + "\t" + + "missing " + + title); mapLevelData.get(locale).missing.add(level, weight); mapLevelData.get(locale).samples.put(level, samples); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateDayPeriodChart.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateDayPeriodChart.java index d205f9dab91..d44e002f5d5 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateDayPeriodChart.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateDayPeriodChart.java @@ -103,7 +103,12 @@ public static void main(String[] args) { for (String locale : dayPeriodLocales) { // SC.getLocaleCoverageLocales("cldr", // EnumSet.of(Level.MODERN))) { - System.out.print(type + "\t" + locale + "\t" + ENGLISH.getName(locale)); + System.out.print( + type + + "\t" + + locale + + "\t" + + ENGLISH.nameGetter().getNameFromBCP47(locale)); DayPeriodInfo dayPeriod = getFixedDayPeriodInfo(type, locale); doRow(dayPeriod); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateDerivedAnnotations.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateDerivedAnnotations.java index a7a55fff1b4..bc73fd3ad9c 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateDerivedAnnotations.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateDerivedAnnotations.java @@ -176,7 +176,10 @@ public static void main(String[] args) throws IOException { if (main == null) { main = cldrFactory.make(locale, true); } - shortName = main.getName(CLDRFile.CURRENCY_NAME, currencyCode); + shortName = + main.nameGetter() + .getNameFromTypenumCode( + CLDRFile.CURRENCY_NAME, currencyCode); if (shortName.contentEquals(currencyCode)) { shortName = null; // don't want fallback raw code } @@ -216,7 +219,7 @@ public static void main(String[] args) throws IOException { + "\t" + level + "\t" - + english.getName(locale) + + english.nameGetter().getNameFromBCP47(locale) + "\t" + failures.size() + "\t" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateEnums.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateEnums.java index 6f828ab1a02..cd3e1fbeb81 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateEnums.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateEnums.java @@ -34,6 +34,7 @@ import org.unicode.cldr.util.Iso639Data.Scope; import org.unicode.cldr.util.Iso639Data.Type; import org.unicode.cldr.util.Log; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.StandardCodes; import org.unicode.cldr.util.StandardCodes.LstrType; import org.unicode.cldr.util.SupplementalDataInfo; @@ -68,6 +69,7 @@ public class GenerateEnums { // private Map enum_TLD = new TreeMap(); private CLDRFile english = factory.make("en", false); + private final NameGetter englishNameGetter = english.nameGetter(); private CLDRFile supplementalMetadata = factory.make("supplementalMetadata", false); @@ -135,7 +137,7 @@ private void showCurrencies() throws IOException { } private String getName(String code) { - String result = english.getName(CLDRFile.CURRENCY_NAME, code); + String result = englishNameGetter.getNameFromTypenumCode(CLDRFile.CURRENCY_NAME, code); if (result == null) { result = code; System.out.println("Failed to find: " + code); @@ -174,7 +176,8 @@ private void showScripts() throws IOException { int len = " /** Arabic */ Arab,".length(); for (Iterator<String> it = scripts.iterator(); it.hasNext(); ) { String code = it.next(); - String englishName = english.getName(CLDRFile.SCRIPT_NAME, code); + String englishName = + englishNameGetter.getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, code); if (englishName == null) continue; printRow(Log.getLog(), code, null, "script", code_replacements, len); // Log.println(" /**" + englishName + "*/ " + code + ","); @@ -222,7 +225,8 @@ private void showLanguages() throws IOException { for (Iterator<String> it = languages.iterator(); it.hasNext(); ) { String code = it.next(); - String englishName = english.getName(CLDRFile.LANGUAGE_NAME, code); + String englishName = + englishNameGetter.getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, code); if (englishName == null) continue; System.out.println(" /**" + englishName + "*/ " + code + ","); } @@ -640,7 +644,7 @@ private void showRegionCodeInfo() throws IOException { format(popData.getPopulation()), format(popData.getLiteratePopulation() / popData.getPopulation()), format(popData.getGdp()), - english.getName("territory", territory)); + englishNameGetter.getNameFromTypestrCode("territory", territory)); // remove all the ISO 639-3 until they are part of BCP 47 // we need to remove in earlier pass so we have the count Set<String> languages = new TreeSet<>(); @@ -671,7 +675,7 @@ private void showRegionCodeInfo() throws IOException { format(popData.getPopulation()), format(popData.getLiteratePopulation() / popData.getPopulation()), (count == 0 ? ";" : ""), - english.getName(language)); + englishNameGetter.getNameFromBCP47(language)); } } Log.close(); @@ -733,7 +737,12 @@ private void showRegionCodeInfo() throws IOException { // dumb // octal // syntax - System.out.println(un + "\t" + region + "\t" + english.getName("territory", region)); + System.out.println( + un + + "\t" + + region + + "\t" + + englishNameGetter.getNameFromTypestrCode("territory", region)); } showGeneratedCommentEnd(DATA_INDENT); @@ -873,7 +882,8 @@ private void printRow( ? getEnglishName(codeName) : type.equals("currency") ? getName(codeName) - : english.getName(CLDRFile.SCRIPT_NAME, codeName); + : englishNameGetter.getNameFromTypenumCode( + CLDRFile.SCRIPT_NAME, codeName); resolvedEnglishName = doFallbacks.transliterate(resolvedEnglishName); String prefix = CODE_INDENT + "/** " + resolvedEnglishName; // + " - " + @@ -910,7 +920,7 @@ private String getEnglishName(String codeName) { if (codeName.length() > 3) codeName = codeName.substring(2); // fix UN name String name = extraNames.get(codeName); if (name != null) return name; - name = english.getName(CLDRFile.TERRITORY_NAME, codeName); + name = englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, codeName); if (name != null) return name; return codeName; } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateG2xG2.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateG2xG2.java index 0b787eab385..ed776d84248 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateG2xG2.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateG2xG2.java @@ -219,7 +219,8 @@ private static boolean showLocales(int choice) throws Exception { String territory = it.next(); if (territory.charAt(0) < 'A') continue; String locale = "haw-" + territory; - System.out.print(locale + ": " + english.getName(locale) + ", "); + System.out.print( + locale + ": " + english.nameGetter().getNameFromBCP47(locale) + ", "); } if (true) return true; } @@ -232,7 +233,10 @@ private static boolean showLocales(int choice) throws Exception { for (Iterator it = testSet.iterator(); it.hasNext(); ) { String country = (String) it.next(); System.out.println( - country + "\t" + english.getName(CLDRFile.CURRENCY_NAME, country)); + country + + "\t" + + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.CURRENCY_NAME, country)); } return true; } else if (choice == 0) { // get available @@ -335,9 +339,9 @@ static void checkItems( + "\t" + sourceLocale + "\t(" - + english.getName(sourceLocale) + + english.nameGetter().getNameFromBCP47(sourceLocale) + ": " - + sourceData.getName(sourceLocale) + + sourceData.nameGetter().getNameFromBCP47(sourceLocale) + ")" + "\t" + priorityMap.get(item) @@ -385,9 +389,9 @@ private static String getTypeName(String item) { private static String getItemName(CLDRFile data, int type, String item) { String result; if (type == CLDRFile.LANGUAGE_NAME) { - result = data.getName(item); + result = data.nameGetter().getNameFromBCP47(item); } else if (type != CLDRFile.TZ_EXEMPLAR) { - result = data.getName(type, item); + result = data.nameGetter().getNameFromTypenumCode(type, item); } else { String prefix = "//ldml/dates/timeZoneNames/zone[@type=\"" + item + "\"]/exemplarCity"; result = data.getStringValue(prefix); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateKaraList.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateKaraList.java index 0e3cd69be4e..9137eb74b43 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateKaraList.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateKaraList.java @@ -97,7 +97,7 @@ private static void printCodes( Set<String> errors = new HashSet<>(); for (Iterator<String> it = availableCodes.iterator(); it.hasNext(); ) { String id = it.next(); - String ename = english.getName(choice, id); + String ename = english.nameGetter().getNameFromTypenumCode(choice, id); if (ename == null) ename = "[untranslated: " + id + "]"; System.out.println(id + "\t" + ename); log.println("\t<entry>"); @@ -115,7 +115,8 @@ private static void printCodes( log.println("\t\t\t<epos>n</epos>"); // this is the part of speech value. It is fixed. log.println("\t\t\t<sense>"); if (hasAbbreviation) { // only applicable for the currency entries - String aename = english.getName(CLDRFile.CURRENCY_SYMBOL, id); + String aename = + english.nameGetter().getNameFromTypenumCode(CLDRFile.CURRENCY_SYMBOL, id); if (aename != null) { log.println( "\t\t\t\t<eabbr>" @@ -127,7 +128,7 @@ private static void printCodes( String locale = it2.next(); try { CLDRFile cldrfile = cldrFactory.make(locale, true); - String trans = cldrfile.getName(choice, id); + String trans = cldrfile.nameGetter().getNameFromTypenumCode(choice, id); if (trans == null) continue; log.println("\t\t\t\t<target>"); // one target block for each language // String etrans = getName(english, "languages/language", locale, true); @@ -136,7 +137,7 @@ private static void printCodes( + locale + "</tlanguage>\t<!-- " + TransliteratorUtilities.toXML.transliterate( - english.getName(locale)) + english.nameGetter().getNameFromBCP47(locale)) + " -->"); // We do use // non-ISO // values but @@ -158,7 +159,9 @@ private static void printCodes( + TransliteratorUtilities.toXML.transliterate(trans) + "</trans>"); if (hasAbbreviation) { - String aename = cldrfile.getName(CLDRFile.CURRENCY_SYMBOL, id); + String aename = + cldrfile.nameGetter() + .getNameFromTypenumCode(CLDRFile.CURRENCY_SYMBOL, id); if (aename != null && !aename.equals(id)) { log.println( "\t\t\t\t\t<tabbr>" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLanguageData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLanguageData.java index 08a4a32f51e..47783f9abe4 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLanguageData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLanguageData.java @@ -71,7 +71,7 @@ public static void main(String[] args) throws IOException { xpp.setAttribute(-1, LDMLConstants.TYPE, languageCode); String xpath = xpp.toString(); - newEn.add(xpp.toString(), oldEn.getName(languageCode)); + newEn.add(xpp.toString(), oldEn.nameGetter().getNameFromBCP47(languageCode)); String oldValue = oldEn.getStringValue(xpath); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLanguageMatches.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLanguageMatches.java index 21701cf7abf..04fe4bd4015 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLanguageMatches.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLanguageMatches.java @@ -113,6 +113,7 @@ public String transform(@SuppressWarnings("unused") String source) { }; private static String getName(String lang) { - return ENGLISH.getName(CLDRFile.LANGUAGE_NAME, lang, MENU); + return ENGLISH.nameGetter() + .getNameFromTypeCodeAltpicker(CLDRFile.LANGUAGE_NAME, lang, MENU); } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLikelySubtagTests.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLikelySubtagTests.java index 9afa4c9d275..8cb4297f51a 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLikelySubtagTests.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLikelySubtagTests.java @@ -200,17 +200,18 @@ public static String printingName(String locale, String spacing) { + spacing + (lang.equals(LocaleNames.UND) ? "?" - : ENGLISH.getName(CLDRFile.LANGUAGE_NAME, lang)) + : ENGLISH.nameGetter().getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, lang)) + ";" + spacing + (script == null || script.equals("") ? "?" - : ENGLISH.getName(CLDRFile.SCRIPT_NAME, script)) + : ENGLISH.nameGetter().getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script)) + ";" + spacing + (region == null || region.equals("") ? "?" - : ENGLISH.getName(CLDRFile.TERRITORY_NAME, region)) + : ENGLISH.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, region)) + spacing + "}"; } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLikelySubtags.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLikelySubtags.java index 70d21083044..443de3e9aa8 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLikelySubtags.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLikelySubtags.java @@ -666,7 +666,7 @@ private String replaceMissing(String field, String ifEqual, String replacement) public static String getNameSafe(String oldValue) { try { if (oldValue != null) { - String result = english.getName(oldValue); + String result = english.nameGetter().getNameFromBCP47(oldValue); if (result.startsWith("Unknown language ")) { result = result.substring("Unknown language ".length()); } @@ -739,7 +739,7 @@ private static Map<String, String> generatePopulationData(Map<String, String> to // // if (SHOW_ADD) // // System.out.println("Skipping:\t" + writtenLanguage // + "\t" + region + "\t" - // // + english.getName(locale) + // // + english.nameGetter().getName(locale) // // + "\t-- too small:\t" + // number.format(literatePopulation)); // // continue; @@ -1691,13 +1691,16 @@ public static String printingName(String locale, Joiner spacing) { return spacing.join( (lang.equals(LocaleNames.UND) ? "?" - : english.getName(CLDRFile.LANGUAGE_NAME, lang)), + : english.nameGetter() + .getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, lang)), (script == null || script.equals("") ? "?" - : english.getName(CLDRFile.SCRIPT_NAME, script)), + : english.nameGetter() + .getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script)), (region == null || region.equals("") ? "?" - : english.getName(CLDRFile.TERRITORY_NAME, region))); + : english.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, region))); } static final String SEPARATOR = diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLocaleIDTestData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLocaleIDTestData.java index 1af58bf967a..8c44fc4e501 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLocaleIDTestData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateLocaleIDTestData.java @@ -230,7 +230,10 @@ private static Map<String, String> prepareDisplayNames( CLDRFile formattingLocaleFile, boolean onlyConstructCompound, String... locales) { Map<String, String> displayNames = new TreeMap<>(); for (String locale : locales) { - String name = formattingLocaleFile.getName(locale, onlyConstructCompound); + String name = + formattingLocaleFile + .nameGetter() + .getNameFromBCP47Bool(locale, onlyConstructCompound); if (name.contains("null")) { System.err.println("** REPLACE: " + locale + "; " + name); } else { diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GeneratePluralRanges.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GeneratePluralRanges.java index ffbf7cd0877..129fd2c22b0 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GeneratePluralRanges.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GeneratePluralRanges.java @@ -99,7 +99,7 @@ private void generateSamples(CLDRFile english, Factory factory) { System.out.println( locale + "\t" - + english.getName(locale) + + english.nameGetter().getNameFromBCP47(locale) + "\t" + rangeSample.start + "\t" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateSeedDurations.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateSeedDurations.java index 01f0a4a7ceb..90b69b00014 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateSeedDurations.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateSeedDurations.java @@ -43,7 +43,8 @@ public static void main(String[] args) { Set<String> warnings = new LinkedHashSet<>(); for (String locale : cldrFactory.getAvailableLanguages()) { CLDRFile cldrFile = cldrFactory.make(locale, true); - String localeString = locale + "\t" + testInfo.getEnglish().getName(locale); + String localeString = + locale + "\t" + testInfo.getEnglish().nameGetter().getNameFromBCP47(locale); System.out.println("\n" + localeString); DateTimeFormats formats = new DateTimeFormats().set(cldrFile, "gregorian"); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateSidewaysView.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateSidewaysView.java index 7166e514950..34f58d9140b 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateSidewaysView.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateSidewaysView.java @@ -612,7 +612,7 @@ private static String cleanLocale(String item, boolean name) { String core = item; item = toHTML.transform(item); if (name) { - item = english.getName(core); + item = english.nameGetter().getNameFromBCP47(core); item = item == null ? "<i>null</i>" : toHTML.transform(item); } if (draft) { diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateStatistics.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateStatistics.java index 79c722f6261..03a599bbfb8 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateStatistics.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateStatistics.java @@ -309,7 +309,7 @@ private static void addCounts( String nativeName, englishName; draftLanguages.add(lang); nativeName = getFixedLanguageName(localeID, langScript); - englishName = english.getName(langScript); + englishName = english.nameGetter().getNameFromBCP47(langScript); if (!lang.equals("en") && nativeName.equals(englishName)) { Log.logln( (isDraft ? "D" : "") @@ -399,7 +399,7 @@ private static String getFixedLanguageName(String localeID, String lang) { } } CLDRFile cldr = factory.make(localeID, true); - return cldr.getName(lang); + return cldr.nameGetter().getNameFromBCP47(lang); } /** @@ -414,7 +414,7 @@ private static String getFixedDisplayCountry(String localeID, String country) { } } CLDRFile cldr = factory.make(localeID, true); - String name = cldr.getName("territory", country); + String name = cldr.nameGetter().getNameFromTypestrCode("territory", country); if (false && HACK) { Object trial = fixCountryNames.get(name); if (trial != null) { diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GetChanges.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GetChanges.java index e3435e32319..79f945e03fe 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GetChanges.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GetChanges.java @@ -340,7 +340,7 @@ private void old() { + "\t" + locale + "\t" - + english.getName(locale) + + english.nameGetter().getNameFromBCP47(locale) + "\t" + ph + "\t«" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GetLanguageData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GetLanguageData.java index f4ef82ed0aa..e0eaca91e1b 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GetLanguageData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GetLanguageData.java @@ -27,7 +27,7 @@ private void run() { System.out.println("Code\tLang\tLpop\tApprox. Gdp"); for (String language : sdata.getLanguages()) { final long pop = languageToPop.getCount(language); - System.out.print(language + "\t" + english.getName(language)); + System.out.print(language + "\t" + english.nameGetter().getNameFromBCP47(language)); if (pop > 0) { Pair<OfficialStatus, String> status = isOfficialLanguageOfEUCountry(language); System.out.print( @@ -70,7 +70,8 @@ private void findSuspectData() { System.out.println( territory // + "\t" - + english.getName("territory", territory) // + + english.nameGetter() + .getNameFromTypestrCode("territory", territory) // + "\t" + territoryPop // + "\t" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/LSRSource.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/LSRSource.java index 1699203fcf4..71b42335efc 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/LSRSource.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/LSRSource.java @@ -88,9 +88,9 @@ public String line(String source) { + (getSources().isEmpty() ? "" : "\" origin=\"" + getSourceString()) + "\"/>" + "\t<!-- " - + english.getName(source) + + english.nameGetter().getNameFromBCP47(source) + " ➡︎ " - + english.getName(target) + + english.nameGetter().getNameFromBCP47(target) + " -->"; return result; } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/LanguageCodeConverter.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/LanguageCodeConverter.java index fe385b4e77e..d885aaef49d 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/LanguageCodeConverter.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/LanguageCodeConverter.java @@ -126,7 +126,7 @@ public class LanguageCodeConverter { // if (languageAliases.containsKey(code)) { // continue; // } - // String cldrName = english.getName("language", code); + // String cldrName = english.nameGetter().getName("language", code); // if (cldrName != null && !cldrName.equals("private-use")) { // addNameToCode("cldr", code, cldrName); // } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ListGrammarData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ListGrammarData.java index b229f542919..8e70f94822f 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ListGrammarData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ListGrammarData.java @@ -124,7 +124,7 @@ public static void main(String[] args) { continue; } // System.out.println(locale); - final String names = locale + "\t" + ENGLISH.getName(locale); + final String names = locale + "\t" + ENGLISH.nameGetter().getNameFromBCP47(locale); for (Entry<PathHeader, String> entry : pathHeaderToValue.entrySet()) { final PathHeader ph = entry.getKey(); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ListGrammarInfo.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ListGrammarInfo.java index 43aae86cffa..3c79d093cc1 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ListGrammarInfo.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ListGrammarInfo.java @@ -71,7 +71,7 @@ public static void main(String[] args) { private static String format( String locale, Collection<String> genders, Collection<String> rawCases) { - return english.getName(locale) + return english.nameGetter().getNameFromBCP47(locale) + " (" + locale + "/" @@ -82,6 +82,11 @@ private static String format( } public static String format(String locale, Collection<String> genders) { - return english.getName(locale) + " (" + locale + "/" + genders.size() + ")"; + return english.nameGetter().getNameFromBCP47(locale) + + " (" + + locale + + "/" + + genders.size() + + ")"; } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/Misc.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/Misc.java index f8feea691c0..b58fac740e3 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/Misc.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/Misc.java @@ -281,7 +281,8 @@ private static void listObsoletes() { + " => " + replacementCode + "; " - + english.getName(type, replacementCode)); + + english.nameGetter() + .getNameFromTypestrCode(type, replacementCode)); } } } @@ -352,7 +353,7 @@ private static void printAllZoneLocalizations() throws IOException { // do the header for (Iterator<String> it2 = priorities.iterator(); it2.hasNext(); ) { String locale = it2.next(); - String englishLocaleName = english.getName(locale); + String englishLocaleName = english.nameGetter().getNameFromBCP47(locale); out.println("<th>" + locale + " (" + englishLocaleName + ")" + "</th>"); } @@ -370,7 +371,9 @@ private static void printAllZoneLocalizations() throws IOException { out.println("<th>" + (++count) + "</th>"); out.println("<th>" + zone + "</th>"); String country = zone_country.get(zone); - String countryName = english.getName(CLDRFile.TERRITORY_NAME, country); + String countryName = + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, country); out.println("<td>" + country + " (" + countryName + ")" + "</td>"); TimeZone tzone = TimeZone.getTimeZone(zone); out.println("<td>" + offsetString(tzone) + "</td>"); @@ -477,7 +480,11 @@ static void printZoneAliases() { String zone = it.next(); new_old.put(zone, new TreeSet<String>(col)); String country = zone_countries.get(zone); - String name = english.getName("territory", country) + " (" + country + ")"; + String name = + english.nameGetter().getNameFromTypestrCode("territory", country) + + " (" + + country + + ")"; Set<String> oldSet = country_zones.get(name); if (oldSet == null) country_zones.put(name, oldSet = new TreeSet<>(col)); oldSet.add(zone); @@ -651,7 +658,10 @@ private static void printCurrentTimezoneLocalizations(PrintWriter log, String lo for (Iterator<String> it = zone_countries.keySet().iterator(); it.hasNext(); ) { String zoneID = it.next(); String country = zone_countries.get(zoneID); - String countryName = desiredLocaleFile.getName(CLDRFile.TERRITORY_NAME, country); + String countryName = + desiredLocaleFile + .nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, country); if (countryName == null) countryName = UTF16.valueOf(0x10FFFD) + country; reordered.put(countryName + "0" + zoneID, zoneID); } @@ -663,7 +673,10 @@ private static void printCurrentTimezoneLocalizations(PrintWriter log, String lo String key = it.next(); String zoneID = reordered.get(key); String country = zone_countries.get(zoneID); - String countryName = desiredLocaleFile.getName(CLDRFile.TERRITORY_NAME, country); + String countryName = + desiredLocaleFile + .nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, country); if (countryName == null) countryName = country; log.println( "<tr><th class='ID' colspan=\"4\"><table><tr><th class='I'>" @@ -1198,7 +1211,10 @@ private static void printTimezonesToLocalize( + key + "\" draft=\"unconfirmed\">" + TransliteratorUtilities.toXML.transliterate( - "TODO " + english.getName(CLDRFile.TERRITORY_NAME, key)) + "TODO " + + english.nameGetter() + .getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, key)) + "</territory>"); } log2.println("</territories></localeDisplayNames>"); @@ -1215,7 +1231,9 @@ private static void printTimezonesToLocalize( String key = it.next(); List<String> data = StandardCodes.make().getZoneData().get(key); String countryCode = data.get(2); - String country = english.getName(CLDRFile.TERRITORY_NAME, countryCode); + String country = + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, countryCode); if (!country.equals(lastCountry)) { lastCountry = country; log2.println("\t<!-- " + country + "-->"); @@ -1324,7 +1342,7 @@ private static String getName(CLDRFile localization, String key, Set<String>[] m name = name.replace('_', ' '); } } else { - name = localization.getName(CLDRFile.TERRITORY_NAME, key); + name = localization.nameGetter().getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, key); if (name == null) { if (missing != null) missing[0].add(key); name = key; diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ScriptPopulations.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ScriptPopulations.java index 7eb6b2b3b76..53309afb9e5 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ScriptPopulations.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ScriptPopulations.java @@ -63,9 +63,10 @@ public static void main(String[] args) { + "\t" + langScriptLitPop.getCount(lang) + "\t" - + english.getName(baseLanguage) + + english.nameGetter().getNameFromBCP47(baseLanguage) + "\t" - + english.getName(CLDRFile.SCRIPT_NAME, script) + + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script) + "\t" + officialStatus + "\t" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowChildren.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowChildren.java index d921c233327..e23dcf16d99 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowChildren.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowChildren.java @@ -42,7 +42,7 @@ public static void main(String[] args) { for (Entry<String, Set<String>> entry : parent2children.keyValuesSet()) { Map<String, Relation<String, String>> path2value2locales = new TreeMap<>(); String parent = entry.getKey(); - String parentName = english.getName(parent); + String parentName = english.nameGetter().getNameFromBCP47(parent); CLDRFile parentFile = cldrFactory.make(parent, true); Set<String> children = entry.getValue(); @@ -99,7 +99,7 @@ public static void main(String[] args) { deviations.add(parent, path2value2locales.size()); } for (String locale : deviations.getKeysetSortedByKey()) { - String parentName = english.getName(locale); + String parentName = english.nameGetter().getNameFromBCP47(locale); System.out.println(parentName + "\t" + locale + "\t" + deviations.get(locale)); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowData.java index af4f37e87a8..f46afe26976 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowData.java @@ -517,15 +517,21 @@ private static void getScripts() throws IOException { System.out.println(locale); CLDRFile file = cldrFactory.make(locale, false); if (file.isNonInheriting()) continue; - String localeName = file.getName(locale); + String localeName = file.nameGetter().getNameFromBCP47(locale); getScripts(localeName, scripts); if (!scripts.contains("Latn")) { - out.println(locale + "\t" + english.getName(locale) + "\t" + localeName); + out.println( + locale + + "\t" + + english.nameGetter().getNameFromBCP47(locale) + + "\t" + + localeName); } for (Iterator<String> it2 = UnicodeScripts.iterator(); it2.hasNext(); ) { String script = it2.next(); if (script.equals("Latn")) continue; - String name = file.getName(CLDRFile.SCRIPT_NAME, script); + String name = + file.nameGetter().getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script); if (getScripts(name, scripts).contains(script)) { Map<String, Set<String>> names_locales = script_name_locales.get(script); if (names_locales == null) @@ -540,7 +546,12 @@ private static void getScripts() throws IOException { String script = it2.next(); Object names = script_name_locales.get(script); out.println( - script + "\t(" + english.getName(CLDRFile.SCRIPT_NAME, script) + ")\t" + names); + script + + "\t(" + + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script) + + ")\t" + + names); } out.close(); } @@ -746,7 +757,7 @@ public static String getLinkedLocaleName(String locale) { } public static String getEnglishLocaleName(String locale) { - return english.getName(locale, true, CLDRFile.SHORT_ALTS); + return english.nameGetter().getNameFromBCP47BoolAlt(locale, true, CLDRFile.SHORT_ALTS); } private static String getLocaleNameAndCode(String locale) { diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguageData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguageData.java index 90bc5a37d59..15509ee91a0 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguageData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguageData.java @@ -50,11 +50,12 @@ public static void main(String[] args) { System.out.println( language + "\t" - + english.getName(language) + + english.nameGetter().getNameFromBCP47(language) + "\t" + territory + "\t" - + english.getName(CLDRFile.TERRITORY_NAME, territory) + + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, territory) + "\t" + litPop / (double) total); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguages.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguages.java index 3f0155fc307..1b04e2b277f 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguages.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLanguages.java @@ -67,6 +67,7 @@ import org.unicode.cldr.util.LanguageTagParser; import org.unicode.cldr.util.Level; import org.unicode.cldr.util.Log; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.Organization; import org.unicode.cldr.util.StandardCodes; import org.unicode.cldr.util.StandardCodes.CodeType; @@ -94,6 +95,7 @@ public class ShowLanguages { static Factory cldrFactory = CLDRConfig.getInstance().getCldrFactory(); // .make(CLDRPaths.MAIN_DIRECTORY, ".*"); static CLDRFile english = CLDRConfig.getInstance().getEnglish(); + private static NameGetter englishNameGetter = english.nameGetter(); public static void main(String[] args) throws IOException { System.out.println("Writing into " + FormattedFileWriter.CHART_TARGET_DIR); @@ -623,19 +625,22 @@ private static void addLanguageScriptCells2( } } } - String languageName = english.getName(CLDRFile.LANGUAGE_NAME, language); + String languageName = + englishNameGetter.getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, language); if (languageName == null) languageName = "???"; String isLanguageTranslated = ""; String nativeLanguageName = nativeLanguage == null ? null - : nativeLanguage.getName(CLDRFile.LANGUAGE_NAME, language); + : nativeLanguage + .nameGetter() + .getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, language); if (nativeLanguageName == null || nativeLanguageName.equals(language)) { nativeLanguageName = "<i>n/a</i>"; isLanguageTranslated = "n"; } - String scriptName = english.getName(CLDRFile.SCRIPT_NAME, script); + String scriptName = englishNameGetter.getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script); // String nativeScriptName = nativeLanguage == null ? null : // nativeLanguage.getName(CLDRFile.SCRIPT_NAME,script); // if (nativeScriptName != null && !nativeScriptName.equals(script)) { @@ -643,11 +648,14 @@ private static void addLanguageScriptCells2( // } String isTerritoryTranslated = ""; - String territoryName = english.getName(CLDRFile.TERRITORY_NAME, territory); + String territoryName = + englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, territory); String nativeTerritoryName = nativeLanguage == null ? null - : nativeLanguage.getName(CLDRFile.TERRITORY_NAME, territory); + : nativeLanguage + .nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, territory); if (nativeTerritoryName == null || nativeTerritoryName.equals(territory)) { nativeTerritoryName = "<i>n/a</i>"; isTerritoryTranslated = "n"; @@ -694,7 +702,7 @@ private static String getGifName(String script) { if (temp != null) { return temp; } - String scriptName = english.getName(CLDRFile.SCRIPT_NAME, script); + String scriptName = englishNameGetter.getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script); scriptName = scriptName.toLowerCase(Locale.ENGLISH); temp = fixScriptGif.get(scriptName); if (temp != null) { @@ -714,12 +722,14 @@ private static void addLanguageScriptCells( String script, String secondary) { try { - String languageName = english.getName(CLDRFile.LANGUAGE_NAME, language); + String languageName = + englishNameGetter.getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, language); if (languageName == null) { languageName = "¿" + language + "?"; System.err.println("No English Language Name for:" + language); } - String scriptName = english.getName(CLDRFile.SCRIPT_NAME, script); + String scriptName = + englishNameGetter.getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script); if (scriptName == null) { scriptName = "¿" + script + "?"; System.err.println("No English Language Name for:" + script); @@ -1139,7 +1149,7 @@ private String getName(final int type, final String value) { if (value == null || value.equals("") || value.equals("und")) { return "\u00A0"; } - String result = english.getName(type, value); + String result = englishNameGetter.getNameFromTypenumCode(type, value); if (result == null) { result = value; } @@ -1270,7 +1280,9 @@ private void showLanguageCountryInfo(PrintWriter pw) throws IOException { for (String territoryCode : supplementalDataInfo.getTerritoriesWithPopulationData()) { // PopulationData territoryData = // supplementalDataInfo.getPopulationDataForTerritory(territoryCode); - String territoryName = english.getName(CLDRFile.TERRITORY_NAME, territoryCode); + String territoryName = + englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, territoryCode); for (String languageCode : supplementalDataInfo.getLanguagesForTerritoryWithPopulationData( territoryCode)) { @@ -1362,7 +1374,9 @@ private String getLanguagePluralMessage(String msg, String languageCode) { } private String getLanguageName(String languageCode) { - String result = english.getName(languageCode, true, CLDRFile.SHORT_ALTS); + String result = + englishNameGetter.getNameFromBCP47BoolAlt( + languageCode, true, CLDRFile.SHORT_ALTS); if (!result.equals(languageCode)) return result; Set<String> names = Iso639Data.getNames(languageCode); if (names != null && names.size() != 0) { @@ -1550,7 +1564,8 @@ public void showTabbedOrgLevels( final String name = locale.equals("*") ? "ALL" - : english.getName(locale, true, CLDRFile.SHORT_ALTS); + : englishNameGetter.getNameFromBCP47BoolAlt( + locale, true, CLDRFile.SHORT_ALTS); coverageGoalsTsv.println( String.format( "%s\t;\t%s\t;\t%s\t;\t%s", organization, locale, level, name)); @@ -1677,7 +1692,9 @@ private void showCountryLanguageInfo(PrintWriter pw) throws IOException { .addColumn("Report Bug", "class='target'", null, "class='target'", false); for (String territoryCode : supplementalDataInfo.getTerritoriesWithPopulationData()) { - String territoryName = english.getName(CLDRFile.TERRITORY_NAME, territoryCode); + String territoryName = + englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, territoryCode); PopulationData territoryData2 = supplementalDataInfo.getPopulationDataForTerritory(territoryCode); double territoryLiteracy = territoryData2.getLiteratePopulationPercent(); @@ -1816,7 +1833,9 @@ private void showCountryInfo(PrintWriter pw) throws IOException { tablePrinter.addColumn("Report Bug", "class='target'", null, "class='target'", false); for (String territoryCode : supplementalDataInfo.getTerritoriesWithPopulationData()) { - String territoryName = english.getName(CLDRFile.TERRITORY_NAME, territoryCode); + String territoryName = + englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, territoryCode); PopulationData territoryData2 = supplementalDataInfo.getPopulationDataForTerritory(territoryCode); double population = territoryData2.getPopulation() / 1000000; @@ -1945,8 +1964,9 @@ private void addCharSubstitution(String value, String substitute) { // String territory = (String) it.next(); // String parent = (String) territory_parent.get(territory); // System.out.println(territory + "\t" + - // english.getName(english.TERRITORY_NAME, territory) + "\t" - // + parent + "\t" + english.getName(english.TERRITORY_NAME, parent)); + // englishNameGetter.getName(english.TERRITORY_NAME, territory) + "\t" + // + parent + "\t" + englishNameGetter.getName(english.TERRITORY_NAME, + // parent)); // } // } @@ -2040,7 +2060,8 @@ public void showCorrespondances() { Map<String, String> name_script = new TreeMap<>(); for (Iterator<String> it = sc.getAvailableCodes("script").iterator(); it.hasNext(); ) { String script = it.next(); - String name = english.getName(CLDRFile.SCRIPT_NAME, script); + String name = + englishNameGetter.getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script); if (name == null) name = script; name_script.put(name, script); /* @@ -2054,14 +2075,16 @@ public void showCorrespondances() { for (Iterator<String> it = sc.getAvailableCodes("language").iterator(); it.hasNext(); ) { String language = it.next(); - String names = english.getName(CLDRFile.LANGUAGE_NAME, language); + String names = + englishNameGetter.getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, language); if (names == null) names = language; name_language.put(names, language); } for (Iterator<String> it = sc.getAvailableCodes("language").iterator(); it.hasNext(); ) { String language = it.next(); - String names = english.getName(CLDRFile.LANGUAGE_NAME, language); + String names = + englishNameGetter.getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, language); if (names == null) names = language; String[] words = names.split(delimiter); if (words.length > 1) { @@ -2208,7 +2231,8 @@ public void printCurrency(PrintWriter index) throws IOException { + infoItem.getCurrency() + "</td>" + "<td class='target'>" - + english.getName("currency", infoItem.getCurrency()) + + englishNameGetter.getNameFromTypestrCode( + "currency", infoItem.getCurrency()) + "</td>" + "</tr>"); } @@ -2263,7 +2287,8 @@ public void printCurrency(PrintWriter index) throws IOException { "<tr>" + "<td class='source nowrap'>" + TransliteratorUtilities.toHTML.transform( - english.getName("currency", currency)) + englishNameGetter.getNameFromTypestrCode( + "currency", currency)) + "</td>" + "<td class='source'>" + CldrUtility.getDoubleLinkedText(currency) @@ -2323,7 +2348,8 @@ public void printCurrency(PrintWriter index) throws IOException { // for (Iterator it = territoriesWithoutCurrencies.iterator(); it.hasNext();) { // if (first) first = false; // else pw.print(", "); - // pw.print(english.getName(CLDRFile.TERRITORY_NAME, it.next().toString(), false)); + // pw.print(englishNameGetter.getName(CLDRFile.TERRITORY_NAME, it.next().toString(), + // false)); // } // pw.println("</td><td class='target'>"); // Set currenciesWithoutTerritories = new TreeSet(); @@ -2333,7 +2359,8 @@ public void printCurrency(PrintWriter index) throws IOException { // for (Iterator it = currenciesWithoutTerritories.iterator(); it.hasNext();) { // if (first) first = false; // else pw.print(", "); - // pw.print(english.getName(CLDRFile.CURRENCY_NAME, it.next().toString(), false)); + // pw.print(englishNameGetter.getName(CLDRFile.CURRENCY_NAME, it.next().toString(), + // false)); // } // pw.println("</td></tr>"); // doFooter(pw); @@ -2342,7 +2369,7 @@ public void printCurrency(PrintWriter index) throws IOException { private String getTerritoryName(String territory) { String name; - name = english.getName("territory", territory); + name = englishNameGetter.getNameFromTypestrCode("territory", territory); if (name == null) { name = sc.getData("territory", territory); } @@ -2736,7 +2763,7 @@ private String getName(int type, String oldcode, boolean codeFirst) { } else { int pos = oldcode.indexOf('*'); String code = pos < 0 ? oldcode : oldcode.substring(0, pos); - String ename = english.getName(type, code); + String ename = englishNameGetter.getNameFromTypenumCode(type, code); String nameString = ename == null ? code : ename; return nameString.equals(oldcode) ? nameString @@ -2945,7 +2972,7 @@ private static Map<String, Set<String>> getInverse( private static SortedMap<String, String> getNameToCode(CodeType codeType, String cldrCodeType) { SortedMap<String, String> temp = new TreeMap<String, String>(col); for (String territory : StandardCodes.make().getAvailableCodes(codeType)) { - String name = english.getName(cldrCodeType, territory); + String name = englishNameGetter.getNameFromTypestrCode(cldrCodeType, territory); temp.put(name == null ? territory : name, territory); } temp = Collections.unmodifiableSortedMap(temp); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLocaleCoverage.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLocaleCoverage.java index 946a06fd10c..546f9aa5bcc 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLocaleCoverage.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowLocaleCoverage.java @@ -889,8 +889,11 @@ private static void showCoverage( tablePrinter .addRow() .addCell(language) - .addCell(ENGLISH.getName(language, true, CLDRFile.SHORT_ALTS)) - .addCell(file.getName(language)) + .addCell( + ENGLISH.nameGetter() + .getNameFromBCP47BoolAlt( + language, true, CLDRFile.SHORT_ALTS)) + .addCell(file.nameGetter().getNameFromBCP47(language)) .addCell(script) .addCell(defRegion) .addCell(sublocales.size()) @@ -916,7 +919,7 @@ private static void showCoverage( + " ;\t" + visibleLevelComputed + " ;\t" - + ENGLISH.getName(locale)); + + ENGLISH.nameGetter().getNameFromBCP47(locale)); // TODO decide whether to restore this // Level higher = Level.UNDETERMINED; // switch (computed) { @@ -1175,9 +1178,9 @@ private static String spreadsheetLine( specialFlag + language + "\t" - + ENGLISH.getName(language) + + ENGLISH.nameGetter().getNameFromBCP47(language) + "\t" - + ENGLISH.getName("script", script) + + ENGLISH.nameGetter().getNameFromTypestrCode("script", script) + "\t" + cldrLocaleLevelGoal + "\t" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowPlurals.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowPlurals.java index 51403c1608d..46d293fe00c 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowPlurals.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowPlurals.java @@ -168,7 +168,7 @@ public void printPluralTable( if (localeFilter != null && !localeFilter.equals(locale) || locale.equals("root")) { continue; } - final String name = english.getName(locale); + final String name = english.nameGetter().getNameFromBCP47(locale); String canonicalLocale = canonicalizer.transform(locale); if (!locale.equals(canonicalLocale)) { String redirect = diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowRegionalVariants.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowRegionalVariants.java index ab4ffd81146..9cca8f42cc4 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowRegionalVariants.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowRegionalVariants.java @@ -200,7 +200,7 @@ public static void main(String[] args) throws IOException { grandSummary.println( parent + "\t" - + ENGLISH.getName(parent.toString()) + + ENGLISH.nameGetter().getNameFromBCP47(parent.toString()) + "\t" + totalChildDiffs + "\t" @@ -213,13 +213,13 @@ public static void main(String[] args) throws IOException { summary.println( parent + "\t" - + ENGLISH.getName(parent.toString()) + + ENGLISH.nameGetter().getNameFromBCP47(parent.toString()) + "\t" + childDiffValue + "\t" + s + "\t" - + ENGLISH.getName(s.toString())); + + ENGLISH.nameGetter().getNameFromBCP47(s.toString())); } ArrayList<CLDRFile> parentChain = new ArrayList<>(); @@ -324,7 +324,8 @@ private static String nameForLocale(CLDRLocale key) { LanguageTagParser ltp = new LanguageTagParser().set(max); country = "(" + ltp.getRegion() + ")"; } - return ENGLISH.getName(key.toString(), false, CLDRFile.SHORT_ALTS) + return ENGLISH.nameGetter() + .getNameFromBCP47BoolAlt(key.toString(), false, CLDRFile.SHORT_ALTS) + "\t" + key + "\t" diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowStarredCoverage.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowStarredCoverage.java index 40e25d09cc2..375e0478d41 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowStarredCoverage.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowStarredCoverage.java @@ -581,11 +581,14 @@ private void getLanguageTags() { } public String getName(final String written) { - String result = CldrConfig.getEnglish().getName(written); + String result = CldrConfig.getEnglish().nameGetter().getNameFromBCP47(written); if (result.equals(written)) { R2<List<String>, String> alias = languageFix.get(written); if (alias != null) { - result = CldrConfig.getEnglish().getName(alias.get0().get(0)); + result = + CldrConfig.getEnglish() + .nameGetter() + .getNameFromBCP47(alias.get0().get(0)); } } return result; diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/VettingAdder.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/VettingAdder.java index e3070fabcc9..13cb5943cc3 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/VettingAdder.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/VettingAdder.java @@ -289,7 +289,12 @@ public void showFiles(Factory cldrFactory, String targetDir) throws IOException String path = it2.next(); String fullPath = cldr.getFullXPath(path); if (fullPath.indexOf("[@draft=") >= 0) { - Log.logln(locale + " \t" + english.getName(locale) + "\texample: " + fullPath); + Log.logln( + locale + + " \t" + + english.nameGetter().getNameFromBCP47(locale) + + "\texample: " + + fullPath); break; } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/WritePluralRulesSpreadsheets.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/WritePluralRulesSpreadsheets.java index c1a88fbfd34..e3b3523fe20 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/WritePluralRulesSpreadsheets.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/WritePluralRulesSpreadsheets.java @@ -251,7 +251,9 @@ private static void writeRanges( } private static String getName(String missing) { - return missing + "\t" + CLDRConfig.getInstance().getEnglish().getName(missing); + return missing + + "\t" + + CLDRConfig.getInstance().getEnglish().nameGetter().getNameFromBCP47(missing); } private static String getSamplePattern(PluralMinimalPairs samplePatterns, String start) { diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java index 800c02ac346..2739487e897 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java @@ -8,8 +8,6 @@ */ package org.unicode.cldr.util; -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableSet; @@ -102,13 +100,6 @@ public class CLDRFile implements Freezable<CLDRFile>, Iterable<String>, LocaleStringProvider { - private static final String GETNAME_LOCALE_SEPARATOR = - "//ldml/localeDisplayNames/localeDisplayPattern/localeSeparator"; - private static final String GETNAME_LOCALE_PATTERN = - "//ldml/localeDisplayNames/localeDisplayPattern/localePattern"; - private static final String GETNAME_LOCALE_KEY_TYPE_PATTERN = - "//ldml/localeDisplayNames/localeDisplayPattern/localeKeyTypePattern"; - private static final ImmutableSet<String> casesNominativeOnly = ImmutableSet.of(GrammaticalFeature.grammaticalCase.getDefault(null)); @@ -134,8 +125,7 @@ public class CLDRFile implements Freezable<CLDRFile>, Iterable<String>, LocaleSt private static boolean DEBUG_LOGGING = false; public static final String SUPPLEMENTAL_NAME = "supplementalData"; - public static final String SUPPLEMENTAL_METADATA = "supplementalMetadata"; - public static final String SUPPLEMENTAL_PREFIX = "supplemental"; + public static final String GEN_VERSION = "47"; public static final List<String> SUPPLEMENTAL_NAMES = Arrays.asList( @@ -302,6 +292,8 @@ public boolean isNonInheriting() { return dataSource.isNonInheriting(); } + private final NameGetter nameGetter; + private static final boolean DEBUG_CLDR_FILE = false; private String creationTime = null; // only used if DEBUG_CLDR_FILE @@ -312,6 +304,7 @@ public boolean isNonInheriting() { */ public CLDRFile(XMLSource dataSource) { this.dataSource = dataSource; + this.nameGetter = new NameGetter(this); if (DEBUG_CLDR_FILE) { creationTime = @@ -329,6 +322,7 @@ public CLDRFile(XMLSource dataSource) { * @param minimalDraftStatus */ public CLDRFile(String localeId, List<File> dirs, DraftStatus minimalDraftStatus) { + this.nameGetter = new NameGetter(this); // order matters this.dataSource = XMLSource.getFrozenInstance(localeId, dirs, minimalDraftStatus); this.dtdType = dataSource.getXMLNormalizingDtdType(); @@ -336,6 +330,7 @@ public CLDRFile(String localeId, List<File> dirs, DraftStatus minimalDraftStatus } public CLDRFile(XMLSource dataSource, XMLSource... resolvingParents) { + this.nameGetter = new NameGetter(this); List<XMLSource> sourceList = new ArrayList<>(); sourceList.add(dataSource); sourceList.addAll(Arrays.asList(resolvingParents)); @@ -351,6 +346,10 @@ public CLDRFile(XMLSource dataSource, XMLSource... resolvingParents) { } } + public NameGetter nameGetter() { + return nameGetter; + } + public static CLDRFile loadFromFile( File f, String localeName, DraftStatus minimalDraftStatus, XMLSource source) { String fullFileName = f.getAbsolutePath(); @@ -2382,6 +2381,7 @@ public static String getNameTypeName(int index) { } } + /** Why isn't this an enum? */ public static final int NO_NAME = -1, LANGUAGE_NAME = 0, SCRIPT_NAME = 1, @@ -2931,7 +2931,7 @@ public static class Status { * XPath where originally found. May be {@link GlossonymConstructor#PSEUDO_PATH} if the * value was constructed. * - * @see GlossonymnConstructor + * @see GlossonymConstructor */ public String pathWhereFound; @@ -3877,527 +3877,6 @@ public String getKeyValueName(String key, String value) { return result; } - /* - ******************************************************************************************* - * TODO: move the code below here -- that is, the many (currently ten as of 2022-06-01) - * versions of getName and their subroutines and data -- to a new class in a separate file, - * and enable tracking similar to existing "pathWhereFound/localeWhereFound" but more general. - * - * Reference: https://unicode-org.atlassian.net/browse/CLDR-15830 - ******************************************************************************************* - */ - - static final Joiner JOIN_HYPHEN = Joiner.on('-'); - static final Joiner JOIN_UNDERBAR = Joiner.on('_'); - - /** Utility for getting a name, given a type and code. */ - public String getName(String type, String code) { - return getName(typeNameToCode(type), code); - } - - public String getName(int type, String code) { - return getName(type, code, null, null); - } - - public String getName(int type, String code, Set<String> paths) { - return getName(type, code, null, paths); - } - - public String getName(int type, String code, Transform<String, String> altPicker) { - return getName(type, code, altPicker, null); - } - - /** - * Returns the name of the given bcp47 identifier. Note that extensions must be specified using - * the old "\@key=type" syntax. - * - * @param localeOrTZID - * @return - */ - public synchronized String getName(String localeOrTZID) { - return getName(localeOrTZID, false); - } - - public String getName( - LanguageTagParser lparser, - boolean onlyConstructCompound, - Transform<String, String> altPicker) { - return getName(lparser, onlyConstructCompound, altPicker, null); - } - - /** - * @param paths if non-null, will contain contributory paths on return - */ - public String getName( - LanguageTagParser lparser, - boolean onlyConstructCompound, - Transform<String, String> altPicker, - Set<String> paths) { - return getName( - lparser, - onlyConstructCompound, - altPicker, - getWinningValueWithBailey(GETNAME_LOCALE_KEY_TYPE_PATTERN), - getWinningValueWithBailey(GETNAME_LOCALE_PATTERN), - getWinningValueWithBailey(GETNAME_LOCALE_SEPARATOR), - paths); - } - - public synchronized String getName( - String localeOrTZID, - boolean onlyConstructCompound, - String localeKeyTypePattern, - String localePattern, - String localeSeparator) { - return getName( - localeOrTZID, - onlyConstructCompound, - localeKeyTypePattern, - localePattern, - localeSeparator, - null, - null); - } - - /** - * Returns the name of the given bcp47 identifier. Note that extensions must be specified using - * the old "\@key=type" syntax. - * - * @param localeOrTZID the locale or timezone ID - * @param onlyConstructCompound - * @return - */ - public synchronized String getName(String localeOrTZID, boolean onlyConstructCompound) { - return getName(localeOrTZID, onlyConstructCompound, null); - } - - /** - * Returns the name of the given bcp47 identifier. Note that extensions must be specified using - * the old "\@key=type" syntax. - * - * @param localeOrTZID the locale or timezone ID - * @param onlyConstructCompound if true, returns "English (United Kingdom)" instead of "British - * English" - * @param altPicker Used to select particular alts. For example, SHORT_ALTS can be used to get - * "English (U.K.)" instead of "English (United Kingdom)" - * @return - */ - public synchronized String getName( - String localeOrTZID, - boolean onlyConstructCompound, - Transform<String, String> altPicker) { - return getName(localeOrTZID, onlyConstructCompound, altPicker, null); - } - - /** - * Returns the name of the given bcp47 identifier. Note that extensions must be specified using - * the old "\@key=type" syntax. - * - * @param localeOrTZID the locale or timezone ID - * @param onlyConstructCompound if true, returns "English (United Kingdom)" instead of "British - * English" - * @param altPicker Used to select particular alts. For example, SHORT_ALTS can be used to get - * "English (U.K.)" instead of "English (United Kingdom)" - * @return - */ - public synchronized String getName( - String localeOrTZID, - boolean onlyConstructCompound, - Transform<String, String> altPicker, - Set<String> paths) { - return getName( - localeOrTZID, - onlyConstructCompound, - getWinningValueWithBailey(GETNAME_LOCALE_KEY_TYPE_PATTERN), - getWinningValueWithBailey(GETNAME_LOCALE_PATTERN), - getWinningValueWithBailey(GETNAME_LOCALE_SEPARATOR), - altPicker, - paths); - } - - /** - * Returns the name of the given bcp47 identifier. Note that extensions must be specified using - * the old "\@key=type" syntax. Only used by ExampleGenerator. - * - * @param localeOrTZID the locale or timezone ID - * @param onlyConstructCompound - * @param localeKeyTypePattern the pattern used to format key-type pairs - * @param localePattern the pattern used to format primary/secondary subtags - * @param localeSeparator the list separator for secondary subtags - * @param paths if non-null, fillin with contributory paths - * @return - */ - public synchronized String getName( - String localeOrTZID, - boolean onlyConstructCompound, - String localeKeyTypePattern, - String localePattern, - String localeSeparator, - Transform<String, String> altPicker, - Set<String> paths) { - // Hack for seed - if (localePattern == null) { - localePattern = "{0} ({1})"; - } - boolean isCompound = localeOrTZID.contains("_"); - String name = - isCompound && onlyConstructCompound - ? null - : getName(LANGUAGE_NAME, localeOrTZID, altPicker, paths); - - // TODO - handle arbitrary combinations - if (name != null && !name.contains("_") && !name.contains("-")) { - name = replaceBracketsForName(name); - return name; - } - LanguageTagParser lparser = new LanguageTagParser().set(localeOrTZID); - return getName( - lparser, - onlyConstructCompound, - altPicker, - localeKeyTypePattern, - localePattern, - localeSeparator, - paths); - } - - public String getName( - LanguageTagParser lparser, - boolean onlyConstructCompound, - Transform<String, String> altPicker, - String localeKeyTypePattern, - String localePattern, - String localeSeparator, - Set<String> paths) { - String name; - String original = null; - - // we need to check for prefixes, for lang+script or lang+country - boolean haveScript = false; - boolean haveRegion = false; - // try lang+script - if (onlyConstructCompound) { - name = getName(LANGUAGE_NAME, original = lparser.getLanguage(), altPicker, paths); - if (name == null) name = original; - } else { - String x = lparser.toString(LanguageTagParser.LANGUAGE_SCRIPT_REGION); - name = getName(LANGUAGE_NAME, x, altPicker, paths); - if (name != null) { - haveScript = haveRegion = true; - } else { - name = - getName( - LANGUAGE_NAME, - lparser.toString(LanguageTagParser.LANGUAGE_SCRIPT), - altPicker, - paths); - if (name != null) { - haveScript = true; - } else { - name = - getName( - LANGUAGE_NAME, - lparser.toString(LanguageTagParser.LANGUAGE_REGION), - altPicker, - paths); - if (name != null) { - haveRegion = true; - } else { - name = - getName( - LANGUAGE_NAME, - original = lparser.getLanguage(), - altPicker, - paths); - if (name == null) { - name = original; - } - } - } - } - } - name = replaceBracketsForName(name); - String extras = ""; - if (!haveScript) { - extras = - addDisplayName( - lparser.getScript(), - SCRIPT_NAME, - localeSeparator, - extras, - altPicker, - paths); - } - if (!haveRegion) { - extras = - addDisplayName( - lparser.getRegion(), - TERRITORY_NAME, - localeSeparator, - extras, - altPicker, - paths); - } - List<String> variants = lparser.getVariants(); - for (String orig : variants) { - extras = addDisplayName(orig, VARIANT_NAME, localeSeparator, extras, altPicker, paths); - } - - // Look for key-type pairs. - main: - for (Map.Entry<String, List<String>> extension : - lparser.getLocaleExtensionsDetailed().entrySet()) { - String key = extension.getKey(); - if (key.equals("h0")) { - continue; - } - List<String> keyValue = extension.getValue(); - String oldFormatType = - (key.equals("ca") ? JOIN_HYPHEN : JOIN_UNDERBAR) - .join(keyValue); // default value - // Check if key/type pairs exist in the CLDRFile first. - String value = getKeyValueName(key, oldFormatType); - if (value != null) { - value = replaceBracketsForName(value); - } else { - // if we fail, then we construct from the key name and the value - String kname = getKeyName(key); - if (kname == null) { - kname = key; // should not happen, but just in case - } - switch (key) { - case "t": - List<String> hybrid = lparser.getLocaleExtensionsDetailed().get("h0"); - if (hybrid != null) { - kname = getKeyValueName("h0", JOIN_UNDERBAR.join(hybrid)); - } - oldFormatType = getName(oldFormatType); - break; - case "h0": - continue main; - case "cu": - oldFormatType = - getName( - CURRENCY_SYMBOL, - oldFormatType.toUpperCase(Locale.ROOT), - paths); - break; - case "tz": - if (paths != null) { - throw new IllegalArgumentException( - "Error: getName(…) with paths doesn't handle timezones."); - } - oldFormatType = - getTZName( - oldFormatType, "VVVV"); // TODO: paths not handled here, yet - break; - case "kr": - oldFormatType = getReorderName(localeSeparator, keyValue, paths); - break; - case "rg": - case "sd": - oldFormatType = getName(SUBDIVISION_NAME, oldFormatType, paths); - break; - default: - oldFormatType = JOIN_HYPHEN.join(keyValue); - } - value = - MessageFormat.format( - localeKeyTypePattern, new Object[] {kname, oldFormatType}); - if (paths != null) { - paths.add(GETNAME_LOCALE_KEY_TYPE_PATTERN); - } - value = replaceBracketsForName(value); - } - if (paths != null && !extras.isEmpty()) { - paths.add(GETNAME_LOCALE_SEPARATOR); - } - extras = - extras.isEmpty() - ? value - : MessageFormat.format(localeSeparator, new Object[] {extras, value}); - } - // now handle stray extensions - for (Map.Entry<String, List<String>> extension : - lparser.getExtensionsDetailed().entrySet()) { - String value = - MessageFormat.format( - localeKeyTypePattern, - new Object[] { - extension.getKey(), JOIN_HYPHEN.join(extension.getValue()) - }); - if (paths != null) { - paths.add(GETNAME_LOCALE_KEY_TYPE_PATTERN); - } - extras = - extras.isEmpty() - ? value - : MessageFormat.format(localeSeparator, new Object[] {extras, value}); - } - // fix this -- shouldn't be hardcoded! - if (extras.length() == 0) { - return name; - } - if (paths != null) { - paths.add(GETNAME_LOCALE_PATTERN); - } - return MessageFormat.format(localePattern, new Object[] {name, extras}); - } - - private static final String replaceBracketsForName(String value) { - value = value.replace('(', '[').replace(')', ']').replace('(', '[').replace(')', ']'); - return value; - } - - /** - * Utility for getting the name, given a code. - * - * @param type - * @param code - * @param codeToAlt - if not null, is called on the code. If the result is not null, then that - * is used for an alt value. If the alt path has a value it is used, otherwise the normal - * one is used. For example, the transform could return "short" for PS or HK or MO, but not - * US or GB. - * @param paths if non-null, will have contributory paths on return - * @return - */ - public String getName( - int type, String code, Transform<String, String> codeToAlt, Set<String> paths) { - String path = getKey(type, code); - String result = null; - if (codeToAlt != null) { - String alt = codeToAlt.transform(code); - if (alt != null) { - String altPath = path + "[@alt=\"" + alt + "\"]"; - result = getStringValueWithBaileyNotConstructed(altPath); - if (paths != null && result != null) { - paths.add(altPath); - } - } - } - if (result == null) { - result = getStringValueWithBaileyNotConstructed(path); - if (paths != null && result != null) { - paths.add(path); - } - } - if (getLocaleID().equals("en")) { - CLDRFile.Status status = new CLDRFile.Status(); - String sourceLocale = getSourceLocaleID(path, status); - if (result == null || !sourceLocale.equals("en")) { - if (type == LANGUAGE_NAME) { - Set<String> set = Iso639Data.getNames(code); - if (set != null) { - return set.iterator().next(); - } - Map<String, Map<String, String>> map = - StandardCodes.getLStreg().get("language"); - Map<String, String> info = map.get(code); - if (info != null) { - result = info.get("Description"); - } - } else if (type == TERRITORY_NAME) { - result = getLstrFallback("region", code, paths); - } else if (type == SCRIPT_NAME) { - result = getLstrFallback("script", code, paths); - } - } - } - return result; - } - - static final Pattern CLEAN_DESCRIPTION = Pattern.compile("([^\\(\\[]*)[\\(\\[].*"); - static final Splitter DESCRIPTION_SEP = Splitter.on('▪'); - - private String getLstrFallback(String codeType, String code, Set<String> paths) { - Map<String, String> info = StandardCodes.getLStreg().get(codeType).get(code); - if (info != null) { - String temp = info.get("Description"); - if (!temp.equalsIgnoreCase("Private use")) { - List<String> temp2 = DESCRIPTION_SEP.splitToList(temp); - temp = temp2.get(0); - final Matcher matcher = CLEAN_DESCRIPTION.matcher(temp); - if (matcher.lookingAt()) { - temp = matcher.group(1).trim(); - } - return temp; - } - } - return null; - } - - /** - * Gets timezone name. Not optimized. - * - * @param tzcode - * @return - */ - private String getTZName(String tzcode, String format) { - String longid = getLongTzid(tzcode); - if (tzcode.length() == 4 && !tzcode.equals("gaza")) { - return longid; - } - TimezoneFormatter tzf = new TimezoneFormatter(this); - return tzf.getFormattedZone(longid, format, 0); - } - - private String getReorderName( - String localeSeparator, List<String> keyValues, Set<String> paths) { - String result = null; - for (String value : keyValues) { - String name = - getName( - SCRIPT_NAME, - Character.toUpperCase(value.charAt(0)) + value.substring(1), - paths); - if (name == null) { - name = getKeyValueName("kr", value); - if (name == null) { - name = value; - } - } - result = - result == null - ? name - : MessageFormat.format(localeSeparator, new Object[] {result, name}); - } - return result; - } - - /** - * Adds the display name for a subtag to a string. - * - * @param subtag the subtag - * @param type the type of the subtag - * @param separatorPattern the pattern to be used for separating display names in the resultant - * string - * @param extras the string to be added to - * @return the modified display name string - */ - private String addDisplayName( - String subtag, - int type, - String separatorPattern, - String extras, - Transform<String, String> altPicker, - Set<String> paths) { - if (subtag.length() == 0) { - return extras; - } - String sname = getName(type, subtag, altPicker, paths); - if (sname == null) { - sname = subtag; - } - sname = replaceBracketsForName(sname); - - if (extras.length() == 0) { - extras += sname; - } else { - extras = MessageFormat.format(separatorPattern, new Object[] {extras, sname}); - } - return extras; - } - /** * Like getStringValueWithBailey, but reject constructed values, to prevent circularity problems * with getName @@ -4411,7 +3890,7 @@ private String addDisplayName( * @param path the given xpath * @return the string value, or null */ - private String getStringValueWithBaileyNotConstructed(String path) { + String getStringValueWithBaileyNotConstructed(String path) { Output<String> pathWhereFound = new Output<>(); final String value = getStringValueWithBailey(path, pathWhereFound, null); if (value == null || GlossonymConstructor.PSEUDO_PATH.equals(pathWhereFound.toString())) { diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRLocale.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRLocale.java index 163f30b370e..252071c0eb7 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRLocale.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRLocale.java @@ -151,13 +151,16 @@ public CLDRFormatter(FormatBehavior behavior) { @Override public String getDisplayVariant(CLDRLocale cldrLocale) { - if (file != null) return file.getName("variant", cldrLocale.getVariant()); + if (file != null) + return file.nameGetter().getNameFromTypestrCode("variant", cldrLocale.getVariant()); return tryForBetter(super.getDisplayVariant(cldrLocale), cldrLocale.getVariant()); } @Override public String getDisplayName(CLDRLocale cldrLocale) { - if (file != null) return file.getName(cldrLocale.toDisplayLanguageTag(), true, null); + if (file != null) + return file.nameGetter() + .getNameFromBCP47BoolAlt(cldrLocale.toDisplayLanguageTag(), true, null); return super.getDisplayName(cldrLocale); } @@ -167,26 +170,34 @@ public String getDisplayName( boolean onlyConstructCompound, Transform<String, String> altPicker) { if (file != null) - return file.getName( - cldrLocale.toDisplayLanguageTag(), onlyConstructCompound, altPicker); + return file.nameGetter() + .getNameFromBCP47BoolAlt( + cldrLocale.toDisplayLanguageTag(), + onlyConstructCompound, + altPicker); return super.getDisplayName(cldrLocale); } @Override public String getDisplayScript(CLDRLocale cldrLocale) { - if (file != null) return file.getName("script", cldrLocale.getScript()); + if (file != null) + return file.nameGetter().getNameFromTypestrCode("script", cldrLocale.getScript()); return tryForBetter(super.getDisplayScript(cldrLocale), cldrLocale.getScript()); } @Override public String getDisplayLanguage(CLDRLocale cldrLocale) { - if (file != null) return file.getName("language", cldrLocale.getLanguage()); + if (file != null) + return file.nameGetter() + .getNameFromTypestrCode("language", cldrLocale.getLanguage()); return tryForBetter(super.getDisplayLanguage(cldrLocale), cldrLocale.getLanguage()); } @Override public String getDisplayCountry(CLDRLocale cldrLocale) { - if (file != null) return file.getName("territory", cldrLocale.getCountry()); + if (file != null) + return file.nameGetter() + .getNameFromTypestrCode("territory", cldrLocale.getCountry()); return tryForBetter(super.getDisplayLanguage(cldrLocale), cldrLocale.getLanguage()); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRTransforms.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRTransforms.java index eaed4e88ce2..2e560d82545 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRTransforms.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRTransforms.java @@ -600,7 +600,11 @@ private String getDisplaySourceOrTarget(String sourceOrTarget) { return "Indic"; } try { - String name = CLDRConfig.getInstance().getEnglish().getName(sourceOrTarget); + String name = + CLDRConfig.getInstance() + .getEnglish() + .nameGetter() + .getNameFromBCP47(sourceOrTarget); return name; } catch (Exception e) { return sourceOrTarget; diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/DateTimeFormats.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/DateTimeFormats.java index 87b368f9bfd..24faaa268e2 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/DateTimeFormats.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/DateTimeFormats.java @@ -1100,7 +1100,7 @@ public static void main(String[] args) throws IOException { System.out.println("Skipping default content: " + localeID); continue; } - sorted.put(englishFile.getName(localeID, true), localeID); + sorted.put(englishFile.nameGetter().getNameFromBCP47Bool(localeID, true), localeID); } writeCss(DIR); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/DayPeriodsCheck.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/DayPeriodsCheck.java index 5148898520c..8dde478596a 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/DayPeriodsCheck.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/DayPeriodsCheck.java @@ -33,11 +33,15 @@ public static void main(String[] args) { case "groups": StandardCodes sc = StandardCodes.make(); CLDRFile english = CLDRConfig.getInstance().getEnglish(); - english.getName(LanguageGroup.uralic.iso); + english.nameGetter().getNameFromBCP47(LanguageGroup.uralic.iso); for (LanguageGroup group : LanguageGroup.values()) { System.out.println( - group + "\t" + group.iso + "\t" + english.getName(group.iso)); + group + + "\t" + + group.iso + + "\t" + + english.nameGetter().getNameFromBCP47(group.iso)); } for (LanguageGroup group : LanguageGroup.values()) { diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/DiffLanguageGroups.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/DiffLanguageGroups.java index b401ccbdf76..88e1be187c1 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/DiffLanguageGroups.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/DiffLanguageGroups.java @@ -284,7 +284,8 @@ public static String show(String languageCode) { } public static String getName(String languageCode) { - String result = ENGLISH.getName(CLDRFile.LANGUAGE_NAME, languageCode); + String result = + ENGLISH.nameGetter().getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, languageCode); return result == null ? "(no name)" : result.replace(" (Other)", ""); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/GlossonymConstructor.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/GlossonymConstructor.java index e078934c732..bd1fa07dfb6 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/GlossonymConstructor.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/GlossonymConstructor.java @@ -115,7 +115,8 @@ private synchronized String reallyGetValue(String xpath) { final String alt = parts.getAttributeValue(-1, "alt"); final CLDRFile.SimpleAltPicker altPicker = (alt == null) ? null : new CLDRFile.SimpleAltPicker(alt); - final String value = cldrFile.getName(type, true, altPicker); + final String value = + cldrFile.nameGetter().getNameFromBCP47BoolAlt(type, true, altPicker); if (!valueIsBogus(value)) { return value; } @@ -130,7 +131,9 @@ public Set<String> getPathsWhereFound(String xpath, Set<String> paths) { final String alt = parts.getAttributeValue(-1, "alt"); final CLDRFile.SimpleAltPicker altPicker = (alt == null) ? null : new CLDRFile.SimpleAltPicker(alt); - final String value = cldrFile.getName(type, true, altPicker, paths); + final String value = + cldrFile.nameGetter() + .getNameFromBCP47BoolAltPaths(type, true, altPicker, paths); if (!valueIsBogus(value)) { return paths; } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/LanguageGroup.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/LanguageGroup.java index e91f0789063..39147aff508 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/LanguageGroup.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/LanguageGroup.java @@ -291,7 +291,8 @@ public String getName(CLDRFile cldrFile) { case "": break; default: - return cldrFile.getName(CLDRFile.TERRITORY_NAME, ltp.getRegion()); + return cldrFile.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, ltp.getRegion()); } switch (ltp.getScript()) { case "Hani": @@ -302,7 +303,8 @@ public String getName(CLDRFile cldrFile) { throw new IllegalArgumentException("Need to fix code: " + ltp.getScript()); } return prefix - + cldrFile.getName(ltp.getLanguage()) + + cldrFile.nameGetter() + .getNameFromBCP47(ltp.getLanguage()) .replace(" [Other]", "") .replace(" languages", ""); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/NameGetter.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/NameGetter.java new file mode 100644 index 00000000000..a44f26d1cb0 --- /dev/null +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/NameGetter.java @@ -0,0 +1,547 @@ +package org.unicode.cldr.util; + +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import com.ibm.icu.text.MessageFormat; +import com.ibm.icu.text.Transform; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class NameGetter { + + private final CLDRFile cldrFile; + + /** + * Construct a new NameGetter. + * + * @param cldrFile must not be null + */ + public NameGetter(CLDRFile cldrFile) { + if (cldrFile == null) { + throw new IllegalArgumentException("NameGetter must have non-null CLDRFile"); + } + this.cldrFile = cldrFile; + } + + private static final String GETNAME_LOCALE_SEPARATOR_PATH = + "//ldml/localeDisplayNames/localeDisplayPattern/localeSeparator"; + private static final String GETNAME_LOCALE_PATTERN_PATH = + "//ldml/localeDisplayNames/localeDisplayPattern/localePattern"; + private static final String GETNAME_LOCALE_KEY_TYPE_PATTERN_PATH = + "//ldml/localeDisplayNames/localeDisplayPattern/localeKeyTypePattern"; + + private static final Joiner JOIN_HYPHEN = Joiner.on('-'); + private static final Joiner JOIN_UNDERBAR = Joiner.on('_'); + + /** + * Get a name, given a type (as a String) and a code. + * + * <p>Ideally getNameFromTypestrCode and getNameFromTypenumCode should be replaced by a method + * that takes an enum rather than String or int. Compare StandardCodes.CodeType, and the + * integers defined in the vicinity of CLDRFile.TERRITORY_NAME + * + * @param type a string such as "currency", "language", "region", "script", "territory", ... + * @param code a code such as "JP" + * @return the name + */ + public String getNameFromTypestrCode(String type, String code) { + return getNameFromTypenumCode(CLDRFile.typeNameToCode(type), code); + } + + /** + * Get a name, given a type (as a int) and a code. + * + * @param type the type such as CLDRFile.TERRITORY_NAME + * @param code a code such as "JP" + * @return the name + */ + public String getNameFromTypenumCode(int type, String code) { + return getNameFromTypeCodeTransformPaths(type, code, null, null); + } + + public String getNameFromTypeCodePaths(int type, String code, Set<String> paths) { + return getNameFromTypeCodeTransformPaths(type, code, null, paths); + } + + public String getNameFromTypeCodeAltpicker( + int type, String code, Transform<String, String> altPicker) { + return getNameFromTypeCodeTransformPaths(type, code, altPicker, null); + } + + /** + * Returns the name of the given bcp47 identifier. Note that extensions must be specified using + * the old "\@key=type" syntax. + * + * @param localeOrTZID the bcp47 identifier (locale or timezone ID) + * @return the name of the given bcp47 identifier + */ + public synchronized String getNameFromBCP47(String localeOrTZID) { + return getNameFromBCP47Bool(localeOrTZID, false); + } + + /** + * Returns the name of the given bcp47 identifier. Note that extensions must be specified using + * the old "\@key=type" syntax. + * + * @param localeOrTZID the bcp47 identifier (locale or timezone ID) + * @param onlyConstructCompound if true, returns "English (United Kingdom)" instead of "British + * English" + * @return the name of the given bcp47 identifier + */ + public synchronized String getNameFromBCP47Bool( + String localeOrTZID, boolean onlyConstructCompound) { + return getNameFromBCP47BoolAlt(localeOrTZID, onlyConstructCompound, null); + } + + public String getNameFromParserBool(LanguageTagParser lparser, boolean onlyConstructCompound) { + return getNameFromOtherThings( + lparser, + onlyConstructCompound, + null, + cldrFile.getWinningValueWithBailey(GETNAME_LOCALE_KEY_TYPE_PATTERN_PATH), + cldrFile.getWinningValueWithBailey(GETNAME_LOCALE_PATTERN_PATH), + cldrFile.getWinningValueWithBailey(GETNAME_LOCALE_SEPARATOR_PATH), + null); + } + + public synchronized String getNameFromBCP47Etc( + String localeOrTZID, + boolean onlyConstructCompound, + String localeKeyTypePattern, + String localePattern, + String localeSeparator) { + return getNameFromManyThings( + localeOrTZID, + onlyConstructCompound, + localeKeyTypePattern, + localePattern, + localeSeparator, + null, + null); + } + + /** + * Returns the name of the given bcp47 identifier. Note that extensions must be specified using + * the old "\@key=type" syntax. + * + * @param localeOrTZID the bcp47 identifier (locale or timezone ID) + * @param onlyConstructCompound if true, returns "English (United Kingdom)" instead of "British + * English" + * @param altPicker Used to select particular alts. For example, SHORT_ALTS can be used to get + * "English (U.K.)" instead of "English (United Kingdom)" + * @return the name of the given bcp47 identifier + */ + public synchronized String getNameFromBCP47BoolAlt( + String localeOrTZID, + boolean onlyConstructCompound, + Transform<String, String> altPicker) { + return getNameFromBCP47BoolAltPaths(localeOrTZID, onlyConstructCompound, altPicker, null); + } + + /** + * Returns the name of the given bcp47 identifier. Note that extensions must be specified using + * the old "\@key=type" syntax. + * + * @param localeOrTZID the bcp47 identifier (locale or timezone ID) + * @param onlyConstructCompound if true, returns "English (United Kingdom)" instead of "British + * English" + * @param altPicker Used to select particular alts. For example, SHORT_ALTS can be used to get + * "English (U.K.)" instead of "English (United Kingdom)" + * @return the name of the given bcp47 identifier + */ + public synchronized String getNameFromBCP47BoolAltPaths( + String localeOrTZID, + boolean onlyConstructCompound, + Transform<String, String> altPicker, + Set<String> paths) { + return getNameFromManyThings( + localeOrTZID, + onlyConstructCompound, + cldrFile.getWinningValueWithBailey(GETNAME_LOCALE_KEY_TYPE_PATTERN_PATH), + cldrFile.getWinningValueWithBailey(GETNAME_LOCALE_PATTERN_PATH), + cldrFile.getWinningValueWithBailey(GETNAME_LOCALE_SEPARATOR_PATH), + altPicker, + paths); + } + + /** + * Returns the name of the given bcp47 identifier. Note that extensions must be specified using + * the old "\@key=type" syntax. Only used by ExampleGenerator. + * + * @param localeOrTZID the bcp47 identifier (locale or timezone ID) + * @param onlyConstructCompound if true, returns "English (United Kingdom)" instead of "British + * English" + * @param localeKeyTypePattern the pattern used to format key-type pairs + * @param localePattern the pattern used to format primary/secondary subtags + * @param localeSeparator the list separator for secondary subtags + * @param paths if non-null, fillin with contributory paths + * @return the name of the given bcp47 identifier + */ + private synchronized String getNameFromManyThings( + String localeOrTZID, + boolean onlyConstructCompound, + String localeKeyTypePattern, + String localePattern, + String localeSeparator, + Transform<String, String> altPicker, + Set<String> paths) { + // Hack for seed + if (localePattern == null) { + localePattern = "{0} ({1})"; + } + boolean isCompound = localeOrTZID.contains("_"); + String name = + isCompound && onlyConstructCompound + ? null + : getNameFromTypeCodeTransformPaths( + CLDRFile.LANGUAGE_NAME, localeOrTZID, altPicker, paths); + + // TODO - handle arbitrary combinations + if (name != null && !name.contains("_") && !name.contains("-")) { + name = replaceBracketsForName(name); + return name; + } + LanguageTagParser lparser = new LanguageTagParser().set(localeOrTZID); + return getNameFromOtherThings( + lparser, + onlyConstructCompound, + altPicker, + localeKeyTypePattern, + localePattern, + localeSeparator, + paths); + } + + private String getNameFromOtherThings( + LanguageTagParser lparser, + boolean onlyConstructCompound, + Transform<String, String> altPicker, + String localeKeyTypePattern, + String localePattern, + String localeSeparator, + Set<String> paths) { + String name; + String original; + + // we need to check for prefixes, for lang+script or lang+country + boolean haveScript = false; + boolean haveRegion = false; + // try lang+script + if (onlyConstructCompound) { + name = + getNameFromTypeCodeTransformPaths( + CLDRFile.LANGUAGE_NAME, + original = lparser.getLanguage(), + altPicker, + paths); + if (name == null) name = original; + } else { + String x = lparser.toString(LanguageTagParser.LANGUAGE_SCRIPT_REGION); + name = getNameFromTypeCodeTransformPaths(CLDRFile.LANGUAGE_NAME, x, altPicker, paths); + if (name != null) { + haveScript = haveRegion = true; + } else { + name = + getNameFromTypeCodeTransformPaths( + CLDRFile.LANGUAGE_NAME, + lparser.toString(LanguageTagParser.LANGUAGE_SCRIPT), + altPicker, + paths); + if (name != null) { + haveScript = true; + } else { + name = + getNameFromTypeCodeTransformPaths( + CLDRFile.LANGUAGE_NAME, + lparser.toString(LanguageTagParser.LANGUAGE_REGION), + altPicker, + paths); + if (name != null) { + haveRegion = true; + } else { + name = + getNameFromTypeCodeTransformPaths( + CLDRFile.LANGUAGE_NAME, + original = lparser.getLanguage(), + altPicker, + paths); + if (name == null) { + name = original; + } + } + } + } + } + name = replaceBracketsForName(name); + String extras = ""; + if (!haveScript) { + extras = + addDisplayName( + lparser.getScript(), + CLDRFile.SCRIPT_NAME, + localeSeparator, + extras, + altPicker, + paths); + } + if (!haveRegion) { + extras = + addDisplayName( + lparser.getRegion(), + CLDRFile.TERRITORY_NAME, + localeSeparator, + extras, + altPicker, + paths); + } + List<String> variants = lparser.getVariants(); + for (String orig : variants) { + extras = + addDisplayName( + orig, CLDRFile.VARIANT_NAME, localeSeparator, extras, altPicker, paths); + } + + // Look for key-type pairs. + for (Map.Entry<String, List<String>> extension : + lparser.getLocaleExtensionsDetailed().entrySet()) { + String key = extension.getKey(); + if (key.equals("h0")) { + continue; + } + List<String> keyValue = extension.getValue(); + String oldFormatType = + (key.equals("ca") ? JOIN_HYPHEN : JOIN_UNDERBAR) + .join(keyValue); // default value + // Check if key/type pairs exist in the CLDRFile first. + String value = cldrFile.getKeyValueName(key, oldFormatType); + if (value == null) { + // if we fail, then we construct from the key name and the value + String kname = cldrFile.getKeyName(key); + if (kname == null) { + kname = key; // should not happen, but just in case + } + switch (key) { + case "t": + List<String> hybrid = lparser.getLocaleExtensionsDetailed().get("h0"); + if (hybrid != null) { + kname = cldrFile.getKeyValueName("h0", JOIN_UNDERBAR.join(hybrid)); + } + oldFormatType = getNameFromBCP47(oldFormatType); + break; + case "cu": + oldFormatType = + getNameFromTypeCodePaths( + CLDRFile.CURRENCY_SYMBOL, + oldFormatType.toUpperCase(Locale.ROOT), + paths); + break; + case "tz": + if (paths != null) { + throw new IllegalArgumentException( + "Error: getName(…) with paths doesn't handle timezones."); + } + oldFormatType = + getTZName(oldFormatType); // TODO: paths not handled here, yet + break; + case "kr": + oldFormatType = getReorderName(localeSeparator, keyValue, paths); + break; + case "rg": + case "sd": + oldFormatType = + getNameFromTypeCodePaths( + CLDRFile.SUBDIVISION_NAME, oldFormatType, paths); + break; + default: + oldFormatType = JOIN_HYPHEN.join(keyValue); + } + value = MessageFormat.format(localeKeyTypePattern, kname, oldFormatType); + if (paths != null) { + paths.add(GETNAME_LOCALE_KEY_TYPE_PATTERN_PATH); + } + } + value = replaceBracketsForName(value); + if (paths != null && !extras.isEmpty()) { + paths.add(GETNAME_LOCALE_SEPARATOR_PATH); + } + extras = + extras.isEmpty() ? value : MessageFormat.format(localeSeparator, extras, value); + } + // now handle stray extensions + for (Map.Entry<String, List<String>> extension : + lparser.getExtensionsDetailed().entrySet()) { + String value = + MessageFormat.format( + localeKeyTypePattern, + extension.getKey(), + JOIN_HYPHEN.join(extension.getValue())); + if (paths != null) { + paths.add(GETNAME_LOCALE_KEY_TYPE_PATTERN_PATH); + } + extras = + extras.isEmpty() ? value : MessageFormat.format(localeSeparator, extras, value); + } + // fix this -- shouldn't be hardcoded! + if (extras.isEmpty()) { + return name; + } + if (paths != null) { + paths.add(GETNAME_LOCALE_PATTERN_PATH); + } + return MessageFormat.format(localePattern, name, extras); + } + + private static String replaceBracketsForName(String value) { + return value.replace('(', '[').replace(')', ']').replace('(', '[').replace(')', ']'); + } + + /** + * Utility for getting the name, given a code. + * + * @param type the type such as CLDRFile.TERRITORY_NAME + * @param code the code such as "JP" + * @param codeToAlt - if not null, is called on the code. If the result is not null, then that + * is used for an alt value. If the alt path has a value it is used, otherwise the normal + * one is used. For example, the transform could return "short" for PS or HK or MO, but not + * US or GB. + * @param paths if non-null, will have contributory paths on return + * @return the name + */ + private String getNameFromTypeCodeTransformPaths( + int type, String code, Transform<String, String> codeToAlt, Set<String> paths) { + String path = CLDRFile.getKey(type, code); + String result = null; + if (codeToAlt != null) { + String alt = codeToAlt.transform(code); + if (alt != null) { + String altPath = path + "[@alt=\"" + alt + "\"]"; + result = cldrFile.getStringValueWithBaileyNotConstructed(altPath); + if (paths != null && result != null) { + paths.add(altPath); + } + } + } + if (result == null) { + result = cldrFile.getStringValueWithBaileyNotConstructed(path); + if (paths != null && result != null) { + paths.add(path); + } + } + if (cldrFile.getLocaleID().equals("en")) { + CLDRFile.Status status = new CLDRFile.Status(); + String sourceLocale = cldrFile.getSourceLocaleID(path, status); + if (result == null || !sourceLocale.equals("en")) { + if (type == CLDRFile.LANGUAGE_NAME) { + Set<String> set = Iso639Data.getNames(code); + if (set != null) { + return set.iterator().next(); + } + Map<String, Map<String, String>> map = + StandardCodes.getLStreg().get("language"); + Map<String, String> info = map.get(code); + if (info != null) { + result = info.get("Description"); + } + } else if (type == CLDRFile.TERRITORY_NAME) { + result = getLstrFallback("region", code); + } else if (type == CLDRFile.SCRIPT_NAME) { + result = getLstrFallback("script", code); + } + } + } + return result; + } + + static final Pattern CLEAN_DESCRIPTION = Pattern.compile("([^(\\[]*)[(\\[].*"); + static final Splitter DESCRIPTION_SEP = Splitter.on('▪'); + + private String getLstrFallback(String codeType, String code) { + Map<String, String> info = StandardCodes.getLStreg().get(codeType).get(code); + if (info != null) { + String temp = info.get("Description"); + if (!temp.equalsIgnoreCase("Private use")) { + List<String> temp2 = DESCRIPTION_SEP.splitToList(temp); + temp = temp2.get(0); + final Matcher matcher = CLEAN_DESCRIPTION.matcher(temp); + if (matcher.lookingAt()) { + temp = matcher.group(1).trim(); + } + return temp; + } + } + return null; + } + + /** + * Gets timezone name. Not optimized. + * + * @param tzcode the code such as "gaza" + * @return timezone name + */ + private String getTZName(String tzcode) { + String longid = CLDRFile.getLongTzid(tzcode); + if (tzcode.length() == 4 && !tzcode.equals("gaza")) { + return longid; + } + TimezoneFormatter tzf = new TimezoneFormatter(cldrFile); + return tzf.getFormattedZone(longid, "VVVV", 0); + } + + private String getReorderName( + String localeSeparator, List<String> keyValues, Set<String> paths) { + String result = null; + for (String value : keyValues) { + String name = + getNameFromTypeCodePaths( + CLDRFile.SCRIPT_NAME, + Character.toUpperCase(value.charAt(0)) + value.substring(1), + paths); + if (name == null) { + name = cldrFile.getKeyValueName("kr", value); + if (name == null) { + name = value; + } + } + result = result == null ? name : MessageFormat.format(localeSeparator, result, name); + } + return result; + } + + /** + * Adds the display name for a subtag to a string. + * + * @param subtag the subtag + * @param type the type of the subtag + * @param separatorPattern the pattern to be used for separating display names in the resultant + * string + * @param extras the string to be added to + * @return the modified display name string + */ + private String addDisplayName( + String subtag, + int type, + String separatorPattern, + String extras, + Transform<String, String> altPicker, + Set<String> paths) { + if (subtag.isEmpty()) { + return extras; + } + String sname = getNameFromTypeCodeTransformPaths(type, subtag, altPicker, paths); + if (sname == null) { + sname = subtag; + } + sname = replaceBracketsForName(sname); + + if (extras.isEmpty()) { + extras += sname; + } else { + extras = MessageFormat.format(separatorPattern, extras, sname); + } + return extras; + } +} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathDescription.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathDescription.java index 6ebdcad0351..6f8f8e5817f 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathDescription.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathDescription.java @@ -994,7 +994,8 @@ public String getDescription(String path, String value, Object context) { code = "the timezone “" + codeName + "”"; found = true; } else if (country != null) { - String countryName = english.getName("territory", country); + String countryName = + english.nameGetter().getNameFromTypestrCode("territory", country); if (countryName != null) { if (!codeName.equals(countryName)) { code = "the city “" + codeName + "” (in " + countryName + ")"; @@ -1012,7 +1013,9 @@ public String getDescription(String path, String value, Object context) { MessageFormat.format(MessageFormat.autoQuoteApostrophe(description), code); } else if (path.contains("exemplarCity")) { String regionCode = ZONE2COUNTRY.get(attributes.get(0)); - String englishRegionName = english.getName(CLDRFile.TERRITORY_NAME, regionCode); + String englishRegionName = + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, regionCode); description = MessageFormat.format( MessageFormat.autoQuoteApostrophe(description), englishRegionName); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java index fef2148fcb6..24dc3b8ad69 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java @@ -636,6 +636,7 @@ public static class Factory implements Transform<String, PathHeader> { static final Relation<SectionPage, String> sectionPageToPaths = Relation.of(new TreeMap<>(), HashSet.class); private static CLDRFile englishFile; + private static NameGetter englishNameGetter; private final Set<String> matchersFound = new HashSet<>(); /** @@ -656,6 +657,7 @@ private static void setEnglishCLDRFileIfNotSet(CLDRFile englishFile2) { synchronized (Factory.class) { if (englishFile == null) { englishFile = englishFile2; + englishNameGetter = englishFile.nameGetter(); } } } @@ -1416,7 +1418,8 @@ public String transform(String source0) { languageOnlyPart = source0; } - return englishFile.getName(CLDRFile.LANGUAGE_NAME, languageOnlyPart) + return englishNameGetter.getNameFromTypenumCode( + CLDRFile.LANGUAGE_NAME, languageOnlyPart) + " \u25BA " + source0; } @@ -1431,7 +1434,9 @@ public String transform(String source0) { if (script == null) { script = likelySubtags.getLikelyScript(language); } - String scriptName = englishFile.getName(CLDRFile.SCRIPT_NAME, script); + String scriptName = + englishNameGetter.getNameFromTypenumCode( + CLDRFile.SCRIPT_NAME, script); return "Languages in " + (script.equals("Hans") || script.equals("Hant") ? "Han Script" @@ -1449,7 +1454,8 @@ public String transform(String source) { String territory = getSubdivisionsTerritory(source, null); String container = Containment.getContainer(territory); order = Containment.getOrder(territory); - return englishFile.getName(CLDRFile.TERRITORY_NAME, container); + return englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, container); } }); functionMap.put( @@ -1483,7 +1489,7 @@ public String transform(String source0) { : "003"; // was Integer.valueOf(subcontinent) == // 5 return "Territories (" - + englishFile.getName( + + englishNameGetter.getNameFromTypenumCode( CLDRFile.TERRITORY_NAME, theSubContinent) + ")"; case "001": @@ -1491,7 +1497,7 @@ public String transform(String source0) { return "Geographic Regions"; // not in containment default: return "Territories (" - + englishFile.getName( + + englishNameGetter.getNameFromTypenumCode( CLDRFile.TERRITORY_NAME, theContinent) + ")"; } @@ -1533,7 +1539,8 @@ public String transform(String source0) { } } if (singlePageTerritories.contains(theTerritory)) { - return englishFile.getName(CLDRFile.TERRITORY_NAME, theTerritory); + return englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, theTerritory); } String theContinent = Containment.getContinent(theTerritory); final String subcontinent = Containment.getSubcontinent(theTerritory); @@ -1549,19 +1556,19 @@ public String transform(String source0) { } catch (NumberFormatException ex) { theSubContinent = "009"; } - return englishFile.getName( + return englishNameGetter.getNameFromTypenumCode( CLDRFile.TERRITORY_NAME, theSubContinent); case 19: // Americas - For the timeZonePage, we just group North // America & South America theSubContinent = Integer.parseInt(subcontinent) == 5 ? "005" : "003"; - return englishFile.getName( + return englishNameGetter.getNameFromTypenumCode( CLDRFile.TERRITORY_NAME, theSubContinent); case 142: // Asia - return englishFile.getName( + return englishNameGetter.getNameFromTypenumCode( CLDRFile.TERRITORY_NAME, subcontinent); default: - return englishFile.getName( + return englishNameGetter.getNameFromTypenumCode( CLDRFile.TERRITORY_NAME, theContinent); } } @@ -1660,7 +1667,8 @@ public String transform(String source) { if (PathHeader.UNIFORM_CONTINENTS) { String container = getMetazonePageTerritory(source); order = Containment.getOrder(container); - return englishFile.getName(CLDRFile.TERRITORY_NAME, container); + return englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, container); } else { String continent = metazoneToContinent.get(source); if (continent == null) { @@ -1770,13 +1778,15 @@ public String transform(String source0) { if (territory.equals("ZZ")) { order = 999; - return englishFile.getName(CLDRFile.TERRITORY_NAME, territory) + return englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, territory) + ": " + source0; } else { return catFromTerritory.transform(territory) + ": " - + englishFile.getName(CLDRFile.TERRITORY_NAME, territory) + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, territory) + tenderOrNot; } } @@ -1798,7 +1808,8 @@ public String transform(String source0) { if (territory.equals("ZZ")) { order = 999; subContinent = - englishFile.getName(CLDRFile.TERRITORY_NAME, territory); + englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, territory); } else { subContinent = catFromTerritory.transform(territory); } @@ -2188,7 +2199,9 @@ private static String getEnglishFirstLetter(String s) { } else { languageOnlyPart = s; } - final String name = englishFile.getName(CLDRFile.LANGUAGE_NAME, languageOnlyPart); + final String name = + englishNameGetter.getNameFromTypenumCode( + CLDRFile.LANGUAGE_NAME, languageOnlyPart); return name == null ? "?" : name.substring(0, 1).toUpperCase(); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/PluralSnapshot.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/PluralSnapshot.java index ebda1c8bcb5..af4681d83ec 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/PluralSnapshot.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/PluralSnapshot.java @@ -334,7 +334,7 @@ public static void writeTables(CLDRFile english, PrintWriter out) { // } Map<String, String> fullLocales = new TreeMap<>(); for (String localeId : locales) { - String name = english.getName(localeId); + String name = english.nameGetter().getNameFromBCP47(localeId); fullLocales.put(name, localeId); } out.print( diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/TestUtilities.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/TestUtilities.java index 7ac9a99849d..31bfec4d3da 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/TestUtilities.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/TestUtilities.java @@ -128,7 +128,12 @@ private static void testNames() { "zh_Hans_US_SAAHO" }; for (String test : tests) { - System.out.println(test + "\t" + english.getName(test) + "\t" + french.getName(test)); + System.out.println( + test + + "\t" + + english.nameGetter().getNameFromBCP47(test) + + "\t" + + french.nameGetter().getNameFromBCP47(test)); } } @@ -1010,24 +1015,36 @@ private static void printCountries() throws IOException { Factory mainCldrFactory = Factory.make(CLDRPaths.COMMON_DIRECTORY + "main" + File.separator, ".*"); CLDRFile english = mainCldrFactory.make("en", true); + NameGetter englishNameGetter = english.nameGetter(); PrintWriter out = FileUtilities.openUTF8Writer(CLDRPaths.GEN_DIRECTORY, "country_language_names.txt"); StandardCodes sc = StandardCodes.make(); for (Iterator<String> it = sc.getGoodAvailableCodes("language").iterator(); it.hasNext(); ) { String code = it.next(); - out.println(code + "\t" + english.getName(CLDRFile.LANGUAGE_NAME, code)); + out.println( + code + + "\t" + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.LANGUAGE_NAME, code)); } out.println("****"); for (Iterator<String> it = sc.getGoodAvailableCodes("territory").iterator(); it.hasNext(); ) { String code = it.next(); - out.println(code + "\t" + english.getName(CLDRFile.TERRITORY_NAME, code)); + out.println( + code + + "\t" + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, code)); } out.println("****"); for (Iterator<String> it = sc.getGoodAvailableCodes("script").iterator(); it.hasNext(); ) { String code = it.next(); - out.println(code + "\t" + english.getName(CLDRFile.SCRIPT_NAME, code)); + out.println( + code + + "\t" + + englishNameGetter.getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, code)); } out.close(); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/TimezoneFormatter.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/TimezoneFormatter.java index c2e7404a47f..0f7b96b78a9 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/TimezoneFormatter.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/TimezoneFormatter.java @@ -214,7 +214,7 @@ private String getStringValue(String cleanPath) { private String getName(int territory_name, String country, boolean skipDraft2) { checkForDraft(CLDRFile.getKey(territory_name, country)); - return desiredLocaleFile.getName(territory_name, country); + return desiredLocaleFile.nameGetter().getNameFromTypenumCode(territory_name, country); } private void checkForDraft(String cleanPath) { @@ -613,7 +613,10 @@ public String getLocalizedMetazone( } private String getLocalizedCountryName(String zoneIdsCountry) { - String countryName = desiredLocaleFile.getName(CLDRFile.TERRITORY_NAME, zoneIdsCountry); + String countryName = + desiredLocaleFile + .nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, zoneIdsCountry); if (countryName == null) { countryName = zoneIdsCountry; } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/VerifyCompactNumbers.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/VerifyCompactNumbers.java index 70e76dd61aa..a152d1bd874 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/VerifyCompactNumbers.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/VerifyCompactNumbers.java @@ -116,7 +116,9 @@ public static void main(String[] args) throws IOException { } PrintWriter out = FileUtilities.openUTF8Writer(DIR, locale + ".html"); - String title = "Verify Number Formats: " + englishCldrFile.getName(locale); + String title = + "Verify Number Formats: " + + englishCldrFile.nameGetter().getNameFromBCP47(locale); out.println( "<!doctype HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'><html><head>\n" + "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>\n" @@ -135,7 +137,7 @@ public static void main(String[] args) throws IOException { out.println("</body></html>"); out.close(); - indexMap.put(english.getName(locale), locale + ".html"); + indexMap.put(english.nameGetter().getNameFromBCP47(locale), locale + ".html"); } try (PrintWriter index = DateTimeFormats.openIndex(DIR, "Numbers")) { DateTimeFormats.writeIndexMap(indexMap, index); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/VerifyZones.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/VerifyZones.java index 37985006984..8204808d053 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/VerifyZones.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/VerifyZones.java @@ -272,7 +272,8 @@ public static void main(String[] args) throws IOException { } CLDRFile cldrFile = factory2.make(localeID, true); PrintWriter out = FileUtilities.openUTF8Writer(DIR, localeID + ".html"); - String title = "Verify Time Zones: " + englishCldrFile.getName(localeID); + String title = + "Verify Time Zones: " + englishCldrFile.nameGetter().getNameFromBCP47(localeID); out.println( "<!doctype HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'><html><head>\n" + "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>\n" @@ -290,7 +291,7 @@ public static void main(String[] args) throws IOException { out.println("</body></html>"); out.close(); - indexMap.put(english.getName(localeID), localeID + ".html"); + indexMap.put(english.nameGetter().getNameFromBCP47(localeID), localeID + ".html"); } try (PrintWriter index = DateTimeFormats.openIndex(DIR, "Time Zones")) { DateTimeFormats.writeIndexMap(indexMap, index); @@ -452,7 +453,10 @@ private static void addZones( String grouping = row.getContainer(); TimeZone currentZone = TimeZone.getTimeZone(tzid); TimeZone tz = currentZone; - String englishGrouping = englishCldrFile.getName(CLDRFile.TERRITORY_NAME, grouping); + String englishGrouping = + englishCldrFile + .nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, grouping); String metazoneInfo = englishGrouping @@ -468,7 +472,9 @@ private static void addZones( continue; } String englishTerritory = - englishCldrFile.getName(CLDRFile.TERRITORY_NAME, countryCode2); + englishCldrFile + .nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, countryCode2); output.addRow() .addCell(metazoneInfo) .addCell(englishTerritory + ": " + tzid.replace("/", "/\u200B")); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/VettingViewer.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/VettingViewer.java index 7d3160a0d2b..7a3775ebd51 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/VettingViewer.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/VettingViewer.java @@ -1335,7 +1335,7 @@ private void appendNameAndCode(String name, String localeID, Appendable output) private String getName(String localeID) { Set<String> contents = supplementalDataInfo.getEquivalentsForLocale(localeID); // put in special character that can be split on later - return englishFile.getName(localeID, true, CLDRFile.SHORT_ALTS) + return englishFile.nameGetter().getNameFromBCP47BoolAlt(localeID, true, CLDRFile.SHORT_ALTS) + SPLIT_CHAR + gatherCodes(contents); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/WikipediaOfficialLanguages.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/WikipediaOfficialLanguages.java index 7da47c2ef51..f3a7414e395 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/WikipediaOfficialLanguages.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/WikipediaOfficialLanguages.java @@ -299,13 +299,17 @@ public static void main(String[] args) { sInfo == null ? OfficialStatus.unknown : sInfo.getOfficialStatus(); if (!areCompatible(info.status, cldrStatus)) { System.out.print( - region + "\t" + english.getName(CLDRFile.TERRITORY_NAME, region)); + region + + "\t" + + english.nameGetter() + .getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, region)); System.out.println( "\t" + info.language + "\t" - + english.getName(info.language) + + english.nameGetter().getNameFromBCP47(info.language) + "\t" + info.status + "\t" @@ -322,13 +326,17 @@ public static void main(String[] args) { OfficialStatus officialStatus = sInfo.getOfficialStatus(); if (OfficialStatus.unknown != officialStatus) { System.out.print( - region + "\t" + english.getName(CLDRFile.TERRITORY_NAME, region)); + region + + "\t" + + english.nameGetter() + .getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, region)); System.out.println( "\t" + r2 + "\t" - + english.getName(r2) + + english.nameGetter().getNameFromBCP47(r2) + "\t" + "CLDR-ONLY" + "\t" diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/CheckLanguageCodeConverter.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/CheckLanguageCodeConverter.java index fbf837f68ff..14dc0792350 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/CheckLanguageCodeConverter.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/CheckLanguageCodeConverter.java @@ -159,7 +159,7 @@ public static String getName(CLDRFile english, String goodCode) { if (goodCode.startsWith("x_")) { return "Private use: " + goodCode.substring(2); } - return english.getName(goodCode); + return english.nameGetter().getNameFromBCP47(goodCode); } public static void printLine(LanguageLine entry) { diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/CheckYear.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/CheckYear.java index 2ba46b9eed1..f4a7507b6ce 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/CheckYear.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/CheckYear.java @@ -291,7 +291,7 @@ public static void main(String[] args) throws IOException { System.out.println("Skipping default content: " + localeID); continue; } - sorted.put(englishFile.getName(localeID, true), localeID); + sorted.put(englishFile.nameGetter().getNameFromBCP47Bool(localeID, true), localeID); data.put(localeID, new LocaleInfo()); } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LanguageInfoTest.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LanguageInfoTest.java index e2d6dc774e9..cfc73fe0679 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LanguageInfoTest.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LanguageInfoTest.java @@ -85,7 +85,9 @@ private int count(char c, String string) { public static String getName(String item) { return item.contains("*") ? "n/a" - : item.contains("$") ? item : testInfo.getEnglish().getName(item); + : item.contains("$") + ? item + : testInfo.getEnglish().nameGetter().getNameFromBCP47(item); } public static void main(String[] args) { diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LanguageTest.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LanguageTest.java index b2a57bab81d..995708dff3f 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LanguageTest.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LanguageTest.java @@ -17,6 +17,7 @@ import org.unicode.cldr.util.CLDRFile; import org.unicode.cldr.util.Counter2; import org.unicode.cldr.util.LanguageTagParser; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.StandardCodes; import org.unicode.cldr.util.SupplementalDataInfo; import org.unicode.cldr.util.SupplementalDataInfo.BasicLanguageData; @@ -228,14 +229,15 @@ public void addLine(String input, final String result) { private String getLocaleName(String input) { LanguageTagParser parser = new LanguageTagParser().set(input); + NameGetter nameGetter = testInfo.getEnglish().nameGetter(); return (parser.getLanguage().isEmpty() ? "?" : getLanguageName(parser.getLanguage())) + "; " + (parser.getScript().isEmpty() ? "?" : getScriptName(parser.getScript())) + "; " + (parser.getRegion().isEmpty() ? "?" - : testInfo.getEnglish() - .getName(CLDRFile.TERRITORY_NAME, parser.getRegion())); + : nameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, parser.getRegion())); } Set<String> getUnicodeScripts() { @@ -258,7 +260,8 @@ Set<String> getUnicodeScripts() { } private String getScriptName(String script) { - String name = testInfo.getEnglish().getName("script", script); + NameGetter nameGetter = testInfo.getEnglish().nameGetter(); + String name = nameGetter.getNameFromTypestrCode("script", script); if (name != null && !name.equals(script)) { return name; } @@ -277,7 +280,8 @@ public String getDescription(String type, String token) { } private String getLanguageName(String language) { - String name = testInfo.getEnglish().getName("language", language); + NameGetter nameGetter = testInfo.getEnglish().nameGetter(); + String name = nameGetter.getNameFromTypestrCode("language", language); if (name != null && !name.equals(language)) { return name; } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LikelySubtagsTest.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LikelySubtagsTest.java index 832e838983a..40e09465d33 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LikelySubtagsTest.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LikelySubtagsTest.java @@ -375,14 +375,16 @@ public void TestMissingInfoForRegion() { "Missing likely subtags for region: " + region + "\t" - + english.getName("territory", region)); + + english.nameGetter() + .getNameFromTypestrCode("territory", region)); } } else { // container logln( "Missing likely subtags for macroregion (fix to exclude regions having 'en'): " + region + "\t" - + english.getName("territory", region)); + + english.nameGetter() + .getNameFromTypestrCode("territory", region)); } } else { logln("Likely subtags for region: " + region + ":\t " + likely); diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LocaleMatcherTest.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LocaleMatcherTest.java index 8a0191ff188..ac5d938eefb 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LocaleMatcherTest.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/LocaleMatcherTest.java @@ -112,7 +112,8 @@ private void assertCloser(String a, String closer, String further) { // { // continue; // } - // System.out.println(locale + "\t" + CONFIG.getEnglish().getName(locale) + "\t" + + // System.out.println(locale + "\t" + + // CONFIG.getEnglish().nameGetter().getName(locale) + "\t" + // parentId + "\t" + parentIdSimple); // } // } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/StandardCodesTest.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/StandardCodesTest.java index 8c893b4f665..07b80a39ef1 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/StandardCodesTest.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/StandardCodesTest.java @@ -29,7 +29,10 @@ public void TestCoverage() { continue; } for (String locale : sc.getLocaleCoverageLocales(org)) { - String name = locale.equals("*") ? "ALL" : testInfo.getEnglish().getName(locale); + String name = + locale.equals("*") + ? "ALL" + : testInfo.getEnglish().nameGetter().getNameFromBCP47(locale); logln( org + "\t;\t" diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestAttributeValues.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestAttributeValues.java index e2bf827b68c..954174042f6 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestAttributeValues.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestAttributeValues.java @@ -430,7 +430,9 @@ private void show(String language, LanguageInfo languageInfo) { logln( language + "\t" - + config.getEnglish().getName(CLDRFile.LANGUAGE_NAME, language) + + config.getEnglish() + .nameGetter() + .getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, language) + "\t" + languageInfo); } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestBasic.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestBasic.java index 9a3f3773249..25dc05c53a9 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestBasic.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestBasic.java @@ -543,7 +543,7 @@ public void TestAbstractPaths() { for (String locale : getInclusion() <= 5 ? eightPointLocales : cldrFactory.getAvailable()) { CLDRFile file = testInfo.getCLDRFile(locale, resolved); if (file.isNonInheriting()) continue; - logln(locale + "\t-\t" + english.getName(locale)); + logln(locale + "\t-\t" + english.nameGetter().getNameFromBCP47(locale)); for (Iterator<String> it = file.iterator(); it.hasNext(); ) { String path = it.next(); @@ -619,7 +619,7 @@ public void TestPaths() { DisplayAndInputProcessor displayAndInputProcessor = new DisplayAndInputProcessor(file, false); - logln(locale + "\t-\t" + english.getName(locale)); + logln(locale + "\t-\t" + english.nameGetter().getNameFromBCP47(locale)); for (Iterator<String> it = file.iterator(); it.hasNext(); ) { String path = it.next(); @@ -1121,7 +1121,11 @@ public void TestCoreData() { warnings.clear(); String name = - "Locale:" + localeID + " (" + testInfo.getEnglish().getName(localeID) + ")"; + "Locale:" + + localeID + + " (" + + testInfo.getEnglish().nameGetter().getNameFromBCP47(localeID) + + ")"; if (!collations.contains(localeID)) { warnings.put(MissingType.collation, "missing"); diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRFile.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRFile.java index 520fc88c9d7..36ccbdf51dd 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRFile.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRFile.java @@ -85,7 +85,7 @@ public void testFallbackNames() { }; CLDRFile english = testInfo.getEnglish(); for (String[] test : tests) { - assertEquals("", test[1], english.getName(test[0])); + assertEquals("", test[1], english.nameGetter().getNameFromBCP47(test[0])); } } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRLocaleCoverage.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRLocaleCoverage.java index 28c6f6a2f25..86c9dfef479 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRLocaleCoverage.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRLocaleCoverage.java @@ -161,7 +161,8 @@ public void TestLanguageNameCoverage() { if (!localesForNames.contains(locale) && CLDRLocale.getInstance(locale).getParent().equals(CLDRLocale.ROOT)) { official1MSetNames.put( - localeAndSize.getValue(), "\t" + locale + "\t" + ENGLISH.getName(locale)); + localeAndSize.getValue(), + "\t" + locale + "\t" + ENGLISH.nameGetter().getNameFromBCP47(locale)); } } if (!official1MSetNames.isEmpty()) { @@ -179,7 +180,7 @@ public void TestLanguageNameCoverage() { coverageLocales.removeAll(additionsToTranslate); for (String locale : localesForNames) { - logln("\n" + locale + "\t" + ENGLISH.getName(locale)); + logln("\n" + locale + "\t" + ENGLISH.nameGetter().getNameFromBCP47(locale)); } logln("\nmainLocales:" + composeList(mainLocales, "\n\t", new StringBuilder())); @@ -242,7 +243,7 @@ private boolean assertContains( temp.removeAll(set); Set<String> temp2 = new TreeSet<>(); for (String locale : temp) { - temp2.add(locale + "\t" + ENGLISH.getName(locale)); + temp2.add(locale + "\t" + ENGLISH.nameGetter().getNameFromBCP47(locale)); } errln(title + ": Missing:\t" + temp.size() + "\n\t" + Joiner.on("\n\t").join(temp2)); } @@ -340,7 +341,11 @@ public void TestCldrSuperset() { Level maxLevel = Level.max(specialLevel, Level.max(orgToLevel.values().toArray(new Level[0]))); assertEquals( - "cldr level = max for " + locale + " (" + ENGLISH.getName(locale) + ")", + "cldr level = max for " + + locale + + " (" + + ENGLISH.nameGetter().getNameFromBCP47(locale) + + ")", cldrLevel, maxLevel); } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRUtils.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRUtils.java index 2d8d27be505..37f14f1bd41 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRUtils.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRUtils.java @@ -18,6 +18,7 @@ import org.unicode.cldr.util.CLDRLocale; import org.unicode.cldr.util.CLDRLocale.CLDRFormatter; import org.unicode.cldr.util.CLDRLocale.FormatBehavior; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.SimpleFactory; /** @@ -94,10 +95,11 @@ public void TestVariantName() { */ private void checkNames( CLDRFile french, String locale, String combinedLong, String... otherNames) { + NameGetter frenchNameGetter = french.nameGetter(); assertEquals( "Test variant formatting combinedLong " + locale, combinedLong, - french.getName(locale)); + frenchNameGetter.getNameFromBCP47(locale)); String combinedShort = otherNames.length > 0 ? otherNames[0] : combinedLong; String uncombinedLong = otherNames.length > 1 ? otherNames[1] : combinedLong; String uncombinedShort = otherNames.length > 2 ? otherNames[2] : uncombinedLong; @@ -105,15 +107,15 @@ private void checkNames( assertEquals( "Test variant formatting combinedShort " + locale, combinedShort, - french.getName(locale, false, SHORT_ALT_PICKER)); + frenchNameGetter.getNameFromBCP47BoolAlt(locale, false, SHORT_ALT_PICKER)); assertEquals( "Test variant formatting uncombinedLong " + locale, uncombinedLong, - french.getName(locale, true)); + frenchNameGetter.getNameFromBCP47Bool(locale, true)); assertEquals( "Test variant formatting uncombinedShort " + locale, uncombinedShort, - french.getName(locale, true, SHORT_ALT_PICKER)); + frenchNameGetter.getNameFromBCP47BoolAlt(locale, true, SHORT_ALT_PICKER)); } public void TestEmptyCLDRFile() { diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCheckCLDR.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCheckCLDR.java index 5de38d853cf..8ad5b883c57 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCheckCLDR.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCheckCLDR.java @@ -1384,7 +1384,12 @@ public void TestALLOWED_IN_LIMITED_PATHS() { counter.add(LimitedStatus.disallowed, 1); } } - System.out.print(locale + "\t" + english.getName(locale) + "\t" + cldrLevel); + System.out.print( + locale + + "\t" + + english.nameGetter().getNameFromBCP47(locale) + + "\t" + + cldrLevel); for (LimitedStatus limitedStatus : LimitedStatus.values()) { System.out.print("\t" + limitedStatus + ":\t" + counter.get(limitedStatus)); } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCoverage.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCoverage.java index c30648df5bb..ab995724f6d 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCoverage.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCoverage.java @@ -135,7 +135,7 @@ public Multimap<CoreItems, String> checkLocale(CLDRFile testFile) { } private String getLocaleAndName(String locale) { - return locale + "\t" + testInfo.getEnglish().getName(locale); + return locale + "\t" + testInfo.getEnglish().nameGetter().getNameFromBCP47(locale); } private String showColumn(Set items) { diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCoverageLevel.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCoverageLevel.java index 0cbe132b066..b1411b41b89 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCoverageLevel.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCoverageLevel.java @@ -392,7 +392,7 @@ public TypeName(int field) { @Override public String transform(String source) { - String result = ENGLISH.getName(field, source); + String result = ENGLISH.nameGetter().getNameFromTypenumCode(field, source); String extra = ""; if (field == CLDRFile.LANGUAGE_NAME) { String lang = isBigLanguage(source); @@ -1196,7 +1196,8 @@ public void testLSR() { typeAndInfo.getValue().get3(); // it looks like the targetLevel is ignored for (String code : Sets.union(idPartMap.keySet(), setRoot)) { - String displayName = testInfo.getEnglish().getName(type, code); + String displayName = + testInfo.getEnglish().nameGetter().getNameFromTypenumCode(type, code); String path = CLDRFile.getKey(type, code); Level level = coverageLevel.getLevel(path); data.put( diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestDayPeriods.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestDayPeriods.java index cb05f690191..9a3c865e07a 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestDayPeriods.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestDayPeriods.java @@ -48,7 +48,7 @@ public void TestBasicDayPeriods() { logln( locale + "\t" - + CONFIG.getEnglish().getName(locale) + + CONFIG.getEnglish().nameGetter().getNameFromBCP47(locale) + "\t" + dayPeriodFormat + "\t" diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java index 68d312d97a7..d009a81bcb9 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java @@ -1550,7 +1550,8 @@ public void TestListMinimalPairExamples() { + "\"]", Pair.of("gender", unitGender)); } - String localeName = CLDRConfig.getInstance().getEnglish().getName(locale); + String localeName = + CLDRConfig.getInstance().getEnglish().nameGetter().getNameFromBCP47(locale); boolean pluralOnly = true; if (paths.isEmpty()) { pluralSheet.add( diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestInheritance.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestInheritance.java index bbc9e803f95..612aa3948d9 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestInheritance.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestInheritance.java @@ -167,7 +167,10 @@ public void TestLocalesHaveOfficial() { if (!testOrg.contains(language)) { continue; } - System.out.print(language + "\t" + testInfo.getEnglish().getName(language)); + System.out.print( + language + + "\t" + + testInfo.getEnglish().nameGetter().getNameFromBCP47(language)); M3<OfficialStatus, String, Boolean> officialChildren = languageToOfficialChildren.get(language); @@ -194,14 +197,20 @@ private String show(Set<String> joint, boolean showStatus) { LanguageTagParser ltp = new LanguageTagParser().set(s); String script = ltp.getScript(); if (script.length() != 0) { - b.append(testInfo.getEnglish().getName(CLDRFile.SCRIPT_NAME, script)); + b.append( + testInfo.getEnglish() + .nameGetter() + .getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script)); } String region = ltp.getRegion(); if (region.length() != 0) { if (script.length() != 0) { b.append("-"); } - b.append(testInfo.getEnglish().getName(CLDRFile.TERRITORY_NAME, region)); + b.append( + testInfo.getEnglish() + .nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, region)); } b.append(" [").append(s); if (showStatus) { diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLanguageGroup.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLanguageGroup.java index d657ac055fc..a958a025560 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLanguageGroup.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLanguageGroup.java @@ -126,7 +126,7 @@ private String fixedName(String code) { case "grk": return "Hellenic"; default: - return ENGLISH.getName(code).replace(" [Other]", ""); + return ENGLISH.nameGetter().getNameFromBCP47(code).replace(" [Other]", ""); } } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLocale.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLocale.java index 16d820ff482..4849bdd9870 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLocale.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLocale.java @@ -43,6 +43,7 @@ import org.unicode.cldr.util.LocaleValidator; import org.unicode.cldr.util.LocaleValidator.AllowedMatch; import org.unicode.cldr.util.LocaleValidator.AllowedValid; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.SimpleFactory; import org.unicode.cldr.util.SimpleXMLSource; import org.unicode.cldr.util.StandardCodes; @@ -474,14 +475,15 @@ public void TestBrackets() { "Territorie: {0}"); CLDRFile f = new CLDRFile(dxs, root); ExampleGenerator eg = new ExampleGenerator(f, testInfo.getEnglish()); + NameGetter nameGetter = f.nameGetter(); for (String[] row : tests) { if (row[0] != null) { int typeCode = CLDRFile.typeNameToCode(row[0]); - String standAlone = f.getName(typeCode, row[1]); + String standAlone = nameGetter.getNameFromTypenumCode(typeCode, row[1]); logln(typeCode + ": " + standAlone); if (!assertEquals("stand-alone " + row[3], row[2], standAlone)) { typeCode = CLDRFile.typeNameToCode(row[0]); - standAlone = f.getName(typeCode, row[1]); + standAlone = nameGetter.getNameFromTypenumCode(typeCode, row[1]); } if (row[5] != null) { @@ -490,23 +492,32 @@ public void TestBrackets() { assertEquals("example " + row[3], row[5], ExampleGenerator.simplify(example)); } } - String displayName = f.getName(row[3], true, "{0}={1}", "{0} ({1})", "{0}, {1}"); + String displayName = + nameGetter.getNameFromBCP47Etc( + row[3], true, "{0}={1}", "{0} ({1})", "{0}, {1}"); assertEquals("locale " + row[3], row[4], displayName); } } public void TestLocaleNamePattern() { - assertEquals("Locale name", "Chinese", testInfo.getEnglish().getName("zh")); + NameGetter englishNameGetter = testInfo.getEnglish().nameGetter(); + assertEquals("Locale name", "Chinese", englishNameGetter.getNameFromBCP47("zh")); assertEquals( - "Locale name", "Chinese (United States)", testInfo.getEnglish().getName("zh-US")); + "Locale name", + "Chinese (United States)", + englishNameGetter.getNameFromBCP47("zh-US")); assertEquals( "Locale name", "Chinese (Arabic, United States)", - testInfo.getEnglish().getName("zh-Arab-US")); + englishNameGetter.getNameFromBCP47("zh-Arab-US")); CLDRFile japanese = testInfo.getCLDRFile("ja", true); - assertEquals("Locale name", "中国語", japanese.getName("zh")); - assertEquals("Locale name", "中国語 (アメリカ合衆国)", japanese.getName("zh-US")); - assertEquals("Locale name", "中国語 (アラビア文字\u3001アメリカ合衆国)", japanese.getName("zh-Arab-US")); + NameGetter japaneseNameGetter = japanese.nameGetter(); + assertEquals("Locale name", "中国語", japaneseNameGetter.getNameFromBCP47("zh")); + assertEquals("Locale name", "中国語 (アメリカ合衆国)", japaneseNameGetter.getNameFromBCP47("zh-US")); + assertEquals( + "Locale name", + "中国語 (アラビア文字\u3001アメリカ合衆国)", + japaneseNameGetter.getNameFromBCP47("zh-Arab-US")); } public void TestLocaleDisplay() { @@ -583,7 +594,7 @@ public void TestLocaleDisplay() { // assertEquals("LTP(BCP47)=>ICU=>BCP47", bcp47, roundTripId); canonicalizer.transform(ltp); - String name = cldrFile.getName(ltp, compound, null); + String name = cldrFile.nameGetter().getNameFromParserBool(ltp, compound); if (assertEquals(cldrFile.getLocaleID() + "; " + localeId, expected, name)) { formattedExamplesForSpec .append("<tr><td>") @@ -662,7 +673,7 @@ private void showName( if (locale.equals("en-t-d0-accents")) { int debug = 0; } - String name = cldrFile.getName(locale, true, null); + String name = cldrFile.nameGetter().getNameFromBCP47BoolAlt(locale, true, null); if (isVerbose()) { System.out.println(locale + "; " + name); } @@ -679,22 +690,23 @@ private void showName( } public void TestExtendedLanguage() { + NameGetter englishNameGetter = testInfo.getEnglish().nameGetter(); assertEquals( "Extended language translation", "Simplified Chinese", - testInfo.getEnglish().getName("zh_Hans")); + englishNameGetter.getNameFromBCP47("zh_Hans")); assertEquals( "Extended language translation", "Simplified Chinese (Singapore)", - testInfo.getEnglish().getName("zh_Hans_SG")); + englishNameGetter.getNameFromBCP47("zh_Hans_SG")); assertEquals( "Extended language translation", "American English", - testInfo.getEnglish().getName("en-US")); + englishNameGetter.getNameFromBCP47("en-US")); assertEquals( "Extended language translation", "American English (Arabic)", - testInfo.getEnglish().getName("en-Arab-US")); + englishNameGetter.getNameFromBCP47("en-Arab-US")); } public void testAllVariants() { @@ -848,7 +860,7 @@ private void showItem( + "\n\t\tstructure:\t" + ltp.toString(Format.structure)); try { - String name = testInfo.getEnglish().getName(locale); + String name = testInfo.getEnglish().nameGetter().getNameFromBCP47(locale); logln("\tname:\t" + name); } catch (Exception e) { errln("Name for " + locale + "; " + e.getMessage()); diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLsrvCanonicalizer.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLsrvCanonicalizer.java index 318e3a515dd..fe3e7338f5f 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLsrvCanonicalizer.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestLsrvCanonicalizer.java @@ -295,11 +295,13 @@ public void TestAgainstLanguageSubtagRegistry() { continue; } CLDRFile english = CLDRConfig.getInstance().getEnglish(); - String typeName = english.getName(typeCompat, subtag); + String typeName = + english.nameGetter().getNameFromTypestrCode(typeCompat, subtag); String replacementName = preferredValueCompat == null ? "???" - : english.getName(typeCompat, replacementString); + : english.nameGetter() + .getNameFromTypestrCode(typeCompat, replacementString); addExceptions.add( ".put(\"" + subtag diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java index ac9aa4c85db..a103ea0d1fd 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java @@ -48,6 +48,7 @@ import org.unicode.cldr.util.Iso3166Data; import org.unicode.cldr.util.LanguageTagParser; import org.unicode.cldr.util.Level; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.Organization; import org.unicode.cldr.util.Pair; import org.unicode.cldr.util.PathDescription; @@ -82,6 +83,7 @@ public static void main(String[] args) { static final CLDRConfig info = CLDRConfig.getInstance(); static final Factory factory = info.getCommonAndSeedAndMainAndAnnotationsFactory(); static final CLDRFile english = factory.make("en", true); + static final NameGetter englishNameGetter = english.nameGetter(); static final SupplementalDataInfo supplemental = info.getSupplementalDataInfo(); static PathHeader.Factory pathHeaderFactory = PathHeader.getFactory(english); private EnumSet<PageId> badZonePages = EnumSet.of(PageId.UnknownT); @@ -857,7 +859,7 @@ private Set<String> showContained(String territory, int level, Set<String> soFar private String getNameAndOrder(String territory) { return territory + "\t" - + english.getName(CLDRFile.TERRITORY_NAME, territory) + + englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, territory) + "\t" + Containment.getOrder(territory); } @@ -976,10 +978,15 @@ public void TestContainment() { assertEquals("S. America special case", "005", revision); } if (isVerbose()) { - String name = english.getName(CLDRFile.TERRITORY_NAME, cont); - String name2 = english.getName(CLDRFile.TERRITORY_NAME, sub); - String name3 = english.getName(CLDRFile.TERRITORY_NAME, territory); - String name4 = english.getName(CLDRFile.TERRITORY_NAME, revision); + String name = + englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, cont); + String name2 = + englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, sub); + String name3 = + englishNameGetter.getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, territory); + String name4 = + englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, revision); logln( metazone + "\t" + continent + "\t" + name + "\t" + name2 + "\t" + name3 diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPersonNameFormatter.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPersonNameFormatter.java index b5707bebc04..5f541cd0126 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPersonNameFormatter.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPersonNameFormatter.java @@ -1314,7 +1314,7 @@ public List<String> getValues( "Checking\t" + locale + "\t" - + ENGLISH.getName(locale) + + ENGLISH.nameGetter().getNameFromBCP47(locale) + "\t" + order + "\t" diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestScriptMetadata.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestScriptMetadata.java index 1b5a535e4b5..3c31b921bb7 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestScriptMetadata.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestScriptMetadata.java @@ -201,14 +201,19 @@ public void TestGeographicGrouping() { lines.add( Row.of( info.idUsage, - english.getName(CLDRFile.TERRITORY_NAME, continent), + english.nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, continent), info.idUsage + "\t" - + english.getName(CLDRFile.TERRITORY_NAME, container) + + english.nameGetter() + .getNameFromTypenumCode( + CLDRFile.TERRITORY_NAME, container) + "\t" + scriptCode + "\t" - + english.getName(CLDRFile.SCRIPT_NAME, scriptCode))); + + english.nameGetter() + .getNameFromTypenumCode( + CLDRFile.SCRIPT_NAME, scriptCode))); } for (Row.R3<IdUsage, String, String> s : lines) { logln(s.get2()); diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestSubdivisions.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestSubdivisions.java index 327dde1f68e..7081c21f006 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestSubdivisions.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestSubdivisions.java @@ -100,7 +100,7 @@ private void checkSubdivisionFile( R2<List<String>, String> subdivisionAlias = subdivisionAliases.get(subdivision); if (subdivisionAlias != null) { // String countryName = - // CLDRConfig.getInstance().getEnglish().getName(CLDRFile.TERRITORY_NAME, country); + // CLDRConfig.getInstance().getEnglish().nameGetter().getName(CLDRFile.TERRITORY_NAME, country); // assertEquals("country " + country + " = subdivision " + subdivision, countryName, // value); continue; diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestSupplementalInfo.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestSupplementalInfo.java index 87ab3b0780f..b2ca649d8cd 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestSupplementalInfo.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestSupplementalInfo.java @@ -71,6 +71,7 @@ import org.unicode.cldr.util.LanguageTagParser; import org.unicode.cldr.util.Level; import org.unicode.cldr.util.LocaleNames; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.Organization; import org.unicode.cldr.util.Pair; import org.unicode.cldr.util.PluralRanges; @@ -99,6 +100,7 @@ public class TestSupplementalInfo extends TestFmwkPlus { static CLDRConfig testInfo = CLDRConfig.getInstance(); + private static NameGetter englishNameGetter = testInfo.getEnglish().nameGetter(); private static final StandardCodes STANDARD_CODES = StandardCodes.make(); @@ -870,7 +872,7 @@ private void addName(int languageName, String code, Set<String> b) { if (code.isEmpty()) { return; } - String name = testInfo.getEnglish().getName(languageName, code); + String name = englishNameGetter.getNameFromTypenumCode(languageName, code); if (!code.equals(name)) { b.add(code + "=" + name); } @@ -1070,7 +1072,7 @@ public NameCodeTransform(CLDRFile file, int code) { @Override public String transform(String code) { - return file.getName(codeType, code) + " [" + code + "]"; + return file.nameGetter().getNameFromTypenumCode(codeType, code) + " [" + code + "]"; } } @@ -1238,7 +1240,7 @@ private void errlnDiff(String title, Set<String> mapItems, Set<String> keySet) { } private String getRegionName(String region) { - return testInfo.getEnglish().getName(CLDRFile.TERRITORY_NAME, region); + return englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, region); } private Map<String, Integer> getRecursiveContainment( @@ -1316,7 +1318,7 @@ public void TestMacrolanguages() { // now show the items we found for (Scope scope : scopeToCodes.keySet()) { for (String language : scopeToCodes.getAll(scope)) { - String name = testInfo.getEnglish().getName(language); + String name = englishNameGetter.getNameFromBCP47(language); if (name == null || name.equals(language)) { Set<String> set = Iso639Data.getNames(language); if (set != null) { @@ -1535,7 +1537,8 @@ public void TestSupplementalCurrency() { + "\t" + dateInfo.toString() + "\t" - + testInfo.getEnglish().getName(CLDRFile.CURRENCY_NAME, currency)); + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.CURRENCY_NAME, currency)); } } // fix up @@ -1571,7 +1574,8 @@ public void TestSupplementalCurrency() { for (String currency : modernCurrencyCodes.keySet()) { Set<Pair<String, CurrencyDateInfo>> data = modernCurrencyCodes.getAll(currency); - final String name = testInfo.getEnglish().getName(CLDRFile.CURRENCY_NAME, currency); + final String name = + englishNameGetter.getNameFromTypenumCode(CLDRFile.CURRENCY_NAME, currency); Set<String> isoCountries = isoCurrenciesToCountries.getAll(currency); if (isoCountries == null) { @@ -1645,7 +1649,8 @@ public void TestSupplementalCurrency() { + "\t" + nonModernCurrencyCodes); for (String currency : nonModernCurrencyCodes.keySet()) { - final String name = testInfo.getEnglish().getName(CLDRFile.CURRENCY_NAME, currency); + final String name = + englishNameGetter.getNameFromTypenumCode(CLDRFile.CURRENCY_NAME, currency); if (name == null) { errln("No English name for currency " + currency); continue; @@ -1686,10 +1691,8 @@ public void TestSupplementalCurrency() { + "\t" + dateInfo + "\t" - + testInfo.getEnglish() - .getName( - CLDRFile.CURRENCY_NAME, - dateInfo.getCurrency())); + + englishNameGetter.getNameFromTypenumCode( + CLDRFile.CURRENCY_NAME, dateInfo.getCurrency())); } } } @@ -2137,7 +2140,7 @@ private Set<String> getNames(Set<String> temp) { Set<String> tempNames = new TreeSet<>(); for (String langCode : temp) { tempNames.add( - testInfo.getEnglish().getName(CLDRFile.LANGUAGE_NAME, langCode) + englishNameGetter.getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, langCode) + " (" + langCode + ")"); @@ -2219,6 +2222,9 @@ public void testPredominantEncompassed() { private String codeAndName(String macro) { // TODO Auto-generated method stub - return CLDRConfig.getInstance().getEnglish().getName(macro) + " (" + macro + ")"; + return CLDRConfig.getInstance().getEnglish().nameGetter().getNameFromBCP47(macro) + + " (" + + macro + + ")"; } } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnContainment.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnContainment.java index df55a3560de..012535076fc 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnContainment.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnContainment.java @@ -82,7 +82,10 @@ private String name(Collection<String> codes) { } private String name(String code) { - String name = testInfo.getEnglish().getName(CLDRFile.TERRITORY_NAME, code); + String name = + testInfo.getEnglish() + .nameGetter() + .getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, code); return name + " (" + code + ")"; } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestValidity.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestValidity.java index 7b72eb080c0..44002ae14ae 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestValidity.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestValidity.java @@ -568,9 +568,12 @@ private String makeAliasXml( + "\"/>" + " <!-- " + TransliteratorUtilities.toXML.transform( - CLDRConfig.getInstance().getEnglish().getName(code) + CLDRConfig.getInstance().getEnglish().nameGetter().getNameFromBCP47(code) + " ⇒ " - + CLDRConfig.getInstance().getEnglish().getName(lstrReplacement)) + + CLDRConfig.getInstance() + .getEnglish() + .nameGetter() + .getNameFromBCP47(lstrReplacement)) + " -->"; } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/XLocaleMatcherTest.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/XLocaleMatcherTest.java index 6bc972bdea4..42c2151e2e1 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/XLocaleMatcherTest.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/XLocaleMatcherTest.java @@ -83,7 +83,8 @@ public static void main(String[] args) throws Exception { // { // continue; // } - // System.out.println(locale + "\t" + CONFIG.getEnglish().getName(locale) + "\t" + + // System.out.println(locale + "\t" + + // CONFIG.getEnglish().nameGetter().getName(locale) + "\t" + // parentId + "\t" + parentIdSimple); // } // } diff --git a/tools/cldr-rdf/src/main/java/org/unicode/cldr/tool/GenerateLanguageContainment.java b/tools/cldr-rdf/src/main/java/org/unicode/cldr/tool/GenerateLanguageContainment.java index 85f742f1ab1..5cbc0bddf58 100644 --- a/tools/cldr-rdf/src/main/java/org/unicode/cldr/tool/GenerateLanguageContainment.java +++ b/tools/cldr-rdf/src/main/java/org/unicode/cldr/tool/GenerateLanguageContainment.java @@ -237,7 +237,7 @@ public <T extends Iterable<String>, U extends Iterable<T>> String showNameAndCod code -> code.equals(LocaleNames.MUL) ? LocaleNames.ROOT - : ENGLISH.getName(code) + " (" + code + ")"; + : ENGLISH.nameGetter().getNameFromBCP47(code) + " (" + code + ")"; static final Set<String> COLLECTIONS; @@ -400,7 +400,12 @@ void run(String[] args) throws IOException { if (true) { // check on items for (String check : Arrays.asList("sw", "km", "ksh", "wae", "kea", "mfe", "th", "lo")) { - System.out.println("Checking " + ENGLISH.getName(check) + "[" + check + "]"); + System.out.println( + "Checking " + + ENGLISH.nameGetter().getNameFromBCP47(check) + + "[" + + check + + "]"); Collection<String> entities = QUERY_HELPER.codeToEntity.get(check); if (entities.isEmpty()) { System.out.println("no code for " + check + ": " + entities); diff --git a/tools/cldr-rdf/src/main/java/org/unicode/cldr/tool/SubdivisionNode.java b/tools/cldr-rdf/src/main/java/org/unicode/cldr/tool/SubdivisionNode.java index cccc5d4b9de..676ba3ee411 100644 --- a/tools/cldr-rdf/src/main/java/org/unicode/cldr/tool/SubdivisionNode.java +++ b/tools/cldr-rdf/src/main/java/org/unicode/cldr/tool/SubdivisionNode.java @@ -35,6 +35,7 @@ import org.unicode.cldr.util.ChainedMap.M3; import org.unicode.cldr.util.DtdType; import org.unicode.cldr.util.Factory; +import org.unicode.cldr.util.NameGetter; import org.unicode.cldr.util.Pair; import org.unicode.cldr.util.PatternCache; import org.unicode.cldr.util.StandardCodes; @@ -63,6 +64,7 @@ public class SubdivisionNode { CaseMap.toTitle().wholeString().noLowercase(); static final CLDRConfig CLDR_CONFIG = CLDRConfig.getInstance(); static final CLDRFile ENGLISH_CLDR = CLDR_CONFIG.getEnglish(); + static final NameGetter englishNameGetter = ENGLISH_CLDR.nameGetter(); static final Normalizer2 nfc = Normalizer2.getNFCInstance(); public static String convertToCldr(String regionOrSubdivision) { @@ -263,7 +265,8 @@ private String getBestName(String value, boolean useIso) { SubdivisionInfo.SUBDIVISION_ALIASES_FORMER.get(value); if (subdivisionAlias != null) { String country = subdivisionAlias.get0().get(0); - cldrName = ENGLISH_CLDR.getName(CLDRFile.TERRITORY_NAME, country); + cldrName = + englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, country); if (cldrName != null) { return fixName(cldrName); } @@ -612,7 +615,8 @@ private String getBestName(List<String> replaceBy, boolean useIso) { result.append(", "); } if (SubdivisionNames.isRegionCode(s)) { - result.append(ENGLISH_CLDR.getName(CLDRFile.TERRITORY_NAME, s)); + result.append( + englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, s)); } else { result.append(sdset.getBestName(s, useIso)); }