Add support for plural rules for decimal numbers
authorSanthosh Thottingal <santhosh.thottingal@gmail.com>
Sat, 15 Sep 2012 03:20:04 +0000 (20:20 -0700)
committerSanthosh Thottingal <santhosh.thottingal@gmail.com>
Sun, 16 Sep 2012 18:36:19 +0000 (11:36 -0700)
* Update CLDRPluralRuleParser from upstream
* Use parseFloat instead of parseInt in mediawiki.jqueryMsg
* Add qunit tests

Change-Id: I0b44df6c9e299142925a557f6dc41d749d381a02

resources/mediawiki.libs/CLDRPluralRuleParser.js
resources/mediawiki/mediawiki.jqueryMsg.js
tests/qunit/suites/resources/mediawiki/mediawiki.cldr.test.js

index bb1491d..91bdc07 100644 (file)
@@ -275,7 +275,15 @@ function pluralRuleParser(rule, number) {
 
        var condition = choice([and, or, relation]);
 
+       function isInt(n) {
+               return parseFloat(n) % 1 === 0;
+       }
+
+
        function start() {
+               if (!isInt(number)) {
+                       return false;
+               }
                var result = condition();
                return result;
        }
index def1225..86af31f 100644 (file)
                 * @return {String} selected pluralized form according to current language
                 */
                plural: function ( nodes ) {
-                       var count = parseInt( this.language.convertNumber( nodes[0], true ), 10 );
+                       var count = parseFloat( this.language.convertNumber( nodes[0], true ) );
                        var forms = nodes.slice(1);
                        return forms.length ? this.language.convertPlural( count, forms ) : '';
                },
index 895a735..e2c6668 100644 (file)
@@ -50,9 +50,8 @@ var pluralTestcases = {
                [ 9999, [ "zero", "one", "two", "few", "many", "other" ], "many", "Arabic plural test - 9999 is many" ],
                [ 100, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 100 is other" ],
                [ 102, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 102 is other" ],
-               [ 1000, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 1000 is other" ]
-               // FIXME plural rules for decimal numbers does not work
-               // [ 1.7, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 1.7 is other" ],
+               [ 1000, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 1000 is other" ],
+               [ 1.7, [ "zero", "one", "two", "few", "many", "other" ], "other", "Arabic plural test - 1.7 is other" ]
        ]
 };