-
Notifications
You must be signed in to change notification settings - Fork 424
CLDR-17014 No code fallbacks for language/script paths #4290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package org.unicode.cldr.util; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
|
|
||
| public class ExtraPaths { | ||
|
|
||
| private static final Map<NameType, ExtraPaths> instances = new HashMap<>(); | ||
|
|
||
| public static ExtraPaths getInstance(NameType nameType) { | ||
| return instances.computeIfAbsent(nameType, ExtraPaths::new); | ||
| } | ||
|
|
||
| private final NameType nameType; | ||
| private final Collection<String> paths; | ||
|
|
||
| private ExtraPaths(NameType nameType) { | ||
| this.nameType = nameType; | ||
| paths = new HashSet<>(); | ||
| } | ||
|
|
||
| void append(Collection<String> toAddTo) { | ||
| if (paths.isEmpty()) { | ||
| populatePaths(); | ||
| } | ||
| toAddTo.addAll(paths); | ||
| } | ||
|
|
||
| private void populatePaths() { | ||
| // TODO: https://unicode-org.atlassian.net/browse/CLDR-17014 | ||
| // StandardCodes.CodeType codeType = StandardCodes.CodeType.fromNameType(nameType); | ||
| // See https://github.com/unicode-org/cldr/pull/4287 | ||
| StandardCodes.CodeType codeType; | ||
| switch (nameType) { | ||
| case LANGUAGE: | ||
| codeType = StandardCodes.CodeType.language; | ||
| break; | ||
| case SCRIPT: | ||
| codeType = StandardCodes.CodeType.script; | ||
| break; | ||
| default: | ||
| throw new IllegalArgumentException("TODO: CodeType.fromNameType"); | ||
| } | ||
| StandardCodes sc = StandardCodes.make(); | ||
| Set<String> codes = new TreeSet<>(sc.getGoodAvailableCodes(codeType)); | ||
| adjustCodeSet(codes); | ||
| for (String code : codes) { | ||
| paths.add(nameType.getKeyPath(code)); | ||
| } | ||
| addAltPaths(); | ||
| } | ||
|
|
||
| private void adjustCodeSet(Set<String> codes) { | ||
| if (nameType == NameType.LANGUAGE) { | ||
| codes.remove(LocaleNames.ROOT); | ||
| codes.addAll( | ||
| List.of( | ||
| "ar_001", "de_AT", "de_CH", "en_AU", "en_CA", "en_GB", "en_US", | ||
| "es_419", "es_ES", "es_MX", "fa_AF", "fr_CA", "fr_CH", "frc", "hi_Latn", | ||
| "lou", "nds_NL", "nl_BE", "pt_BR", "pt_PT", "ro_MD", "sw_CD", "zh_Hans", | ||
| "zh_Hant")); | ||
| } | ||
| } | ||
|
|
||
| private void addAltPaths() { | ||
| switch (nameType) { | ||
| case LANGUAGE: | ||
| addAltPath("en_GB", "short"); | ||
| addAltPath("en_US", "short"); | ||
| addAltPath("az", "short"); | ||
| addAltPath("ckb", "menu"); | ||
| addAltPath("ckb", "variant"); | ||
| addAltPath("hi_Latn", "variant"); | ||
| addAltPath("yue", "menu"); | ||
| addAltPath("zh", "menu"); | ||
| addAltPath("zh_Hans", "long"); | ||
| addAltPath("zh_Hant", "long"); | ||
| break; | ||
| case SCRIPT: | ||
| addAltPath("Hans", "stand-alone"); | ||
| addAltPath("Hant", "stand-alone"); | ||
| } | ||
| } | ||
|
|
||
| private void addAltPath(String code, String alt) { | ||
| String fullpath = nameType.getKeyPath(code); | ||
| // Insert the @alt= string after the last occurrence of "]" | ||
| StringBuilder fullpathBuf = new StringBuilder(fullpath); | ||
| String altPath = | ||
| fullpathBuf | ||
| .insert(fullpathBuf.lastIndexOf("]") + 1, "[@alt=\"" + alt + "\"]") | ||
| .toString(); | ||
| paths.add(altPath); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,9 @@ | |
| path.contains("/metazone") | ||
| || path.contains("/timeZoneNames") | ||
| || path.contains("/gender") | ||
| || path.startsWith( | ||
| "//ldml/localeDisplayNames/languages/language") | ||
| || path.startsWith("//ldml/localeDisplayNames/scripts/script") | ||
| || path.startsWith("//ldml/numbers/currencies/currency") | ||
| || path.startsWith("//ldml/personNames/sampleName") | ||
| || path.contains("/availableFormats") | ||
|
|
@@ -914,7 +917,7 @@ | |
| } | ||
| String value = swissHighGerman.getStringValue(xpath); | ||
| if (value != null && value.indexOf('ß') >= 0) { | ||
| warnln("«" + value + "» contains ß at " + xpath); | ||
|
Check warning on line 920 in tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestCLDRFile.java
|
||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these two tables in code instead of in data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be, but best to be in a different ticket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving to a data file is an interesting idea. This ticket moves the code from XMLSource.java to ExtraPaths.java, and so far only for language/script paths. There's still a lot of code for other kinds of extra paths in CLDRFile.java, and for other kinds of "constructed" paths (like currencies) in XMLSource.java. A plan to move such code to a data file should probably take into account not only the code here but also what remains in CLDRFile and XMLSource. Not all of those paths in CLDRFile currently have corresponding NameType values; dayPeriods paths for example don't. All those in XMLSource do have corresponding NameType values. Even if we keep the fallback values for currencies, etc., we might consider taking them out of XMLSource.java and treating them more like extra paths. There could be more of a comprehensive framework rather than scattered code/data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like perhaps it's a coverage level issue or something. Not sure.