ICU-8806 fix MessageFormat plural # formatting: fix offset lookup

X-SVN-Rev: 30634
This commit is contained in:
Markus Scherer 2011-09-07 23:02:21 +00:00
parent 27b6a943bc
commit 49407c6a1e
2 changed files with 15 additions and 10 deletions

View 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());

View 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.