ICU-21550 Add zzzz to subdivision if len==2

See #1662
This commit is contained in:
Frank Tang 2021-03-29 20:35:43 +00:00 committed by Shane F. Carr
parent 866a640b70
commit b926f52688
4 changed files with 40 additions and 7 deletions

View file

@ -1519,9 +1519,12 @@ AliasReplacer::replaceSubdivision(
// Found replacement data for this subdivision.
size_t len = (firstSpace != nullptr) ?
(firstSpace - replacement) : uprv_strlen(replacement);
// Ignore len == 2, see CLDR-14312
if (3 <= len && len <= 8) {
if (2 <= len && len <= 8) {
output.append(replacement, (int32_t)len, status);
if (2 == len) {
// Add 'zzzz' based on changes to UTS #35 for CLDR-14312.
output.append("zzzz", 4, status);
}
}
return true;
}

View file

@ -4938,6 +4938,21 @@ void LocaleTest::TestCanonicalize(void)
{ "und-FR-u-sd-frg", "und-FR-u-sd-frges"},
{ "und-LU-u-sd-lud", "und-LU-u-sd-lucl"},
// ICU-21550
{ "und-u-rg-fi01", "und-u-rg-axzzzz"},
{ "und-u-rg-frcp", "und-u-rg-cpzzzz"},
{ "und-u-rg-frpm", "und-u-rg-pmzzzz"},
{ "und-u-rg-usvi", "und-u-rg-vizzzz"},
{ "und-u-rg-cn91", "und-u-rg-hkzzzz"},
{ "und-u-rg-nlaw", "und-u-rg-awzzzz"},
{ "und-NO-u-sd-frre", "und-NO-u-sd-rezzzz"},
{ "und-CN-u-sd-nlcw", "und-CN-u-sd-cwzzzz"},
{ "und-CZ-u-sd-usgu", "und-CZ-u-sd-guzzzz"},
{ "und-FR-u-sd-shta", "und-FR-u-sd-tazzzz"},
{ "und-FR-u-sd-cn71", "und-FR-u-sd-twzzzz"},
// ICU-21401
{ "cel-gaulish", "xtg"},

View file

@ -1402,11 +1402,12 @@ public final class ULocale implements Serializable, Comparable<ULocale> {
throw new IllegalArgumentException(
"Incorrect key [" + aliasFrom + "] in alias:territory.");
}
if (aliasTo.length() < 3 || aliasTo.length() > 8) {
// Ignore replacement < 3 for now. see CLDR-14312
// throw new IllegalArgumentException(
// "Incorrect value [" + aliasTo + "] in alias:subdivision.");
continue;
if (aliasTo.length() == 2) {
// Add 'zzzz' based on changes to UTS #35 for CLDR-14312.
aliasTo += "zzzz";
} else if (aliasTo.length() < 2 || aliasTo.length() > 8) {
throw new IllegalArgumentException(
"Incorrect value [" + aliasTo + "] in alias:territory.");
}
subdivisionAliasMap.put(aliasFrom, aliasTo);
}

View file

@ -5250,6 +5250,20 @@ public class ULocaleTest extends TestFmwk {
Assert.assertEquals("und-FR-u-sd-frges", canonicalTag("und-FR-u-sd-frg"));
Assert.assertEquals("und-LU-u-sd-lucl", canonicalTag("und-LU-u-sd-lud"));
// ICU-21550
Assert.assertEquals("und-u-rg-axzzzz", canonicalTag("und-u-rg-fi01"));
Assert.assertEquals("und-u-rg-cpzzzz", canonicalTag("und-u-rg-frcp"));
Assert.assertEquals("und-u-rg-pmzzzz", canonicalTag("und-u-rg-frpm"));
Assert.assertEquals("und-u-rg-vizzzz", canonicalTag("und-u-rg-usvi"));
Assert.assertEquals("und-u-rg-hkzzzz", canonicalTag("und-u-rg-cn91"));
Assert.assertEquals("und-u-rg-awzzzz", canonicalTag("und-u-rg-nlaw"));
Assert.assertEquals("und-NO-u-sd-rezzzz", canonicalTag("und-NO-u-sd-frre"));
Assert.assertEquals("und-CN-u-sd-cwzzzz", canonicalTag("und-CN-u-sd-nlcw"));
Assert.assertEquals("und-CZ-u-sd-guzzzz", canonicalTag("und-CZ-u-sd-usgu"));
Assert.assertEquals("und-FR-u-sd-tazzzz", canonicalTag("und-FR-u-sd-shta"));
Assert.assertEquals("und-FR-u-sd-twzzzz", canonicalTag("und-FR-u-sd-cn71"));
// ICU-21401
Assert.assertEquals("xtg", canonicalTag("cel-gaulish"));