diff options
author | Elliott Hughes <enh@google.com> | 2013-04-16 15:23:58 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-04-16 15:23:58 -0700 |
commit | d4f2bbad3cf3b479e76f4913241e2d45010fbb60 (patch) | |
tree | 6a173b599c4450a815f3238f12def2a1bc3dcb43 /luni | |
parent | 3b6a95635bfedbd49d3a52cba2c26444685281a2 (diff) | |
download | libcore-d4f2bbad3cf3b479e76f4913241e2d45010fbb60.zip libcore-d4f2bbad3cf3b479e76f4913241e2d45010fbb60.tar.gz libcore-d4f2bbad3cf3b479e76f4913241e2d45010fbb60.tar.bz2 |
Fix Hebrew/Indonesian/Yiddish plural rules.
icu4c doesn't translate the deprecated language codes Java uses back into
the current language codes, so we need to do that ourselves.
Bug: 8619221
Change-Id: I241c33e10547d2858ac08e303d5f0327912a89ff
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/native/libcore_icu_NativePluralRules.cpp | 20 | ||||
-rw-r--r-- | luni/src/test/java/libcore/icu/NativePluralRulesTest.java | 9 |
2 files changed, 27 insertions, 2 deletions
diff --git a/luni/src/main/native/libcore_icu_NativePluralRules.cpp b/luni/src/main/native/libcore_icu_NativePluralRules.cpp index 3253eb8..571ba6d 100644 --- a/luni/src/main/native/libcore_icu_NativePluralRules.cpp +++ b/luni/src/main/native/libcore_icu_NativePluralRules.cpp @@ -23,6 +23,8 @@ #include "ScopedUtfChars.h" #include "unicode/plurrule.h" +#include <string> + static PluralRules* toPluralRules(jint address) { return reinterpret_cast<PluralRules*>(static_cast<uintptr_t>(address)); } @@ -31,8 +33,22 @@ static void NativePluralRules_finalizeImpl(JNIEnv*, jclass, jint address) { delete toPluralRules(address); } -static jint NativePluralRules_forLocaleImpl(JNIEnv* env, jclass, jstring localeName) { - Locale locale = Locale::createFromName(ScopedUtfChars(env, localeName).c_str()); +static jint NativePluralRules_forLocaleImpl(JNIEnv* env, jclass, jstring javaLocaleName) { + // The icu4c PluralRules returns a "other: n" default rule for the deprecated locales Java uses. + // Work around this by translating back to the current language codes. + std::string localeName(ScopedUtfChars(env, javaLocaleName).c_str()); + if (localeName[0] == 'i' && localeName[1] == 'w') { + localeName[0] = 'h'; + localeName[1] = 'e'; + } else if (localeName[0] == 'i' && localeName[1] == 'n') { + localeName[0] = 'i'; + localeName[1] = 'd'; + } else if (localeName[0] == 'j' && localeName[1] == 'i') { + localeName[0] = 'y'; + localeName[1] = 'i'; + } + + Locale locale = Locale::createFromName(localeName.c_str()); UErrorCode status = U_ZERO_ERROR; PluralRules* result = PluralRules::forLocale(locale, status); maybeThrowIcuException(env, "PluralRules::forLocale", status); diff --git a/luni/src/test/java/libcore/icu/NativePluralRulesTest.java b/luni/src/test/java/libcore/icu/NativePluralRulesTest.java index ccc3ca6..73699ff 100644 --- a/luni/src/test/java/libcore/icu/NativePluralRulesTest.java +++ b/luni/src/test/java/libcore/icu/NativePluralRulesTest.java @@ -55,4 +55,13 @@ public class NativePluralRulesTest extends junit.framework.TestCase { assertEquals(NativePluralRules.FEW, npr.quantityForInt(103)); assertEquals(NativePluralRules.MANY, npr.quantityForInt(111)); } + + public void testHebrew() throws Exception { + // java.util.Locale will translate "he" to the deprecated "iw". + NativePluralRules he = NativePluralRules.forLocale(new Locale("he")); + assertEquals(NativePluralRules.ONE, he.quantityForInt(1)); + assertEquals(NativePluralRules.TWO, he.quantityForInt(2)); + assertEquals(NativePluralRules.OTHER, he.quantityForInt(3)); + assertEquals(NativePluralRules.MANY, he.quantityForInt(10)); + } } |