Fixes the GWT plural rule for the Polish language. The old class defined: "one" == 1. "paucal" == numbers ending in 2-4 except 12-14 and 22-24. "other" == all other integers. The correct definitions are: "one" == 1 "few" == numbers ending in 2-4 except 12-14. "many" == all other integers. "other" == fractional values. Review at http://gwt-code-reviews.appspot.com/1874804 git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11422 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/i18n/client/impl/plurals/DefaultRule_1_paucal_n.java b/user/src/com/google/gwt/i18n/client/impl/plurals/DefaultRule_1_paucal_n.java index 7f43656..8bb77b7 100644 --- a/user/src/com/google/gwt/i18n/client/impl/plurals/DefaultRule_1_paucal_n.java +++ b/user/src/com/google/gwt/i18n/client/impl/plurals/DefaultRule_1_paucal_n.java
@@ -19,8 +19,13 @@ import com.google.gwt.i18n.client.PluralRule.PluralForm; /** - * Common plural rule for languages that have 1, few, and other forms. - * + * Common plural rule for languages that have singular, two plural forms + * (based on the units and tens digits) and a fractional form ("other"). + * + * Polish is the only language that uses this plural rule. + * + * Note: Perhaps this class should have been named: DefaultRule_1_x234_n + * * @see DefaultRule_0_1_2_n * @see DefaultRule_0_1_n * @see DefaultRule_01_n @@ -35,16 +40,18 @@ return new PluralForm[] { new PluralForm("other", "Default plural form"), new PluralForm("one", "Count is 1"), - new PluralForm("paucal", "Count ends in 2-4 but not 12-14 or 22-24"), + new PluralForm("few", "Count ends in 2-4 but not 12-14"), + new PluralForm("many", "Count is not 1 and does not end in 2-4 except 12-14"), }; } public static int select(int n) { /* - * For Polish, numbers that end in 2-4, except 12-14 and 22-24, have a special plural form. + * This method will only return a 1, 2, or 3 ("one", "few", or "many"). + * This method will never return 0 because "other" is the fractional form. */ return n == 1 ? 1 - : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 > 29) ? 2 - : 0; + : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 > 20) ? 2 + : 3; } }
diff --git a/user/test/com/google/gwt/i18n/I18NSuite.java b/user/test/com/google/gwt/i18n/I18NSuite.java index 9906f51..dc1864b 100644 --- a/user/test/com/google/gwt/i18n/I18NSuite.java +++ b/user/test/com/google/gwt/i18n/I18NSuite.java
@@ -43,6 +43,7 @@ import com.google.gwt.i18n.client.NumberFormat_fr_Test; import com.google.gwt.i18n.client.NumberParse_en_Test; import com.google.gwt.i18n.client.NumberParse_fr_Test; +import com.google.gwt.i18n.client.PolishPluralsTest; import com.google.gwt.i18n.client.RuntimeLocalesTest; import com.google.gwt.i18n.client.TimeZoneInfoTest; import com.google.gwt.i18n.client.TimeZoneTest; @@ -110,6 +111,7 @@ suite.addTestSuite(NumberFormat_fr_Test.class); suite.addTestSuite(NumberParse_en_Test.class); suite.addTestSuite(NumberParse_fr_Test.class); + suite.addTestSuite(PolishPluralsTest.class); suite.addTestSuite(PropertyCatalogFactoryTest.class); suite.addTestSuite(ReflectionMessageInterfaceTest.class); suite.addTestSuite(RegionInheritanceTest.class);
diff --git a/user/test/com/google/gwt/i18n/client/PolishPluralsTest.java b/user/test/com/google/gwt/i18n/client/PolishPluralsTest.java new file mode 100644 index 0000000..df9e59b --- /dev/null +++ b/user/test/com/google/gwt/i18n/client/PolishPluralsTest.java
@@ -0,0 +1,70 @@ +/* + * Copyright 2012 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.i18n.client; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.junit.client.GWTTestCase; + +/** + * Tests Polish plurals, which is one of the most complicated. + */ +public class PolishPluralsTest extends GWTTestCase { + + /** + * Shorter message for just testing that Polish plurals work properly. + */ + public interface PluralMessage extends Messages { + @DefaultMessage("{0} widgets-few") + @AlternateMessage({"one", "A widget"}) + String pluralWidgetsOther(@PluralCount int count); + } + + @Override + public String getModuleName() { + return "com.google.gwt.i18n.I18NTest_pl"; + } + + public void testPlurals() { + // Note that all text is actually in English, but written according to + // Polish plural rules. + PluralMessage m = GWT.create(PluralMessage.class); + assertEquals("(Polish many) 0 widgets", m.pluralWidgetsOther(0)); + assertEquals("(Polish one) A widget", m.pluralWidgetsOther(1)); + assertEquals("(Polish few) 2 widgets", m.pluralWidgetsOther(2)); + assertEquals("(Polish few) 3 widgets", m.pluralWidgetsOther(3)); + assertEquals("(Polish few) 4 widgets", m.pluralWidgetsOther(4)); + assertEquals("(Polish many) 5 widgets", m.pluralWidgetsOther(5)); + assertEquals("(Polish many) 10 widgets", m.pluralWidgetsOther(10)); + assertEquals("(Polish many) 11 widgets", m.pluralWidgetsOther(11)); + assertEquals("(Polish many) 12 widgets", m.pluralWidgetsOther(12)); + assertEquals("(Polish many) 13 widgets", m.pluralWidgetsOther(13)); + assertEquals("(Polish many) 14 widgets", m.pluralWidgetsOther(14)); + assertEquals("(Polish many) 15 widgets", m.pluralWidgetsOther(15)); + assertEquals("(Polish many) 20 widgets", m.pluralWidgetsOther(20)); + assertEquals("(Polish many) 21 widgets", m.pluralWidgetsOther(21)); + assertEquals("(Polish few) 22 widgets", m.pluralWidgetsOther(22)); + assertEquals("(Polish few) 23 widgets", m.pluralWidgetsOther(23)); + assertEquals("(Polish few) 24 widgets", m.pluralWidgetsOther(24)); + assertEquals("(Polish many) 25 widgets", m.pluralWidgetsOther(25)); + assertEquals("(Polish many) 99 widgets", m.pluralWidgetsOther(99)); + assertEquals("(Polish many) 100 widgets", m.pluralWidgetsOther(100)); + assertEquals("(Polish many) 101 widgets", m.pluralWidgetsOther(101)); + assertEquals("(Polish few) 102 widgets", m.pluralWidgetsOther(102)); + assertEquals("(Polish few) 103 widgets", m.pluralWidgetsOther(103)); + assertEquals("(Polish few) 104 widgets", m.pluralWidgetsOther(104)); + assertEquals("(Polish many) 105 widgets", m.pluralWidgetsOther(105)); + } +}
diff --git a/user/test/com/google/gwt/i18n/client/PolishPluralsTest_PluralMessage_pl.properties b/user/test/com/google/gwt/i18n/client/PolishPluralsTest_PluralMessage_pl.properties new file mode 100644 index 0000000..ee22380 --- /dev/null +++ b/user/test/com/google/gwt/i18n/client/PolishPluralsTest_PluralMessage_pl.properties
@@ -0,0 +1,4 @@ +pluralWidgetsOther=(Polish other) {0} widgets +pluralWidgetsOther[one]=(Polish one) A widget +pluralWidgetsOther[few]=(Polish few) {0} widgets +pluralWidgetsOther[many]=(Polish many) {0} widgets