]> granicus.if.org Git - icu/commitdiff
ICU-8806 fix MessageFormat plural # formatting: fix offset lookup
authorMarkus Scherer <markus.icu@gmail.com>
Wed, 7 Sep 2011 23:02:21 +0000 (23:02 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Wed, 7 Sep 2011 23:02:21 +0000 (23:02 +0000)
X-SVN-Rev: 30634

icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java

index ba6d42dbf9cc33ba0a4dbdd73e6544c69fabd469..e5e56f26733208725aacfd6f38adab44ed3f8d66 100644 (file)
@@ -1706,7 +1706,7 @@ public class MessageFormat extends UFormat {
                     pluralProvider = new PluralSelectorProvider(ulocale);
                 }
                 int subMsgStart=PluralFormat.findSubMessage(msgPattern, i, pluralProvider, number);
-                double offset=msgPattern.getPluralOffset(subMsgStart);
+                double offset=msgPattern.getPluralOffset(i);
                 formatComplexSubMessage(subMsgStart, number-offset, args, argsMap, dest);
             } else if(argType==ArgType.SELECT) {
                 int subMsgStart=SelectFormat.findSubMessage(msgPattern, i, arg.toString());
index 7f41c8467ef33bd4508275c7cc9680b9e7736aac..d08f239f53f69242c9fb7af9e9a7e6f9758a6c89 100644 (file)
@@ -284,17 +284,22 @@ public class PluralFormatUnitTest extends TestFmwk {
             "There is a bling widget and 5 other widgets.",
             "There is a bling widget and 6 other widgets.",
         };
-        PluralFormat pf = new PluralFormat(
-                ULocale.ENGLISH,
-                "offset:1.0 "
-                + "=0 {There are no widgets.} "
-                + "=1.0 {There is one widget.} "
-                + "=5 {Widgets, five (5-1=#) there be.} "
-                + "one {There is a bling widget and one other widget.} "
-                + "other {There is a bling widget and # other widgets.}");
+        String pluralStyle =
+            "offset:1.0 "
+            + "=0 {There are no widgets.} "
+            + "=1.0 {There is one widget.} "
+            + "=5 {Widgets, five (5-1=#) there be.} "
+            + "one {There is a bling widget and one other widget.} "
+            + "other {There is a bling widget and # other widgets.}";
+        PluralFormat pf = new PluralFormat(ULocale.ENGLISH, pluralStyle);
+        MessageFormat mf = new MessageFormat("{0,plural," + pluralStyle + "}", ULocale.ENGLISH);
+        Integer args[] = new Integer[1];
         for (int i = 0; i < 7; ++i) {
             String result = pf.format(i);
-            assertEquals("value = " + i, targets[i], result);
+            assertEquals("PluralFormat.format(value " + i + ")", targets[i], result);
+            args[0] = i;
+            result = mf.format(args);
+            assertEquals("MessageFormat.format(value " + i + ")", targets[i], result);
         }
 
         // Try explicit values after keywords.