Localisation updates from http://translatewiki.net.
[lhc/web/wiklou.git] / languages / Language.php
index 1edca80..c4807a6 100644 (file)
@@ -48,12 +48,13 @@ class FakeConverter {
        /**
         * @var Language
         */
-       var $mLang;
+       public $mLang;
        function __construct( $langobj ) { $this->mLang = $langobj; }
        function autoConvertToAllVariants( $text ) { return array( $this->mLang->getCode() => $text ); }
        function convert( $t ) { return $t; }
        function convertTo( $text, $variant ) { return $text; }
        function convertTitle( $t ) { return $t->getPrefixedText(); }
+       function convertNamespace( $ns ) { return $this->mLang->getFormattedNsText( $ns ); }
        function getVariants() { return array( $this->mLang->getCode() ); }
        function getPreferredVariant() { return $this->mLang->getCode(); }
        function getDefaultVariant() { return $this->mLang->getCode(); }
@@ -77,21 +78,21 @@ class Language {
        /**
         * @var LanguageConverter
         */
-       var $mConverter;
+       public $mConverter;
 
-       var $mVariants, $mCode, $mLoaded = false;
-       var $mMagicExtensions = array(), $mMagicHookDone = false;
+       public $mVariants, $mCode, $mLoaded = false;
+       public $mMagicExtensions = array(), $mMagicHookDone = false;
        private $mHtmlCode = null;
 
-       var $dateFormatStrings = array();
-       var $mExtendedSpecialPageAliases;
+       public $dateFormatStrings = array();
+       public $mExtendedSpecialPageAliases;
 
        protected $namespaceNames, $mNamespaceIds, $namespaceAliases;
 
        /**
         * ReplacementArray object caches
         */
-       var $transformData = array();
+       public $transformData = array();
 
        /**
         * @var LocalisationCache
@@ -356,7 +357,7 @@ class Language {
         * @deprecated in 1.19
         */
        function getFallbackLanguageCode() {
-               wfDeprecated( __METHOD__ );
+               wfDeprecated( __METHOD__, '1.19' );
                return self::getFallbackFor( $this->mCode );
        }
 
@@ -419,6 +420,16 @@ class Language {
         */
        public function setNamespaces( array $namespaces ) {
                $this->namespaceNames = $namespaces;
+               $this->mNamespaceIds = null;
+       }
+
+       /**
+        * Resets all of the namespace caches. Mainly used for testing
+        */
+       public function resetNamespaces( ) {
+               $this->namespaceNames = null;
+               $this->mNamespaceIds = null;
+               $this->namespaceAliases = null;
        }
 
        /**
@@ -3005,7 +3016,7 @@ class Language {
        function listToText( array $l ) {
                $s = '';
                $m = count( $l ) - 1;
-               
+
                if ( $m === 0 ) {
                        return $l[0];
                } elseif ( $m === 1 ) {
@@ -3409,6 +3420,18 @@ class Language {
                if ( !count( $forms ) ) {
                        return '';
                }
+
+               // Handle explicit 0= and 1= forms
+               foreach ( $forms as $index => $form ) {
+                       if ( isset( $form[1] ) && $form[1] === '=' ) {
+                               if ( $form[0] === (string) $count ) {
+                                       return substr( $form, 2 );
+                               }
+                               unset( $forms[$index] );
+                       }
+               }
+               $forms = array_values( $forms );
+
                $pluralForm = $this->getPluralForm( $count );
                $pluralForm = min( $pluralForm, count( $forms ) - 1 );
                return $forms[$pluralForm];
@@ -3524,6 +3547,16 @@ class Language {
                return $this->mConverter->convertTitle( $title );
        }
 
+       /**
+        * Convert a namespace index to a string in the preferred variant
+        *
+        * @param $ns int
+        * @return string
+        */
+       public function convertNamespace( $ns ) {
+               return $this->mConverter->convertNamespace( $ns );
+       }
+
        /**
         * Check if this is a language with variants
         *
@@ -4187,7 +4220,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 +4239,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;
        }
 
        /**