From: Santhosh Thottingal Date: Sat, 15 Sep 2012 19:49:44 +0000 (-0700) Subject: For languages without plural forms, use them from fallback language X-Git-Tag: 1.31.0-rc.0~22367^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=c1dff7112fc86a6cf78a543e9ccc8802aae31d9d;p=lhc%2Fweb%2Fwiklou.git For languages without plural forms, use them from fallback language * Fixes Bug 40251 and this is alternate for I403a29e2 * This brings back the old mediawiki behavior for languages without defined plural rules * Add a test for hu, which had issue as per Bug 40251 Change-Id: I345c305134a62d43c9dfedc5243981d0e77e326d --- diff --git a/languages/Language.php b/languages/Language.php index 1edca80469..40d1f36cd9 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3005,7 +3005,7 @@ class Language { function listToText( array $l ) { $s = ''; $m = count( $l ) - 1; - + if ( $m === 0 ) { return $l[0]; } elseif ( $m === 1 ) { @@ -4187,7 +4187,17 @@ class Language { * @return array Associative array with plural form, and plural rule as key-value pairs */ public function getCompiledPluralRules() { - return self::$dataCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' ); + $pluralRules = self::$dataCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' ); + $fallbacks = Language::getFallbacksFor( $this->mCode ); + if ( !$pluralRules ) { + foreach ( $fallbacks as $fallbackCode ) { + $pluralRules = self::$dataCache->getItem( strtolower( $fallbackCode ), 'compiledPluralRules' ); + if ( $pluralRules ) { + break; + } + } + } + return $pluralRules; } /** @@ -4196,7 +4206,17 @@ class Language { * @return array Associative array with plural form, and plural rule as key-value pairs */ public function getPluralRules() { - return self::$dataCache->getItem( strtolower( $this->mCode ), 'pluralRules' ); + $pluralRules = self::$dataCache->getItem( strtolower( $this->mCode ), 'pluralRules' ); + $fallbacks = Language::getFallbacksFor( $this->mCode ); + if ( !$pluralRules ) { + foreach ( $fallbacks as $fallbackCode ) { + $pluralRules = self::$dataCache->getItem( strtolower( $fallbackCode ), 'pluralRules' ); + if ( $pluralRules ) { + break; + } + } + } + return $pluralRules; } /** diff --git a/tests/phpunit/languages/LanguageHuTest.php b/tests/phpunit/languages/LanguageHuTest.php new file mode 100644 index 0000000000..adbd37ecd6 --- /dev/null +++ b/tests/phpunit/languages/LanguageHuTest.php @@ -0,0 +1,34 @@ +lang = Language::factory( 'Hu' ); + } + function tearDown() { + unset( $this->lang ); + } + + /** @dataProvider providePlural */ + function testPlural( $result, $value ) { + $forms = array( 'one', 'other' ); + $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) ); + } + + function providePlural() { + return array ( + array( 'other', 0 ), + array( 'one', 1 ), + array( 'other', 2 ), + array( 'other', 200 ), + ); + } + +}