X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguage.php;h=702d0b48771b6c6ab4589a401ebafea3151f3640;hb=ff507e09ececa88bc7135f5c671e3c4701e9ea35;hp=50cb7f79220556427103dbfff20f55cd40b1710e;hpb=7844c9a0581ec68ab7213f81d228c279ed167542;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/Language.php b/languages/Language.php index 50cb7f7922..702d0b4877 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -49,12 +49,14 @@ class FakeConverter { */ public $mLang; function __construct( $langobj ) { $this->mLang = $langobj; } + function autoConvert( $text, $variant = false ) { return $text; } 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 getVariantFallbacks( $variant ) { return $this->mLang->getCode(); } function getPreferredVariant() { return $this->mLang->getCode(); } function getDefaultVariant() { return $this->mLang->getCode(); } function getURLVariant() { return ''; } @@ -66,6 +68,8 @@ class FakeConverter { function convertCategoryKey( $key ) { return $key; } function convertLinkToAllVariants( $text ) { return $this->autoConvertToAllVariants( $text ); } function armourMath( $text ) { return $text; } + function validateVariant( $variant = null ) { return $variant === $this->mLang->getCode() ? $variant : null; } + function translate( $text, $variant ) { return $text; } } /** @@ -81,7 +85,7 @@ class Language { public $mVariants, $mCode, $mLoaded = false; public $mMagicExtensions = array(), $mMagicHookDone = false; - private $mHtmlCode = null; + private $mHtmlCode = null, $mParentLanguage = false; public $dateFormatStrings = array(); public $mExtendedSpecialPageAliases; @@ -3616,7 +3620,7 @@ class Language { function convertPlural( $count, $forms ) { // Handle explicit n=pluralform cases foreach ( $forms as $index => $form ) { - if ( preg_match( '/\d+=/i', $form ) ) { + if ( preg_match( '/^\d+=/i', $form ) ) { $pos = strpos( $form, '=' ); if ( substr( $form, 0, $pos ) === (string) $count ) { return substr( $form, $pos + 1 ); @@ -3939,6 +3943,34 @@ class Language { return $this; } + /** + * Get the "parent" language which has a converter to convert a "compatible" language + * (in another variant) to this language (eg. zh for zh-cn, but not en for en-gb). + * + * @return Language|null + * @since 1.22 + */ + public function getParentLanguage() { + if ( $this->mParentLanguage !== false ) { + return $this->mParentLanguage; + } + + $pieces = explode( '-', $this->getCode() ); + $code = $pieces[0]; + if ( !in_array( $code, LanguageConverter::$languagesWithVariants ) ) { + $this->mParentLanguage = null; + return null; + } + $lang = Language::factory( $code ); + if ( !$lang->hasVariant( $this->getCode() ) ) { + $this->mParentLanguage = null; + return null; + } + + $this->mParentLanguage = $lang; + return $lang; + } + /** * Get the RFC 3066 code for this language object * @@ -3973,8 +4005,9 @@ class Language { */ public function setCode( $code ) { $this->mCode = $code; - // Ensure we don't leave an incorrect html code lying around + // Ensure we don't leave incorrect cached data lying around $this->mHtmlCode = null; + $this->mParentLanguage = false; } /**