]> granicus.if.org Git - icu/commitdiff
ICU-20280 PluralRules::forLocale() ignore locale extensions
authorMarkus Scherer <markus.icu@gmail.com>
Thu, 21 Feb 2019 18:39:20 +0000 (10:39 -0800)
committerMarkus Scherer <markus.icu@gmail.com>
Thu, 21 Feb 2019 19:32:05 +0000 (11:32 -0800)
icu4c/source/i18n/plurrule.cpp
icu4c/source/test/intltest/plurults.cpp
icu4c/source/test/intltest/plurults.h
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralRulesTest.java

index e82c02cb592c417dd9bb931cc521a67f2394a60d..fd1935607081728f99fc9ee17cc34e60c2ae6554 100644 (file)
@@ -703,14 +703,14 @@ PluralRules::getRuleFromResource(const Locale& locale, UPluralType type, UErrorC
         return emptyStr;
     }
     int32_t resLen=0;
-    const char *curLocaleName=locale.getName();
+    const char *curLocaleName=locale.getBaseName();
     const UChar* s = ures_getStringByKey(locRes.getAlias(), curLocaleName, &resLen, &errCode);
 
     if (s == nullptr) {
         // Check parent locales.
         UErrorCode status = U_ZERO_ERROR;
         char parentLocaleName[ULOC_FULLNAME_CAPACITY];
-        const char *curLocaleName2=locale.getName();
+        const char *curLocaleName2=locale.getBaseName();
         uprv_strcpy(parentLocaleName, curLocaleName2);
 
         while (uloc_getParent(parentLocaleName, parentLocaleName,
index 0d59a5a6703a9a813eed70acbb8c42b94b4fd0d3..1afb9c445f3c1a9926f51e8f70135489799bf935 100644 (file)
@@ -55,6 +55,7 @@ void PluralRulesTest::runIndexedTest( int32_t index, UBool exec, const char* &na
     TESTCASE_AUTO(testParseErrors);
     TESTCASE_AUTO(testFixedDecimal);
     TESTCASE_AUTO(testSelectTrailingZeros);
+    TESTCASE_AUTO(testLocaleExtension);
     TESTCASE_AUTO_END;
 }
 
@@ -1036,6 +1037,12 @@ void PluralRulesTest::testSelectTrailingZeros() {
     }
 }
 
-
+void PluralRulesTest::testLocaleExtension() {
+    IcuTestErrorCode errorCode(*this, "testLocaleExtension");
+    LocalPointer<PluralRules> rules(PluralRules::forLocale("pt@calendar=gregorian", errorCode));
+    if (errorCode.errIfFailureAndReset("PluralRules::forLocale()")) { return; }
+    UnicodeString key = rules->select(1);
+    assertEquals("pt@calendar=gregorian select(1)", u"one", key);
+}
 
 #endif /* #if !UCONFIG_NO_FORMATTING */
index e4e2497ec69706a4888fe79f8bea0d55c45a570f..91df27b763889caf10b43482cb7232618c55ff82 100644 (file)
@@ -38,6 +38,7 @@ private:
     void testParseErrors();
     void testFixedDecimal();
     void testSelectTrailingZeros();
+    void testLocaleExtension();
 
     void assertRuleValue(const UnicodeString& rule, double expected);
     void assertRuleKeyValue(const UnicodeString& rule, const UnicodeString& key,
index c23b8a3cd3545586132966026690b3e43abd6d6b..256fcd28b177b3779da49130f4be32b08bda25a8 100644 (file)
@@ -526,6 +526,13 @@ public class PluralRulesTest extends TestFmwk {
         }
     }
 
+    @Test
+    public void testLocaleExtension() {
+        PluralRules rules = PluralRules.forLocale(new ULocale("pt@calendar=gregorian"));
+        String key = rules.select(1);
+        assertEquals("pt@calendar=gregorian select(1)", "one", key);
+    }
+
     @Test
     public void testFunctionalEquivalent() {
         // spot check