Fixed plural rules for Romanian / Moldovan according to CLDR. Added tests for Romania...
authorAmir E. Aharoni <amire80@users.mediawiki.org>
Wed, 1 Feb 2012 15:37:40 +0000 (15:37 +0000)
committerAmir E. Aharoni <amire80@users.mediawiki.org>
Wed, 1 Feb 2012 15:37:40 +0000 (15:37 +0000)
languages/classes/LanguageMo.php
languages/classes/LanguageRo.php
tests/phpunit/languages/LanguageMoTest.php
tests/phpunit/languages/LanguageRoTest.php [new file with mode: 0644]

index a973a7a..3410729 100644 (file)
@@ -14,13 +14,14 @@ class LanguageMo extends Language {
        function convertPlural( $count, $forms ) {
                // Plural rules per
                // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#mo
+               // Identical to Romanian (ro).
                if ( !count( $forms ) ) { return ''; }
 
                $forms = $this->preConvertPlural( $forms, 3 );
 
-               if ( $count == 1 ) {
+               if ( $count === 1 ) {
                        $index = 0;
-               } elseif ( $count == 0 || ( $count % 100 > 0 && $count % 100 < 20 ) ) {
+               } elseif ( $count === 0 || ( $count % 100 > 0 && $count % 100 < 20 ) ) {
                        $index = 1;
                } else {
                        $index = 2;
index 9cfd8b5..ea156c2 100644 (file)
@@ -18,9 +18,9 @@ class LanguageRo extends Language {
 
                $forms = $this->preConvertPlural( $forms, 3 );
 
-               if ( $count == 1 ) {
+               if ( $count === 1 ) {
                        $index = 0;
-               } elseif ( $count == 0 || $count % 100 < 20 ) {
+               } elseif ( $count === 0 || ( $count % 100 > 0 && $count % 100 < 20 ) ) {
                        $index = 1;
                } else {
                        $index = 2;
index 48940a5..533e590 100644 (file)
@@ -22,22 +22,22 @@ class LanguageMoTest extends MediaWikiTestCase {
                $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
        }
 
-
        function providerPlural() {
                return array (
-                       array( 'few', 0 ),
-                       array( 'one', 1 ),
-                       array( 'few', 2 ),
-                       array( 'few', 3 ),
-                       array( 'few', 19 ),
-                       array( 'few', 119 ),
+                       array( 'few',   0 ),
+                       array( 'one',   1 ),
+                       array( 'few',   2 ),
+                       array( 'few',   19 ),
                        array( 'other', 20 ),
-                       array( 'other', 20.123 ),
-                       array( 'other', 31 ),
+                       array( 'other', 99 ),
+                       array( 'other', 100 ),
+                       array( 'few',   101 ),
+                       array( 'few',   119 ),
+                       array( 'other', 120 ),
                        array( 'other', 200 ),
-                       array( 'few', 201 ),
+                       array( 'few',   201 ),
+                       array( 'few',   219 ),
+                       array( 'other', 220 ),
                );
        }
-
-
 }
diff --git a/tests/phpunit/languages/LanguageRoTest.php b/tests/phpunit/languages/LanguageRoTest.php
new file mode 100644 (file)
index 0000000..5270f6f
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * @author Amir E. Aharoni
+ * @copyright Copyright © 2012, Amir E. Aharoni
+ * @file
+ */
+
+/** Tests for MediaWiki languages/classes/LanguageRo.php */
+class LanguageRoTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->lang = Language::factory( 'ro' );
+       }
+       function tearDown() {
+               unset( $this->lang );
+       }
+
+       /** @dataProvider providerPlural */
+       function testPlural( $result, $value ) {
+               $forms =  array( 'one', 'few', 'other' );
+               $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
+       }
+
+       function providerPlural() {
+               return array (
+                       array( 'few',   0 ),
+                       array( 'one',   1 ),
+                       array( 'few',   2 ),
+                       array( 'few',   19 ),
+                       array( 'other', 20 ),
+                       array( 'other', 99 ),
+                       array( 'other', 100 ),
+                       array( 'few',   101 ),
+                       array( 'few',   119 ),
+                       array( 'other', 120 ),
+                       array( 'other', 200 ),
+                       array( 'few',   201 ),
+                       array( 'few',   219 ),
+                       array( 'other', 220 ),
+               );
+       }
+}