public $mVariants, $mCode, $mLoaded = false;
public $mMagicExtensions = array(), $mMagicHookDone = false;
- private $mHtmlCode = null;
+ private $mHtmlCode = null, $mParentLanguage = false;
public $dateFormatStrings = array();
public $mExtendedSpecialPageAliases;
* @param MWTimestamp $relativeTo Base timestamp
* @param User $user User preferences to use
* @return string Human timestamp
- * @since 1.21
+ * @since 1.22
*/
public function getHumanTimestamp( MWTimestamp $ts, MWTimestamp $relativeTo, User $user ) {
$diff = $ts->diff( $relativeTo );
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
*
*/
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;
}
/**
/**
* Get the plural rule types for the language
- * @since 1.21
+ * @since 1.22
* @return array Associative array with plural form number and plural rule type as key-value pairs
*/
public function getPluralRuleTypes() {
* Find the plural rule type appropriate for the given number
* For example, if the language is set to Arabic, getPluralType(5) should
* return 'few'.
- * @since 1.21
+ * @since 1.22
* @return string The name of the plural rule type, e.g. one, two, few, many
*/
public function getPluralRuleType( $number ) {