From: Amir E. Aharoni Date: Wed, 1 Feb 2012 15:37:40 +0000 (+0000) Subject: Fixed plural rules for Romanian / Moldovan according to CLDR. Added tests for Romania... X-Git-Tag: 1.31.0-rc.0~24980 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=655dbec995d4ed5ed3349f4e312260f3a2579182;p=lhc%2Fweb%2Fwiklou.git Fixed plural rules for Romanian / Moldovan according to CLDR. Added tests for Romanian and fixed tests for Moldovan. --- diff --git a/languages/classes/LanguageMo.php b/languages/classes/LanguageMo.php index a973a7ab35..3410729f89 100644 --- a/languages/classes/LanguageMo.php +++ b/languages/classes/LanguageMo.php @@ -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; diff --git a/languages/classes/LanguageRo.php b/languages/classes/LanguageRo.php index 9cfd8b572f..ea156c2749 100644 --- a/languages/classes/LanguageRo.php +++ b/languages/classes/LanguageRo.php @@ -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; diff --git a/tests/phpunit/languages/LanguageMoTest.php b/tests/phpunit/languages/LanguageMoTest.php index 48940a5dc6..533e590fab 100644 --- a/tests/phpunit/languages/LanguageMoTest.php +++ b/tests/phpunit/languages/LanguageMoTest.php @@ -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 index 0000000000..5270f6fee5 --- /dev/null +++ b/tests/phpunit/languages/LanguageRoTest.php @@ -0,0 +1,43 @@ +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 ), + ); + } +}