From b926f52688603fbcfb1df082b2711850b3127007 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 29 Mar 2021 20:35:43 +0000 Subject: [PATCH] ICU-21550 Add zzzz to subdivision if len==2 See #1662 --- icu4c/source/common/locid.cpp | 7 +++++-- icu4c/source/test/intltest/loctest.cpp | 15 +++++++++++++++ .../core/src/com/ibm/icu/util/ULocale.java | 11 ++++++----- .../com/ibm/icu/dev/test/util/ULocaleTest.java | 14 ++++++++++++++ 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/icu4c/source/common/locid.cpp b/icu4c/source/common/locid.cpp index b79ba40ae7c..0d506293a99 100644 --- a/icu4c/source/common/locid.cpp +++ b/icu4c/source/common/locid.cpp @@ -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; } diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index f113eba6933..53d5721a98f 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -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"}, diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java b/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java index 6e0009e881f..84472f5b301 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/ULocale.java @@ -1402,11 +1402,12 @@ public final class ULocale implements Serializable, Comparable { 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); } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java index c2d8c0739c2..cbd7a4fcbb0 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java @@ -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"));