*/
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 ''; }
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; }
}
/**
public $mVariants, $mCode, $mLoaded = false;
public $mMagicExtensions = array(), $mMagicHookDone = false;
- private $mHtmlCode = null;
+ private $mHtmlCode = null, $mParentLanguage = false;
public $dateFormatStrings = array();
public $mExtendedSpecialPageAliases;
}
}
- $this->namespaceAliases = $aliases;
+ # Also add converted namespace names as aliases, to avoid confusion.
+ $convertedNames = array();
+ foreach ( $this->getVariants() as $variant ) {
+ if ( $variant === $this->mCode ) {
+ continue;
+ }
+ foreach ( $this->getNamespaces() as $ns => $_ ) {
+ $convertedNames[$this->getConverter()->convertNamespace( $ns, $variant )] = $ns;
+ }
+ }
+
+ $this->namespaceAliases = $aliases + $convertedNames;
}
return $this->namespaceAliases;
}
$segments = array();
foreach ( $intervals as $intervalName => $intervalValue ) {
+ // Messages: duration-seconds, duration-minutes, duration-hours, duration-days, duration-weeks,
+ // duration-years, duration-decades, duration-centuries, duration-millennia
$message = wfMessage( 'duration-' . $intervalName )->numParams( $intervalValue );
$segments[] = $message->inLanguage( $this )->escaped();
}
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 ) {
+ if ( substr( $form, 0, $pos ) === (string)$count ) {
return substr( $form, $pos + 1 );
}
unset( $forms[$index] );
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;
}
/**