From: Santhosh Thottingal Date: Mon, 9 Jan 2012 12:46:53 +0000 (+0000) Subject: Cleanup the convertPLural method for Lithuanian(lt) X-Git-Tag: 1.31.0-rc.0~25404 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=266c6e85152469f73c97ccaac43bb80db4711f90;p=lhc%2Fweb%2Fwiklou.git Cleanup the convertPLural method for Lithuanian(lt) Add phpunit test cases. --- diff --git a/languages/classes/LanguageLt.php b/languages/classes/LanguageLt.php index 09cacae02b..9b4634266e 100644 --- a/languages/classes/LanguageLt.php +++ b/languages/classes/LanguageLt.php @@ -12,6 +12,7 @@ class LanguageLt extends Language { */ /** + * Lithuanian plural forms as per http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#lt * @param $count int * @param $forms array * @@ -19,13 +20,10 @@ class LanguageLt extends Language { */ function convertPlural( $count, $forms ) { if ( !count( $forms ) ) { return ''; } - - // if no number with word, then use $form[0] for singular and $form[1] for plural or zero - if ( count( $forms ) === 2 ) return $count == 1 ? $forms[0] : $forms[1]; - $forms = $this->preConvertPlural( $forms, 3 ); - + // Form[0] if n mod 10 is 1 and n mod 100 not in 11..19; if ( $count % 10 == 1 && $count % 100 != 11 ) return $forms[0]; + // Forms[1] if n mod 10 in 2..9 and n mod 100 not in 11..19; if ( $count % 10 >= 2 && ( $count % 100 < 10 || $count % 100 >= 20 ) ) return $forms[1]; return $forms[2]; } diff --git a/tests/phpunit/languages/LanguageLtTest.php b/tests/phpunit/languages/LanguageLtTest.php new file mode 100644 index 0000000000..38ea933a05 --- /dev/null +++ b/tests/phpunit/languages/LanguageLtTest.php @@ -0,0 +1,36 @@ +lang = Language::factory( 'Lt' ); + } + function tearDown() { + unset( $this->lang ); + } + + function testPlural() { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( 'other', $this->lang->convertPlural( 0, $forms ) ); + $this->assertEquals( 'one', $this->lang->convertPlural( 1, $forms ) ); + $this->assertEquals( 'few', $this->lang->convertPlural( 2, $forms ) ); + $this->assertEquals( 'few', $this->lang->convertPlural( 9, $forms ) ); + $this->assertEquals( 'other', $this->lang->convertPlural( 10, $forms ) ); + $this->assertEquals( 'other', $this->lang->convertPlural( 11, $forms ) ); + $this->assertEquals( 'other', $this->lang->convertPlural( 20, $forms ) ); + $this->assertEquals( 'one', $this->lang->convertPlural( 21, $forms ) ); + $this->assertEquals( 'few', $this->lang->convertPlural( 32, $forms ) ); + $this->assertEquals( 'one', $this->lang->convertPlural( 41, $forms ) ); + $this->assertEquals( 'one', $this->lang->convertPlural( 40001, $forms ) ); + $forms = array( 'one', 'few' ); + $this->assertEquals( 'one', $this->lang->convertPlural( 1, $forms ) ); + $this->assertEquals( 'few', $this->lang->convertPlural( 15, $forms ) ); + } +}