Skip to content

Commit

Permalink
CLDR-15830 Use getNameFromTypenumCode instead of getNameFromTypestrCo…
Browse files Browse the repository at this point in the history
  • Loading branch information
btangmu authored Dec 13, 2024
1 parent 178ef98 commit 9263526
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,8 @@ public Object transform(Object source) {
public Object transform(Object source) {
if (english == null) english = cldrFactory.make("en", true);
return english.nameGetter()
.getNameFromTypestrCode("currency", source.toString())
.getNameFromTypenumCode(
CLDRFile.CURRENCY_NAME, source.toString())
+ " ("
+ source
+ ")";
Expand Down Expand Up @@ -1191,9 +1192,11 @@ public void TestSupplementalData() {
}
}
logln("Missing English currency names");
NameGetter englishNameGetter = english.nameGetter();
for (Iterator<String> it = legalCurrencies.iterator(); it.hasNext(); ) {
String currency = it.next();
String name = english.nameGetter().getNameFromTypestrCode("currency", currency);
String name =
englishNameGetter.getNameFromTypenumCode(CLDRFile.CURRENCY_NAME, currency);
if (name == null) {
String standardName = sc.getFullData("currency", currency).get(0);
logln("\t\t\t<currency type=\"" + currency + "\">");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,10 @@ private static List<String> compare(
BasicLanguageData.Type oldValue = oldDataToType.get(s);
BasicLanguageData.Type newValue = newDataToType.get(s);
if (!CldrUtility.equals(oldValue, newValue)) {
int code = s.length() == 4 ? CLDRFile.SCRIPT_NAME : CLDRFile.TERRITORY_NAME;
String name = englishNameGetter.getNameFromTypenumCode(code, s);
temp.setLength(0);
temp.append("[")
.append(s)
.append(":")
.append(
englishNameGetter.getNameFromTypestrCode(
s.length() == 4 ? "script" : "region", s))
.append("] ");
temp.append("[").append(s).append(":").append(name).append("] ");
if (oldValue == null) {
temp.append(" added as ").append(newValue);
} else if (newValue == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ private static void writeZonePrettyPath(
"# "
+ newCountry
+ "\t"
+ nameGetter.getNameFromTypestrCode("territory", newCountry));
+ nameGetter.getNameFromTypenumCode(
CLDRFile.TERRITORY_NAME, newCountry));
lastCountry = newCountry;
}
Log.println("\t'" + oldName + "'\t>\t'" + newName + "';");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.unicode.cldr.util.CldrUtility;
import org.unicode.cldr.util.CollatorHelper;
import org.unicode.cldr.util.Factory;
import org.unicode.cldr.util.NameGetter;
import org.unicode.cldr.util.Pair;
import org.unicode.cldr.util.PathUtilities;
import org.unicode.cldr.util.PatternCache;
Expand Down Expand Up @@ -155,13 +156,13 @@ public static void main(String[] args) throws IOException {
System.out.println("\titems: " + itemCount);
totalCount += itemCount;
}

NameGetter englishNameGetter = english.nameGetter();
for (String name : skipped) {
System.out.println(
"\tSkipping, no CLDR locale file: "
+ name
+ "\t"
+ english.nameGetter().getNameFromBCP47(name));
+ englishNameGetter.getNameFromBCP47(name));
}
double deltaTime = System.currentTimeMillis() - startTime;
System.out.println("Elapsed: " + deltaTime / 1000.0 + " seconds");
Expand Down Expand Up @@ -448,10 +449,13 @@ public void addName(String name, String code, boolean skipMessage) {
DataHandler(Type type, String pattern) {
this.type = type;
matcher = PatternCache.get(pattern).matcher("");
NameGetter englishNameGetter = english.nameGetter();
switch (type) {
case LANGUAGE:
for (String code : sc.getAvailableCodes("language")) {
String name = english.nameGetter().getNameFromTypestrCode("language", code);
String name =
englishNameGetter.getNameFromTypenumCode(
CLDRFile.LANGUAGE_NAME, code);
if (name == null) {
// System.out.println("Missing name for: " + code);
continue;
Expand Down Expand Up @@ -493,7 +497,8 @@ public void addName(String name, String code, boolean skipMessage) {
case REGION:
for (String code : sc.getAvailableCodes("territory")) {
String name =
english.nameGetter().getNameFromTypestrCode("territory", code);
englishNameGetter.getNameFromTypenumCode(
CLDRFile.TERRITORY_NAME, code);
if (name == null) {
// System.out.println("Missing name for: " + code);
continue;
Expand Down Expand Up @@ -532,7 +537,9 @@ public void addName(String name, String code, boolean skipMessage) {
break;
case CURRENCY:
for (String code : sc.getAvailableCodes("currency")) {
String name = english.nameGetter().getNameFromTypestrCode("currency", code);
String name =
englishNameGetter.getNameFromTypenumCode(
CLDRFile.CURRENCY_NAME, code);
if (name == null) {
// System.out.println("Missing name for: " + code);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.unicode.cldr.util.DateTimeCanonicalizer.DateTimePatternType;
import org.unicode.cldr.util.Factory;
import org.unicode.cldr.util.LanguageTagParser;
import org.unicode.cldr.util.NameGetter;
import org.unicode.cldr.util.PreferredAndAllowedHour;
import org.unicode.cldr.util.SupplementalDataInfo.OfficialStatus;
import org.unicode.cldr.util.SupplementalDataInfo.PopulationData;
Expand Down Expand Up @@ -261,21 +262,24 @@ public static void main(String[] args) {
if (tag.equals("h")) {
tag += "*";
}

NameGetter englishNameGetter = ENGLISH.nameGetter();
System.out.println(
tag
+ "\t"
+ region
+ "\t"
+ ENGLISH.nameGetter().getNameFromTypestrCode("territory", region)
+ englishNameGetter.getNameFromTypenumCode(
CLDRFile.TERRITORY_NAME, region)
+ "\t"
+ subcontinent
+ "\t"
+ ENGLISH.nameGetter().getNameFromTypestrCode("territory", subcontinent)
+ englishNameGetter.getNameFromTypenumCode(
CLDRFile.TERRITORY_NAME, subcontinent)
+ "\t"
+ continent
+ "\t"
+ ENGLISH.nameGetter().getNameFromTypestrCode("territory", continent)
+ englishNameGetter.getNameFromTypenumCode(
CLDRFile.TERRITORY_NAME, continent)
+ "\t"
+ showInfo(preferredSet));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ private void showRegionCodeInfo() throws IOException {
format(popData.getPopulation()),
format(popData.getLiteratePopulation() / popData.getPopulation()),
format(popData.getGdp()),
englishNameGetter.getNameFromTypestrCode("territory", territory));
englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, 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<>();
Expand Down Expand Up @@ -742,7 +742,8 @@ private void showRegionCodeInfo() throws IOException {
+ "\t"
+ region
+ "\t"
+ englishNameGetter.getNameFromTypestrCode("territory", region));
+ englishNameGetter.getNameFromTypenumCode(
CLDRFile.TERRITORY_NAME, region));
}

showGeneratedCommentEnd(DATA_INDENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private static String getFixedDisplayCountry(String localeID, String country) {
}
}
CLDRFile cldr = factory.make(localeID, true);
String name = cldr.nameGetter().getNameFromTypestrCode("territory", country);
String name = cldr.nameGetter().getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, country);
if (false && HACK) {
Object trial = fixCountryNames.get(name);
if (trial != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ private void findSuspectData() {
territory //
+ "\t"
+ english.nameGetter()
.getNameFromTypestrCode("territory", territory) //
.getNameFromTypenumCode(
CLDRFile.TERRITORY_NAME, territory) //
+ "\t"
+ territoryPop //
+ "\t"
Expand Down
18 changes: 10 additions & 8 deletions tools/cldr-code/src/main/java/org/unicode/cldr/tool/Misc.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.unicode.cldr.util.Factory;
import org.unicode.cldr.util.Iso3166Data;
import org.unicode.cldr.util.LanguageTagParser;
import org.unicode.cldr.util.NameGetter;
import org.unicode.cldr.util.PatternCache;
import org.unicode.cldr.util.SimpleXMLSource;
import org.unicode.cldr.util.StandardCodes;
Expand Down Expand Up @@ -266,6 +267,7 @@ private static void showLanguageTagCount() {
private static void listObsoletes() {
// java.util.TimeZone t;
StandardCodes sc = StandardCodes.make();
NameGetter englishNameGetter = english.nameGetter();
for (Iterator<String> typeIt = sc.getAvailableTypes().iterator(); typeIt.hasNext(); ) {
String type = typeIt.next();
System.out.println(type);
Expand All @@ -276,13 +278,13 @@ private static void listObsoletes() {
if (list.size() < 3) continue;
String replacementCode = list.get(2);
if (replacementCode.length() == 0) continue;
System.out.println(
code
+ " => "
+ replacementCode
+ "; "
+ english.nameGetter()
.getNameFromTypestrCode(type, replacementCode));
/*
* TODO: use getNameFromTypenumCode instead of getNameFromTypestrCode here.
* Reference: https://unicode-org.atlassian.net/browse/CLDR-15830
* type is derived from sc.getAvailableTypes()
*/
String name = englishNameGetter.getNameFromTypestrCode(type, replacementCode);
System.out.println(code + " => " + replacementCode + "; " + name);
}
}
}
Expand Down Expand Up @@ -481,7 +483,7 @@ static void printZoneAliases() {
new_old.put(zone, new TreeSet<String>(col));
String country = zone_countries.get(zone);
String name =
english.nameGetter().getNameFromTypestrCode("territory", country)
english.nameGetter().getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, country)
+ " ("
+ country
+ ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2231,8 +2231,8 @@ public void printCurrency(PrintWriter index) throws IOException {
+ infoItem.getCurrency()
+ "</td>"
+ "<td class='target'>"
+ englishNameGetter.getNameFromTypestrCode(
"currency", infoItem.getCurrency())
+ englishNameGetter.getNameFromTypenumCode(
CLDRFile.CURRENCY_NAME, infoItem.getCurrency())
+ "</td>"
+ "</tr>");
}
Expand Down Expand Up @@ -2287,8 +2287,8 @@ public void printCurrency(PrintWriter index) throws IOException {
"<tr>"
+ "<td class='source nowrap'>"
+ TransliteratorUtilities.toHTML.transform(
englishNameGetter.getNameFromTypestrCode(
"currency", currency))
englishNameGetter.getNameFromTypenumCode(
CLDRFile.CURRENCY_NAME, currency))
+ "</td>"
+ "<td class='source'>"
+ CldrUtility.getDoubleLinkedText(currency)
Expand Down Expand Up @@ -2369,7 +2369,7 @@ public void printCurrency(PrintWriter index) throws IOException {

private String getTerritoryName(String territory) {
String name;
name = englishNameGetter.getNameFromTypestrCode("territory", territory);
name = englishNameGetter.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, territory);
if (name == null) {
name = sc.getData("territory", territory);
}
Expand Down Expand Up @@ -2972,6 +2972,12 @@ 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)) {
/*
* TODO: use getNameFromTypenumCode instead of getNameFromTypestrCode here.
* Reference: https://unicode-org.atlassian.net/browse/CLDR-15830
* codeType is either CodeType.territory or CodeType.currency
* cldrCodeType is either "region" or "currency"
*/
String name = englishNameGetter.getNameFromTypestrCode(cldrCodeType, territory);
temp.put(name == null ? territory : name, territory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ private static String spreadsheetLine(
+ "\t"
+ ENGLISH.nameGetter().getNameFromBCP47(language)
+ "\t"
+ ENGLISH.nameGetter().getNameFromTypestrCode("script", script)
+ ENGLISH.nameGetter().getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script)
+ "\t"
+ cldrLocaleLevelGoal
+ "\t"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ public static int typeNameToCode(String type) {
if (type.equalsIgnoreCase("region")) {
type = "territory";
}
for (int i = 0; i < LIMIT_TYPES; ++i) {
for (int i = 0; i <= LIMIT_TYPES; ++i) {
if (type.equalsIgnoreCase(getNameName(i))) {
return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public CLDRFormatter(FormatBehavior behavior) {
@Override
public String getDisplayVariant(CLDRLocale cldrLocale) {
if (file != null)
return file.nameGetter().getNameFromTypestrCode("variant", cldrLocale.getVariant());
return file.nameGetter()
.getNameFromTypenumCode(CLDRFile.VARIANT_NAME, cldrLocale.getVariant());
return tryForBetter(super.getDisplayVariant(cldrLocale), cldrLocale.getVariant());
}

Expand Down Expand Up @@ -181,23 +182,24 @@ public String getDisplayName(
@Override
public String getDisplayScript(CLDRLocale cldrLocale) {
if (file != null)
return file.nameGetter().getNameFromTypestrCode("script", cldrLocale.getScript());
return file.nameGetter()
.getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, cldrLocale.getScript());
return tryForBetter(super.getDisplayScript(cldrLocale), cldrLocale.getScript());
}

@Override
public String getDisplayLanguage(CLDRLocale cldrLocale) {
if (file != null)
return file.nameGetter()
.getNameFromTypestrCode("language", cldrLocale.getLanguage());
.getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, cldrLocale.getLanguage());
return tryForBetter(super.getDisplayLanguage(cldrLocale), cldrLocale.getLanguage());
}

@Override
public String getDisplayCountry(CLDRLocale cldrLocale) {
if (file != null)
return file.nameGetter()
.getNameFromTypestrCode("territory", cldrLocale.getCountry());
.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, cldrLocale.getCountry());
return tryForBetter(super.getDisplayLanguage(cldrLocale), cldrLocale.getLanguage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,8 @@ public String getDescription(String path, String value, Object context) {
found = true;
} else if (country != null) {
String countryName =
english.nameGetter().getNameFromTypestrCode("territory", country);
english.nameGetter()
.getNameFromTypenumCode(CLDRFile.TERRITORY_NAME, country);
if (countryName != null) {
if (!codeName.equals(countryName)) {
code = "the city “" + codeName + "” (in " + countryName + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Set<String> getUnicodeScripts() {

private String getScriptName(String script) {
NameGetter nameGetter = testInfo.getEnglish().nameGetter();
String name = nameGetter.getNameFromTypestrCode("script", script);
String name = nameGetter.getNameFromTypenumCode(CLDRFile.SCRIPT_NAME, script);
if (name != null && !name.equals(script)) {
return name;
}
Expand All @@ -281,7 +281,7 @@ public String getDescription(String type, String token) {

private String getLanguageName(String language) {
NameGetter nameGetter = testInfo.getEnglish().nameGetter();
String name = nameGetter.getNameFromTypestrCode("language", language);
String name = nameGetter.getNameFromTypenumCode(CLDRFile.LANGUAGE_NAME, language);
if (name != null && !name.equals(language)) {
return name;
}
Expand Down
Loading

0 comments on commit 9263526

Please sign in to comment.