r110485 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110484‎ | r110485 | r110486 >
Date:15:37, 1 February 2012
Author:amire80
Status:resolved (Comments)
Tags:core 
Comment:
Fixed plural rules for Romanian / Moldovan according to CLDR. Added tests for Romanian and fixed tests for Moldovan.
Modified paths:
  • /trunk/phase3/languages/classes/LanguageMo.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageRo.php (modified) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageMoTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageRoTest.php (added) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/languages/LanguageRoTest.php
@@ -0,0 +1,43 @@
 2+<?php
 3+/**
 4+ * @author Amir E. Aharoni
 5+ * @copyright Copyright © 2012, Amir E. Aharoni
 6+ * @file
 7+ */
 8+
 9+/** Tests for MediaWiki languages/classes/LanguageRo.php */
 10+class LanguageRoTest extends MediaWikiTestCase {
 11+ private $lang;
 12+
 13+ function setUp() {
 14+ $this->lang = Language::factory( 'ro' );
 15+ }
 16+ function tearDown() {
 17+ unset( $this->lang );
 18+ }
 19+
 20+ /** @dataProvider providerPlural */
 21+ function testPlural( $result, $value ) {
 22+ $forms = array( 'one', 'few', 'other' );
 23+ $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 24+ }
 25+
 26+ function providerPlural() {
 27+ return array (
 28+ array( 'few', 0 ),
 29+ array( 'one', 1 ),
 30+ array( 'few', 2 ),
 31+ array( 'few', 19 ),
 32+ array( 'other', 20 ),
 33+ array( 'other', 99 ),
 34+ array( 'other', 100 ),
 35+ array( 'few', 101 ),
 36+ array( 'few', 119 ),
 37+ array( 'other', 120 ),
 38+ array( 'other', 200 ),
 39+ array( 'few', 201 ),
 40+ array( 'few', 219 ),
 41+ array( 'other', 220 ),
 42+ );
 43+ }
 44+}
Property changes on: trunk/phase3/tests/phpunit/languages/LanguageRoTest.php
___________________________________________________________________
Added: svn:eol-style
145 + native
Index: trunk/phase3/tests/phpunit/languages/LanguageMoTest.php
@@ -22,22 +22,22 @@
2323 $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
2424 }
2525
26 -
2726 function providerPlural() {
2827 return array (
29 - array( 'few', 0 ),
30 - array( 'one', 1 ),
31 - array( 'few', 2 ),
32 - array( 'few', 3 ),
33 - array( 'few', 19 ),
34 - array( 'few', 119 ),
 28+ array( 'few', 0 ),
 29+ array( 'one', 1 ),
 30+ array( 'few', 2 ),
 31+ array( 'few', 19 ),
3532 array( 'other', 20 ),
36 - array( 'other', 20.123 ),
37 - array( 'other', 31 ),
 33+ array( 'other', 99 ),
 34+ array( 'other', 100 ),
 35+ array( 'few', 101 ),
 36+ array( 'few', 119 ),
 37+ array( 'other', 120 ),
3838 array( 'other', 200 ),
39 - array( 'few', 201 ),
 39+ array( 'few', 201 ),
 40+ array( 'few', 219 ),
 41+ array( 'other', 220 ),
4042 );
4143 }
42 -
43 -
4444 }
Index: trunk/phase3/languages/classes/LanguageMo.php
@@ -14,13 +14,14 @@
1515 function convertPlural( $count, $forms ) {
1616 // Plural rules per
1717 // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#mo
 18+ // Identical to Romanian (ro).
1819 if ( !count( $forms ) ) { return ''; }
1920
2021 $forms = $this->preConvertPlural( $forms, 3 );
2122
22 - if ( $count == 1 ) {
 23+ if ( $count === 1 ) {
2324 $index = 0;
24 - } elseif ( $count == 0 || ( $count % 100 > 0 && $count % 100 < 20 ) ) {
 25+ } elseif ( $count === 0 || ( $count % 100 > 0 && $count % 100 < 20 ) ) {
2526 $index = 1;
2627 } else {
2728 $index = 2;
Index: trunk/phase3/languages/classes/LanguageRo.php
@@ -18,9 +18,9 @@
1919
2020 $forms = $this->preConvertPlural( $forms, 3 );
2121
22 - if ( $count == 1 ) {
 22+ if ( $count === 1 ) {
2323 $index = 0;
24 - } elseif ( $count == 0 || $count % 100 < 20 ) {
 24+ } elseif ( $count === 0 || ( $count % 100 > 0 && $count % 100 < 20 ) ) {
2525 $index = 1;
2626 } else {
2727 $index = 2;

Follow-up revisions

RevisionCommit summaryAuthorDate
r110572== comparison for all languages, instead of ===, according to Niklas' suggest...amire8014:42, 2 February 2012

Comments

#Comment by Nikerabbit (talk | contribs)   11:40, 2 February 2012

Here too, === might break things.

#Comment by Amire80 (talk | contribs)   14:44, 2 February 2012

Should be addressed in r110572.

Status & tagging log