Skip to content

Commit

Permalink
CLDR-15830 Rename some NameGetter methods; use NameOpt.COMPOUND_ONLY …
Browse files Browse the repository at this point in the history
…instead of boolean

-Rename getNameFromBCP47 to getNameFromIdentifier, since may not be only BCP47; change some comments accordingly

-Avoid boolean parameter onlyConstructCompound; use enum NameGetter.NameOpt instead, values COMPOUND_ONLY and DEFAULT
  • Loading branch information
btangmu committed Dec 15, 2024
1 parent 5eb6924 commit 3c96a98
Show file tree
Hide file tree
Showing 93 changed files with 320 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.TreeMap;
import org.unicode.cldr.util.CLDRLocale;
import org.unicode.cldr.util.CLDRLocale.CLDRFormatter;
import org.unicode.cldr.util.NameGetter;

public class LocaleTree {
CLDRFormatter displayLocale;
Expand Down Expand Up @@ -97,7 +98,7 @@ public CLDRLocale getLocaleCode(String localeName) {
}

public String getLocaleDisplayName(CLDRLocale locale) {
return displayLocale.getDisplayName(locale, true, null);
return displayLocale.getDisplayName(locale, NameGetter.NameOpt.COMPOUND_ONLY, null);
}

public Map<String, CLDRLocale> getMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ private void run() throws IOException {
Map<String, String> languageNameToCode = new TreeMap<>();
NameGetter nameGetter = english.nameGetter();
for (String languageCode : info.getLanguages()) {
languageNameToCode.put(nameGetter.getNameFromBCP47(languageCode), languageCode);
languageNameToCode.put(
nameGetter.getNameFromIdentifier(languageCode), languageCode);
}
out.println("\n@sheet:CLDR County Data");
out.println("code\tgdp\tlit-pop\tpopulation\tliteracy");
Expand All @@ -74,7 +75,7 @@ private void run() throws IOException {
Map<String, Counter2<String>> langToCountriesOfficial = new TreeMap<>();

for (String languageCode : info.getLanguages()) {
String languageName = nameGetter.getNameFromBCP47(languageCode);
String languageName = nameGetter.getNameFromIdentifier(languageCode);

String baseLanguage = languageCode;
ltp.set(languageCode);
Expand Down
10 changes: 7 additions & 3 deletions tools/cldr-code/src/main/java/org/unicode/cldr/draft/Misc.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ private static void showDefaultContent(String... strings) {
}
}
System.out.println(
string + "\t" + defCon + "\t" + english.nameGetter().getNameFromBCP47(defCon));
string
+ "\t"
+ defCon
+ "\t"
+ english.nameGetter().getNameFromIdentifier(defCon));
}
}

Expand Down Expand Up @@ -329,7 +333,7 @@ private static void showExemplarSize() {
if (temp != null) {
baseLanguage = temp.get0().get(0);
}
String englishName = english.nameGetter().getNameFromBCP47(baseLanguage);
String englishName = english.nameGetter().getNameFromIdentifier(baseLanguage);
CLDRFile cldrFile = factory.make(baseLanguage, false);
UnicodeSet set = cldrFile.getExemplarSet("", WinningChoice.WINNING);
int script = -1;
Expand All @@ -340,7 +344,7 @@ private static void showExemplarSize() {
break;
}
}
String nativeName = cldrFile.nameGetter().getNameFromBCP47(baseLanguage);
String nativeName = cldrFile.nameGetter().getNameFromIdentifier(baseLanguage);
nameAndInfo.add(
englishName
+ "\t"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.nameGetter().getNameFromBCP47(locale);
String result = english.nameGetter().getNameFromIdentifier(locale);
/*
* Collection c = Utility.splitList(locale, '_', false, null);
* String[] pieces = new String[c.size()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ private static String getEnglishPathValue(String path) {
*/
private static String getLocaleAndName(String locale) {
String localizedName =
CheckCLDR.getDisplayInformation().nameGetter().getNameFromBCP47(locale);
CheckCLDR.getDisplayInformation().nameGetter().getNameFromIdentifier(locale);
if (localizedName == null || localizedName.equals(locale)) return locale;
return locale + " [" + localizedName + "]";
}
Expand All @@ -2000,7 +2000,7 @@ private static String getLocaleAndName(String locale) {
*/
private static String getNameAndLocale(String locale, boolean linkToXml) {
String localizedName =
CheckCLDR.getDisplayInformation().nameGetter().getNameFromBCP47(locale);
CheckCLDR.getDisplayInformation().nameGetter().getNameFromIdentifier(locale);
if (localizedName == null || localizedName.equals(locale)) return locale;
if (linkToXml) {
locale =
Expand All @@ -2015,7 +2015,7 @@ private static String getNameAndLocale(String locale, boolean linkToXml) {

private static String getLocaleName(String locale) {
String localizedName =
CheckCLDR.getDisplayInformation().nameGetter().getNameFromBCP47(locale);
CheckCLDR.getDisplayInformation().nameGetter().getNameFromIdentifier(locale);
if (localizedName == null || localizedName.equals(locale)) return locale;
return localizedName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static void main(String[] args) {
+ "\t"
+ rank
+ "\t"
+ nameGetter.getNameFromBCP47(locale)
+ nameGetter.getNameFromIdentifier(locale)
+ "\t"
+ locale);
for (String sd : SUBDIVISIONS) {
Expand All @@ -173,7 +173,7 @@ public static void main(String[] args) {
+ "\t"
+ rank
+ "\t"
+ english.nameGetter().getNameFromBCP47(locale)
+ english.nameGetter().getNameFromIdentifier(locale)
+ "\t"
+ locale);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ private void handlePersonName(XPathParts parts, String value, List<String> examp
final String name =
localeId.equals("und")
? "«any other»"
: nameGetter2.getNameFromBCP47(localeId);
: nameGetter2.getNameFromIdentifier(localeId);
examples.add(localeId + " = " + name);
}
break;
Expand Down Expand Up @@ -3116,9 +3116,9 @@ private void handleDisplayNames(
for (int i = 0; i < locales.size(); i++) {
examples.add(
invertBackground(
nameGetter.getNameFromBCP47Etc(
nameGetter.getNameFromIdentifierEtc(
locales.get(i),
false,
NameGetter.NameOpt.DEFAULT,
localeKeyTypePattern,
localePattern,
localeSeparator)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ private static void checkPaths() {
DisplayAndInputProcessor displayAndInputProcessor =
new DisplayAndInputProcessor(file, false);

System.out.println(locale + "\t-\t" + english.nameGetter().getNameFromBCP47(locale));
System.out.println(
locale + "\t-\t" + english.nameGetter().getNameFromIdentifier(locale));
DtdType dtdType = null;

for (Iterator<String> it = file.iterator(); it.hasNext(); ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private static void testWeights() {
}
NameGetter nameGetter = english.nameGetter();
for (Pair<Integer, String> p : rel) {
System.out.println(p + "\t" + nameGetter.getNameFromBCP47(p.getSecond()));
System.out.println(p + "\t" + nameGetter.getNameFromIdentifier(p.getSecond()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static void checkAgainstLanguageScript() {
nameGetter.getNameFromTypeEnumCode(NameType.TERRITORY, territory);
if (otherLanguagesLeftover.size() != 0) {
for (String other : otherLanguagesLeftover) {
String name = nameGetter.getNameFromBCP47(other);
String name = nameGetter.getNameFromIdentifier(other);
System.out.println(
territoryString + "\t" + territory + "\t" + name + "\t" + other);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void writeSubcharts(Anchors anchors) throws IOException {
if (locale.startsWith("en")) {
int debug = 0;
}
String name = nameGetter.getNameFromBCP47Bool(locale, true);
String name = nameGetter.getNameFromIndentifierCompoundOnly(locale);
int baseEnd = locale.indexOf('_');
ULocale loc = new ULocale(baseEnd < 0 ? locale : locale.substring(0, baseEnd));
LanguageGroup group = LanguageGroup.get(loc);
Expand All @@ -189,7 +189,7 @@ public void writeSubcharts(Anchors anchors) throws IOException {
for (Entry<LanguageGroup, Set<R3<Integer, String, String>>> groupPairs :
groupToNameAndCodeSorted.keyValuesSet()) {
LanguageGroup group = groupPairs.getKey();
String ename = nameGetter.getNameFromBCP47Bool("en", true);
String ename = nameGetter.getNameFromIndentifierCompoundOnly("en");
nameToCode.clear();
nameToCode.put(ename, "en"); // always have english first

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.unicode.cldr.util.CLDRPaths;
import org.unicode.cldr.util.Factory;
import org.unicode.cldr.util.FileCopier;
import org.unicode.cldr.util.NameGetter;
import org.unicode.cldr.util.Pair;
import org.unicode.cldr.util.PatternCache;
import org.unicode.cldr.util.XMLFileReader;
Expand Down Expand Up @@ -230,7 +231,10 @@ public void writeSubcharts(Anchors anchors) throws IOException {
}
new Subchart(
ENGLISH.nameGetter()
.getNameFromBCP47BoolAlt(locale, true, CLDRFile.SHORT_ALTS),
.getNameFromIdentifierOptAlt(
locale,
NameGetter.NameOpt.COMPOUND_ONLY,
CLDRFile.SHORT_ALTS),
locale,
data)
.writeChart(anchors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void writeContents(FormattedFileWriter pw) throws IOException {
tablePrinter
.addRow()
.addCell(group)
.addCell(ENGLISH.nameGetter().getNameFromBCP47(locale))
.addCell(ENGLISH.nameGetter().getNameFromIdentifier(locale))
.addCell(locale)
// .addCell(type)
.addCell(df.format(time))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ private void writeDiffs(
.addCell(coverageLevel)
.finishRow();
}
String title = ENGLISH.nameGetter().getNameFromBCP47(file) + " " + chartNameCap;
String title = ENGLISH.nameGetter().getNameFromIdentifier(file) + " " + chartNameCap;
writeTable(anchors, file, tablePrinter, title, tsvFile);

diff.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private TablePrinter getFormattedGrammarInfo(Set<String> localeIds) {
}
Set<String> failures = new LinkedHashSet<>();
GrammarInfo grammarInfo = SDI.getGrammarInfo(localeId, false);
String localeName = CONFIG.getEnglish().nameGetter().getNameFromBCP47(localeId);
String localeName = CONFIG.getEnglish().nameGetter().getNameFromIdentifier(localeId);
for (GrammaticalFeature feature : GrammaticalFeature.values()) {
Map<GrammaticalScope, Set<String>> scopeToValues =
grammarInfo.get(GrammaticalTarget.nominal, feature);
Expand Down Expand Up @@ -905,7 +905,7 @@ public void writeSubcharts(Anchors anchors) throws IOException {
powerTable));

if (!info.isEmpty()) {
String name = ENGLISH.nameGetter().getNameFromBCP47(locale);
String name = ENGLISH.nameGetter().getNameFromIdentifier(locale);
new Subchart(name + ": Unit Grammar Info", locale, info).writeChart(anchors);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.util.List;
import org.unicode.cldr.util.CLDRFile;
import org.unicode.cldr.util.NameGetter;

public class ChartLanguageMatching extends Chart {

Expand Down Expand Up @@ -80,7 +81,8 @@ public void writeContents(FormattedFileWriter pw) throws IOException {
private String getName(String codeWithStars, boolean user) {
if (!codeWithStars.contains("*") && !codeWithStars.contains("$")) {
return ENGLISH.nameGetter()
.getNameFromBCP47BoolAlt(codeWithStars, true, CLDRFile.SHORT_ALTS);
.getNameFromIdentifierOptAlt(
codeWithStars, NameGetter.NameOpt.COMPOUND_ONLY, CLDRFile.SHORT_ALTS);
}
String[] parts = codeWithStars.split("_");
if (parts[0].equals("*")) {
Expand All @@ -100,8 +102,10 @@ private String getName(String codeWithStars, boolean user) {
}
String result =
ENGLISH.nameGetter()
.getNameFromBCP47BoolAlt(
String.join("_", parts), true, CLDRFile.SHORT_ALTS);
.getNameFromIdentifierOptAlt(
String.join("_", parts),
NameGetter.NameOpt.COMPOUND_ONLY,
CLDRFile.SHORT_ALTS);
if (user) {
result =
result.replace("Xxxx", "any-script")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public String getDirectory() {

@Override
public String getTitle() {
return ENGLISH.nameGetter().getNameFromBCP47(locale) + ": Person Names";
return ENGLISH.nameGetter().getNameFromIdentifier(locale) + ": Person Names";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void writeSubcharts(Anchors anchors) throws IOException {
if (locale.startsWith("en")) {
int debug = 0;
}
String name = ENGLISH.nameGetter().getNameFromBCP47Bool(locale, true);
String name = ENGLISH.nameGetter().getNameFromIndentifierCompoundOnly(locale);
int baseEnd = locale.indexOf('_');
ULocale loc = new ULocale(baseEnd < 0 ? locale : locale.substring(0, baseEnd));
LanguageGroup group = LanguageGroup.get(loc);
Expand All @@ -113,7 +113,7 @@ public void writeSubcharts(Anchors anchors) throws IOException {
for (Entry<LanguageGroup, Set<R3<Integer, String, String>>> groupPairs :
groupToNameAndCodeSorted.keyValuesSet()) {
LanguageGroup group = groupPairs.getKey();
String ename = ENGLISH.nameGetter().getNameFromBCP47Bool("en", true);
String ename = ENGLISH.nameGetter().getNameFromIndentifierCompoundOnly("en");
nameToCode.clear();
nameToCode.put(ename, "en"); // always have english first

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public String getDirectory() {

@Override
public String getTitle() {
return ENGLISH.nameGetter().getNameFromBCP47(locale) + ": Overall Errors";
return ENGLISH.nameGetter().getNameFromIdentifier(locale) + ": Overall Errors";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static void main(String[] args) {
+ "\t"
+ language
+ "\t"
+ englishNameGetter.getNameFromBCP47(language)
+ englishNameGetter.getNameFromIdentifier(language)
+ "\t"
+ symbol);
// TODO add script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void main(String[] args) {
+ "\t"
+ level
+ "\t"
+ config.getEnglish().nameGetter().getNameFromBCP47(langCode));
+ config.getEnglish().nameGetter().getNameFromIdentifier(langCode));
}
for (String langCode : map.keySet()) {
String path = NameType.LANGUAGE.getKeyPath(langCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void main(String[] args) {
}

public static String langAndName(CLDRFile english, String base) {
return base + "\t" + english.nameGetter().getNameFromBCP47(base);
return base + "\t" + english.nameGetter().getNameFromIdentifier(base);
}

public static String scriptAndName(CLDRFile english, String suppressScript) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static void main(String[] args) throws IOException, ParseException {

public static String getLanguageCodeAndName(String code) {
if (code == null) return null;
return englishNameGetter.getNameFromBCP47(code) + " [" + code + "]";
return englishNameGetter.getNameFromIdentifier(code) + " [" + code + "]";
}

private static String getReplacement(String oldDefault, Set<String> defaultLocaleContent) {
Expand Down Expand Up @@ -384,7 +384,8 @@ private static void writeNewBasicData2(PrintWriter out, Set<RowData> sortedInput
"changing <languageData>",
languageSubtag
+ "\t"
+ englishNameGetter.getNameFromBCP47(languageSubtag),
+ englishNameGetter.getNameFromIdentifier(
languageSubtag),
problem));
}
}
Expand Down Expand Up @@ -991,7 +992,8 @@ public String getLanguageCode() {

public String getLanguageName() {
String cldrResult =
getExcelQuote(englishNameGetter.getNameFromBCP47Bool(languageCode, true));
getExcelQuote(
englishNameGetter.getNameFromIndentifierCompoundOnly(languageCode));
// String result = getLanguageName2();
// if (!result.equalsIgnoreCase(cldrResult)) {
// if (null == oldToFixed.put(result, cldrResult)) {
Expand Down Expand Up @@ -2559,7 +2561,7 @@ private static String fixCountryCode(String countryCode, List<String> row) {
}

private static String getULocaleLocaleName(String languageCode) {
return englishNameGetter.getNameFromBCP47Bool(languageCode, true);
return englishNameGetter.getNameFromIndentifierCompoundOnly(languageCode);
// return new ULocale(languageCode).getDisplayName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ public static void showZoneInfo() throws IOException {
System.out.println(
locale
+ "\t"
+ nameGetter.getNameFromBCP47(locale)
+ nameGetter.getNameFromIdentifier(locale)
+ "\t"
+ onlyLocales.get(locale));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static void main(String[] args) {
+ "\t"
+ lang
+ "\t"
+ english.nameGetter().getNameFromBCP47(lang)
+ english.nameGetter().getNameFromIdentifier(lang)
+ "\t"
+ scripts
+ "\t"
Expand Down
Loading

0 comments on commit 3c96a98

Please sign in to comment.