function listToText( array $l ) {
$s = '';
$m = count( $l ) - 1;
-
+
if ( $m === 0 ) {
return $l[0];
} elseif ( $m === 1 ) {
* @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;
}
/**
* @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;
}
/**
--- /dev/null
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageHu.php */
+class LanguageHuTest extends MediaWikiTestCase {
+ private $lang;
+
+ function setUp() {
+ $this->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 ),
+ );
+ }
+
+}