Language: Turn public properties into Getters in LanguageConverter based hierarchy
The main goal is to simplify the construction of the LanguageConverter and avoid using constructors for derived classes. In order to hard-deprecate removed property, DeprecationHelper::deprecatePublicPropertyFallback was introduced. Bug: T253834 Change-Id: Ib167982e4e872cfdf0fbcb78b7ca597f5ac8d60a
This commit is contained in:
parent
8d8a072566
commit
d8f54cae8b
24 changed files with 795 additions and 218 deletions
|
|
@ -22,7 +22,8 @@
|
|||
|
||||
/**
|
||||
* Use this trait in classes which have properties for which public access
|
||||
* is deprecated. Set the list of properties in $deprecatedPublicProperties
|
||||
* is deprecated or implementation has been move to another class.
|
||||
* Set the list of properties in $deprecatedPublicProperties
|
||||
* and make the properties non-public. The trait will preserve public access
|
||||
* but issue deprecation warnings when it is needed.
|
||||
*
|
||||
|
|
@ -32,11 +33,25 @@
|
|||
* protected $bar;
|
||||
* public function __construct() {
|
||||
* $this->deprecatePublicProperty( 'bar', '1.21', __CLASS__ );
|
||||
* $this->deprecatePublicPropertyFallback(
|
||||
* 'movedValue',
|
||||
* '1.35',
|
||||
* function () {
|
||||
* return MediawikiServices()::getInstance()
|
||||
* ->getNewImplementationService()->getValue();
|
||||
* },
|
||||
* function ( $value ) {
|
||||
* MediawikiServices()::getInstance()
|
||||
* ->getNewImplementationService()->setValue( $value );
|
||||
* }
|
||||
* );
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* $foo = new Foo;
|
||||
* $foo->bar; // works but logs a warning
|
||||
* $foo->movedValue = 10; // works but logs a warning
|
||||
* $movedValue = $foo->movedValue; // also works
|
||||
*
|
||||
* Cannot be used with classes that have their own __get/__set methods.
|
||||
*
|
||||
|
|
@ -45,8 +60,9 @@
|
|||
trait DeprecationHelper {
|
||||
|
||||
/**
|
||||
* List of deprecated properties, in <property name> => [<version>, <class>, <component>] format
|
||||
* where <version> is the MediaWiki version where the property got deprecated, <class> is the
|
||||
* List of deprecated properties, in <property name> => [<version>, <class>,
|
||||
* <component>, <getter>, <setter> ] format where <version> is the MediaWiki version
|
||||
* where the property got deprecated, <class> is the
|
||||
* the name of the class defining the property, <component> is the MediaWiki component
|
||||
* (extension, skin etc.) for use in the deprecation warning) or null if it is MediaWiki.
|
||||
* E.g. [ 'mNewRev' => [ '1.32', 'DifferenceEngine', null ]
|
||||
|
|
@ -57,6 +73,9 @@ trait DeprecationHelper {
|
|||
/**
|
||||
* Mark a property as deprecated. Only use this for properties that used to be public and only
|
||||
* call it in the constructor.
|
||||
*
|
||||
* @note Providing callbacks makes it not serializable
|
||||
*
|
||||
* @param string $property The name of the property.
|
||||
* @param string $version MediaWiki version where the property became deprecated.
|
||||
* @param string|null $class The class which has the deprecated property. This can usually be
|
||||
|
|
@ -66,16 +85,60 @@ trait DeprecationHelper {
|
|||
* @see wfDeprecated()
|
||||
*/
|
||||
protected function deprecatePublicProperty(
|
||||
$property, $version, $class = null, $component = null
|
||||
$property,
|
||||
$version,
|
||||
$class = null,
|
||||
$component = null
|
||||
) {
|
||||
$this->deprecatedPublicProperties[$property] = [ $version, $class ?: __CLASS__, $component ];
|
||||
$this->deprecatedPublicProperties[$property] = [
|
||||
$version,
|
||||
$class ?: __CLASS__,
|
||||
$component,
|
||||
null, null
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a removed public property as deprecated and provide fallback getter and setter callables.
|
||||
* Only use this for properties that used to be public and only
|
||||
* call it in the constructor.
|
||||
*
|
||||
* @param string $property The name of the property.
|
||||
* @param string $version MediaWiki version where the property became deprecated.
|
||||
* @param callable $getter an user provided getter that implements a `get` logic for the property
|
||||
* @param callable|null $setter an user provided getter that implements a `set` logic for the property
|
||||
* @param string|null $class The class which has the deprecated property.
|
||||
* @param string|null $component
|
||||
*
|
||||
* @since 1.36
|
||||
* @see wfDeprecated()
|
||||
*/
|
||||
protected function deprecatePublicPropertyFallback(
|
||||
string $property,
|
||||
string $version,
|
||||
callable $getter,
|
||||
?callable $setter = null,
|
||||
$class = null,
|
||||
$component = null
|
||||
) {
|
||||
$this->deprecatedPublicProperties[$property] = [
|
||||
$version,
|
||||
$class ?: __CLASS__,
|
||||
null,
|
||||
$getter,
|
||||
$setter,
|
||||
$component
|
||||
];
|
||||
}
|
||||
|
||||
public function __get( $name ) {
|
||||
if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
|
||||
list( $version, $class, $component ) = $this->deprecatedPublicProperties[$name];
|
||||
list( $version, $class, $component, $getter ) = $this->deprecatedPublicProperties[$name];
|
||||
$qualifiedName = $class . '::$' . $name;
|
||||
wfDeprecated( $qualifiedName, $version, $component, 3 );
|
||||
if ( $getter ) {
|
||||
return $getter();
|
||||
}
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
|
|
@ -93,10 +156,16 @@ trait DeprecationHelper {
|
|||
|
||||
public function __set( $name, $value ) {
|
||||
if ( isset( $this->deprecatedPublicProperties[$name] ) ) {
|
||||
list( $version, $class, $component ) = $this->deprecatedPublicProperties[$name];
|
||||
list( $version, $class, $component, , $setter ) = $this->deprecatedPublicProperties[$name];
|
||||
$qualifiedName = $class . '::$' . $name;
|
||||
wfDeprecated( $qualifiedName, $version, $component, 3 );
|
||||
$this->$name = $value;
|
||||
if ( $setter ) {
|
||||
$setter( $value );
|
||||
} elseif ( property_exists( $this, $name ) ) {
|
||||
$this->$name = $value;
|
||||
} else {
|
||||
trigger_error( "Cannot access non-public property $qualifiedName", E_USER_ERROR );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ class ConverterRule {
|
|||
|
||||
$sepPos = strpos( $text, '|' );
|
||||
if ( $sepPos !== false ) {
|
||||
$validFlags = $this->mConverter->mFlags;
|
||||
$validFlags = $this->mConverter->getFlags();
|
||||
$f = StringUtils::explode( ';', substr( $text, 0, $sepPos ) );
|
||||
foreach ( $f as $ff ) {
|
||||
$ff = trim( $ff );
|
||||
|
|
@ -189,7 +189,7 @@ class ConverterRule {
|
|||
}
|
||||
}
|
||||
// syntax error, pass
|
||||
if ( !isset( $this->mConverter->mVariantNames[$vv] ) ) {
|
||||
if ( !isset( $this->mConverter->getVariantNames()[$vv] ) ) {
|
||||
$bidtable = [];
|
||||
$unidtable = [];
|
||||
break;
|
||||
|
|
@ -203,15 +203,15 @@ class ConverterRule {
|
|||
* @return string
|
||||
*/
|
||||
private function getRulesDesc() {
|
||||
$codesep = $this->mConverter->mDescCodeSep;
|
||||
$varsep = $this->mConverter->mDescVarSep;
|
||||
$codesep = $this->mConverter->getDescCodeSeparator();
|
||||
$varsep = $this->mConverter->getDescVarSeparator();
|
||||
$text = '';
|
||||
foreach ( $this->mBidtable as $k => $v ) {
|
||||
$text .= $this->mConverter->mVariantNames[$k] . "$codesep$v$varsep";
|
||||
$text .= $this->mConverter->getVariantNames()[$k] . "$codesep$v$varsep";
|
||||
}
|
||||
foreach ( $this->mUnidtable as $k => $a ) {
|
||||
foreach ( $a as $from => $to ) {
|
||||
$text .= $from . '⇒' . $this->mConverter->mVariantNames[$k] .
|
||||
$text .= $from . '⇒' . $this->mConverter->getVariantNames()[$k] .
|
||||
"$codesep$to$varsep";
|
||||
}
|
||||
}
|
||||
|
|
@ -245,7 +245,7 @@ class ConverterRule {
|
|||
$disp = array_values( $unidtable[$variant] )[0];
|
||||
}
|
||||
// or display first text under disable manual convert
|
||||
if ( $disp === false && $this->mConverter->mManualLevel[$variant] === 'disable' ) {
|
||||
if ( $disp === false && $this->mConverter->getManualLevel()[$variant] === 'disable' ) {
|
||||
if ( count( $bidtable ) > 0 ) {
|
||||
$disp = array_values( $bidtable )[0];
|
||||
} else {
|
||||
|
|
@ -258,7 +258,7 @@ class ConverterRule {
|
|||
|
||||
/**
|
||||
* Similar to getRuleConvertedStr(), but this prefers to use original
|
||||
* page title if $variant === $this->mConverter->mMainLanguageCode
|
||||
* page title if $variant === $this->mConverter->getMainCode()
|
||||
* and may return false in this case (so this title conversion rule
|
||||
* will be ignored and the original title is shown).
|
||||
*
|
||||
|
|
@ -267,7 +267,7 @@ class ConverterRule {
|
|||
* @return string|bool The converted title or false if just page name
|
||||
*/
|
||||
private function getRuleConvertedTitle( $variant ) {
|
||||
if ( $variant === $this->mConverter->mMainLanguageCode ) {
|
||||
if ( $variant === $this->mConverter->getMainCode() ) {
|
||||
// If a string targeting exactly this variant is set,
|
||||
// use it. Otherwise, just return false, so the real
|
||||
// page name can be shown (and because variant === main,
|
||||
|
|
@ -298,10 +298,10 @@ class ConverterRule {
|
|||
|
||||
$bidtable = $this->mBidtable;
|
||||
$unidtable = $this->mUnidtable;
|
||||
$manLevel = $this->mConverter->mManualLevel;
|
||||
$manLevel = $this->mConverter->getManualLevel();
|
||||
|
||||
$vmarked = [];
|
||||
foreach ( $this->mConverter->mVariants as $v ) {
|
||||
foreach ( $this->mConverter->getVariants() as $v ) {
|
||||
/* for bidirectional array
|
||||
fill in the missing variants, if any,
|
||||
with fallbacks */
|
||||
|
|
@ -395,7 +395,7 @@ class ConverterRule {
|
|||
if ( isset( $flags['+'] ) || isset( $flags['-'] ) ) {
|
||||
// fill all variants if text in -{A/H/-|text}- is non-empty but without rules
|
||||
if ( $rules !== '' ) {
|
||||
foreach ( $this->mConverter->mVariants as $v ) {
|
||||
foreach ( $this->mConverter->getVariants() as $v ) {
|
||||
$this->mBidtable[$v] = $rules;
|
||||
}
|
||||
}
|
||||
|
|
@ -414,7 +414,7 @@ class ConverterRule {
|
|||
case 'N':
|
||||
// process N flag: output current variant name
|
||||
$ruleVar = trim( $rules );
|
||||
$this->mRuleDisplay = $this->mConverter->mVariantNames[$ruleVar] ?? '';
|
||||
$this->mRuleDisplay = $this->mConverter->getVariantNames()[$ruleVar] ?? '';
|
||||
break;
|
||||
case 'D':
|
||||
// process D flag: output rules description
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ interface ILanguageConverter {
|
|||
|
||||
/**
|
||||
* Get all valid variants.
|
||||
* Call this instead of using $this->mVariants directly.
|
||||
* @return string[] Contains all valid variants
|
||||
*/
|
||||
public function getVariants();
|
||||
|
|
|
|||
|
|
@ -55,14 +55,6 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
'zh',
|
||||
];
|
||||
|
||||
public $mMainLanguageCode;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $mVariants;
|
||||
private $mVariantFallbacks;
|
||||
public $mVariantNames;
|
||||
private $mTablesLoaded = false;
|
||||
|
||||
/**
|
||||
|
|
@ -70,16 +62,11 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
*/
|
||||
protected $mTables;
|
||||
|
||||
/** @var string[] One of 'bidirectional' 'unidirectional' 'disable' for each variant */
|
||||
public $mManualLevel;
|
||||
|
||||
/**
|
||||
* @var Language
|
||||
*/
|
||||
private $mLangObj;
|
||||
public $mFlags;
|
||||
public $mDescCodeSep = ':';
|
||||
public $mDescVarSep = ';';
|
||||
|
||||
private $mUcfirst = false;
|
||||
private $mConvRuleTitle = false;
|
||||
private $mURLVariant;
|
||||
|
|
@ -92,23 +79,8 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
|
||||
/**
|
||||
* @param Language $langobj
|
||||
* @param string $maincode The main language code of this language
|
||||
* @param string[] $variants The supported variants of this language
|
||||
* @param array $variantfallbacks The fallback language of each variant
|
||||
* @param array $flags Defining the custom strings that maps to the flags
|
||||
* @param array $manualLevel Limit for supported variants
|
||||
*/
|
||||
public function __construct(
|
||||
$langobj,
|
||||
$maincode,
|
||||
$variants = [],
|
||||
$variantfallbacks = [],
|
||||
$flags = [],
|
||||
$manualLevel = []
|
||||
) {
|
||||
global $wgDisabledVariants;
|
||||
|
||||
$this->deprecatePublicProperty( 'mURLVariant', '1.35', __CLASS__ );
|
||||
public function __construct( $langobj ) {
|
||||
$this->deprecatePublicProperty( 'mUcfirst', '1.35', __CLASS__ );
|
||||
$this->deprecatePublicProperty( 'mConvRuleTitle', '1.35', __CLASS__ );
|
||||
$this->deprecatePublicProperty( 'mUserVariant', '1.35', __CLASS__ );
|
||||
|
|
@ -121,12 +93,67 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
$this->deprecatePublicProperty( 'mTables', '1.35', __CLASS__ );
|
||||
|
||||
$this->mLangObj = $langobj;
|
||||
$this->mMainLanguageCode = $maincode;
|
||||
$this->mVariants = array_diff( $variants, $wgDisabledVariants );
|
||||
$this->mVariantFallbacks = $variantfallbacks;
|
||||
$this->mVariantNames = MediaWikiServices::getInstance()
|
||||
->getLanguageNameUtils()
|
||||
->getLanguageNames();
|
||||
|
||||
$this->deprecatePublicPropertyFallback( 'mVariants', '1.36', function () {
|
||||
return $this->getVariants();
|
||||
} );
|
||||
|
||||
$this->deprecatePublicPropertyFallback( 'mMainLanguageCode', '1.36', function () {
|
||||
return $this->getMainCode();
|
||||
} );
|
||||
|
||||
$this->deprecatePublicPropertyFallback( 'mVariantFallbacks', '1.36', function () {
|
||||
return $this->getVariantsFallbacks();
|
||||
} );
|
||||
|
||||
$this->deprecatePublicPropertyFallback( 'mFlags', '1.36', function () {
|
||||
return $this->getFlags();
|
||||
} );
|
||||
|
||||
$this->deprecatePublicPropertyFallback( 'mVariantNames', '1.36', function () {
|
||||
return $this->getVariantNames();
|
||||
} );
|
||||
|
||||
$this->deprecatePublicPropertyFallback( 'mDescCodeSep', '1.36', function () {
|
||||
return $this->getDescCodeSeparator();
|
||||
} );
|
||||
|
||||
$this->deprecatePublicPropertyFallback( 'mDescVarSep', '1.36', function () {
|
||||
return $this->getDescVarSeparator();
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getMainCode(): string;
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getLanguageVariants(): array;
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getVariantsFallbacks(): array;
|
||||
|
||||
/**
|
||||
* Get strings that maps to the flags.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final public function getFlags(): array {
|
||||
$defaultflags = [
|
||||
// 'S' show converted text
|
||||
// '+' add rules for alltext
|
||||
|
|
@ -140,25 +167,94 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
'H' => 'H', // add rule for convert code (but no display in placed code)
|
||||
'N' => 'N', // current variant name
|
||||
];
|
||||
$this->mFlags = array_merge( $defaultflags, $flags );
|
||||
foreach ( $this->mVariants as $v ) {
|
||||
if ( array_key_exists( $v, $manualLevel ) ) {
|
||||
$this->mManualLevel[$v] = $manualLevel[$v];
|
||||
} else {
|
||||
$this->mManualLevel[$v] = 'bidirectional';
|
||||
}
|
||||
$this->mFlags[$v] = $v;
|
||||
$flags = array_merge( $defaultflags, $this->getAdditionalFlags() );
|
||||
foreach ( $this->getVariants() as $v ) {
|
||||
$flags[$v] = $v;
|
||||
}
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all valid variants.
|
||||
* Call this instead of using $this->mVariants directly.
|
||||
* Provides additinal flags for converter. By default it return empty array and
|
||||
* typicslly should be overridden by implementation of converter..
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAdditionalFlags(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get manual level limit for supported variants.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final public function getManualLevel() {
|
||||
$manualLevel = $this->getAdditionalManualLevel();
|
||||
$result = [];
|
||||
foreach ( $this->getVariants() as $v ) {
|
||||
if ( array_key_exists( $v, $manualLevel ) ) {
|
||||
$result[$v] = $manualLevel[$v];
|
||||
} else {
|
||||
$result[$v] = 'bidirectional';
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides additinal flags for converter. By default it return empty array and
|
||||
* typicslly should be overridden by implementation of converter.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAdditionalManualLevel(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get desc code separator. By default returns ":", can be overridden by
|
||||
* implementation of converter.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescCodeSeparator(): string {
|
||||
return ':';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get desc var separator. By default returns ";", can be overridden by
|
||||
* implementation of converter.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescVarSeparator(): string {
|
||||
return ';';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variant names.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantNames(): array {
|
||||
return MediaWikiServices::getInstance()
|
||||
->getLanguageNameUtils()
|
||||
->getLanguageNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all valid variants for current Coverter. It uses abstract
|
||||
*
|
||||
* @return string[] Contains all valid variants
|
||||
*/
|
||||
public function getVariants() {
|
||||
return $this->mVariants;
|
||||
final public function getVariants() {
|
||||
global $wgDisabledVariants;
|
||||
return array_diff( $this->getLanguageVariants(), $wgDisabledVariants );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -173,7 +269,7 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
* main code if there is no fallback
|
||||
*/
|
||||
public function getVariantFallbacks( $variant ) {
|
||||
return $this->mVariantFallbacks[$variant] ?? $this->mMainLanguageCode;
|
||||
return $this->getVariantsFallbacks()[$variant] ?? $this->getMainCode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -217,7 +313,7 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
if ( $req ) {
|
||||
return $req;
|
||||
}
|
||||
return $this->mMainLanguageCode;
|
||||
return $this->getMainCode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -240,7 +336,7 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
if ( $req ) {
|
||||
return $req;
|
||||
}
|
||||
return $this->mMainLanguageCode;
|
||||
return $this->getMainCode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -259,14 +355,14 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
// Our internal variants are always lower-case; the variant we
|
||||
// are validating may have mixed case.
|
||||
$variant = LanguageCode::replaceDeprecatedCodes( strtolower( $variant ) );
|
||||
if ( in_array( $variant, $this->mVariants ) ) {
|
||||
if ( in_array( $variant, $this->getVariants() ) ) {
|
||||
return $variant;
|
||||
}
|
||||
// Browsers are supposed to use BCP 47 standard in the
|
||||
// Accept-Language header, but not all of our internal
|
||||
// mediawiki variant codes are BCP 47. Map BCP 47 code
|
||||
// to our internal code.
|
||||
foreach ( $this->mVariants as $v ) {
|
||||
foreach ( $this->getVariants() as $v ) {
|
||||
// Case-insensitive match (BCP 47 is mixed case)
|
||||
if ( strtolower( LanguageCode::bcp47( $v ) ) === $variant ) {
|
||||
return $v;
|
||||
|
|
@ -314,12 +410,12 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
if ( $user->isRegistered() ) {
|
||||
// Get language variant preference from logged in users
|
||||
if (
|
||||
$this->mMainLanguageCode ==
|
||||
$this->getMainCode() ==
|
||||
MediaWikiServices::getInstance()->getContentLanguage()->getCode()
|
||||
) {
|
||||
$ret = $user->getOption( 'variant' );
|
||||
} else {
|
||||
$ret = $user->getOption( 'variant-' . $this->mMainLanguageCode );
|
||||
$ret = $user->getOption( 'variant-' . $this->getMainCode() );
|
||||
}
|
||||
} else {
|
||||
// figure out user lang without constructing wgLang to avoid
|
||||
|
|
@ -361,7 +457,7 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
// We record these fallback variants, and process
|
||||
// them later.
|
||||
$fallbacks = $this->getVariantFallbacks( $language );
|
||||
if ( is_string( $fallbacks ) && $fallbacks !== $this->mMainLanguageCode ) {
|
||||
if ( is_string( $fallbacks ) && $fallbacks !== $this->getMainCode() ) {
|
||||
$fallbackLanguages[] = $fallbacks;
|
||||
} elseif ( is_array( $fallbacks ) ) {
|
||||
$fallbackLanguages =
|
||||
|
|
@ -573,7 +669,7 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
$this->loadTables();
|
||||
|
||||
$ret = [];
|
||||
foreach ( $this->mVariants as $variant ) {
|
||||
foreach ( $this->getVariants() as $variant ) {
|
||||
$ret[$variant] = $this->translate( $text, $variant );
|
||||
}
|
||||
|
||||
|
|
@ -987,7 +1083,7 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
// Do not use null as starting value, as that would confuse phan a lot.
|
||||
$this->mTables = [];
|
||||
$cache = ObjectCache::getInstance( $wgLanguageConverterCacheType );
|
||||
$cacheKey = $cache->makeKey( 'conversiontables', $this->mMainLanguageCode );
|
||||
$cacheKey = $cache->makeKey( 'conversiontables', $this->getMainCode() );
|
||||
if ( $fromCache ) {
|
||||
$this->mTables = $cache->get( $cacheKey );
|
||||
}
|
||||
|
|
@ -996,7 +1092,7 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
// We will first load the default tables
|
||||
// then update them using things in MediaWiki:Conversiontable/*
|
||||
$this->loadDefaultTables();
|
||||
foreach ( $this->mVariants as $var ) {
|
||||
foreach ( $this->getVariants() as $var ) {
|
||||
$cached = $this->parseCachedTable( $var );
|
||||
// @phan-suppress-next-next-line PhanTypeArraySuspiciousNullable
|
||||
// FIXME: $this->mTables could theoretically be null here
|
||||
|
|
@ -1228,7 +1324,7 @@ abstract class LanguageConverter implements ILanguageConverter {
|
|||
// [2] => ''
|
||||
// ]
|
||||
$expandedVariants = [];
|
||||
foreach ( $this->mVariants as $variant ) {
|
||||
foreach ( $this->getVariants() as $variant ) {
|
||||
$expandedVariants[ $variant ] = 1;
|
||||
// Accept standard BCP 47 names for variants as well.
|
||||
$expandedVariants[ LanguageCode::bcp47( $variant ) ] = 1;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ abstract class LanguageConverterIcu extends LanguageConverterSpecific {
|
|||
*/
|
||||
protected function loadDefaultTables() {
|
||||
$this->mTables = [];
|
||||
foreach ( $this->mVariants as $variant ) {
|
||||
foreach ( $this->getVariants() as $variant ) {
|
||||
$this->mTables[$variant] = new ReplacementArray();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ abstract class LanguageConverterSpecific extends LanguageConverter {
|
|||
|
||||
$oldlink = $link;
|
||||
parent::findVariantLink( $link, $nt, $ignoreOtherCond );
|
||||
if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
|
||||
if ( $this->getPreferredVariant() == $this->getMainCode() ) {
|
||||
$link = $oldlink;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,14 @@ class TrivialLanguageConverter implements ILanguageConverter {
|
|||
*/
|
||||
private $titleFormatter;
|
||||
|
||||
/**
|
||||
* Creates a converter for languages that don't have variants. This method is internal
|
||||
* and should be called for LanguageConverterFactory only
|
||||
*
|
||||
* @param Language $langobj
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$this->language = $langobj;
|
||||
$this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
|
||||
|
|
|
|||
|
|
@ -28,19 +28,41 @@
|
|||
class BanConverter extends LanguageConverterIcu {
|
||||
|
||||
/**
|
||||
* @param Language $langobj
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$variants = [ 'ban', 'ban-bali', 'ban-x-dharma', 'ban-x-palmleaf', 'ban-x-pku' ];
|
||||
$variantfallbacks = [
|
||||
public function getMainCode(): string {
|
||||
return 'ban';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'ban', 'ban-bali', 'ban-x-dharma', 'ban-x-palmleaf', 'ban-x-pku' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [
|
||||
'ban-bali' => 'ban',
|
||||
'ban-x-dharma' => 'ban',
|
||||
'ban-x-palmleaf' => 'ban',
|
||||
'ban-x-pku' => 'ban',
|
||||
];
|
||||
}
|
||||
|
||||
parent::__construct( $langobj, 'ban', $variants, $variantfallbacks, [] );
|
||||
|
||||
public function getVariantNames(): array {
|
||||
$names = [
|
||||
'ban' => 'Basa Bali',
|
||||
'ban-bali' => 'ᬩᬲᬩᬮᬶ',
|
||||
|
|
@ -48,7 +70,7 @@ class BanConverter extends LanguageConverterIcu {
|
|||
'ban-x-palmleaf' => 'Basa Bali (alih aksara Palmleaf.org)',
|
||||
'ban-x-pku' => 'Basa Bali (alih aksara Puri Kauhan Ubud)',
|
||||
];
|
||||
$this->mVariantNames = array_merge( $this->mVariantNames, $names );
|
||||
return array_merge( parent::getVariantNames(), $names );
|
||||
}
|
||||
|
||||
protected function getIcuRules() {
|
||||
|
|
|
|||
|
|
@ -75,18 +75,44 @@ class CrhConverter extends LanguageConverterSpecific {
|
|||
public const L_F = 'eiöüEİÖÜ';
|
||||
|
||||
/**
|
||||
* @param Language $langobj
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$variants = [ 'crh', 'crh-cyrl', 'crh-latn' ];
|
||||
$variantfallbacks = [
|
||||
public function getMainCode(): string {
|
||||
return 'crh';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'crh', 'crh-cyrl', 'crh-latn' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [
|
||||
'crh' => 'crh-latn',
|
||||
'crh-cyrl' => 'crh-latn',
|
||||
'crh-latn' => 'crh-cyrl',
|
||||
];
|
||||
}
|
||||
|
||||
parent::__construct( $langobj, 'crh',
|
||||
$variants, $variantfallbacks, [] );
|
||||
/**
|
||||
* @param Language $langobj
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
parent::__construct( $langobj );
|
||||
|
||||
// No point delaying this since they're in code.
|
||||
// Waiting until loadDefaultTables() means they never get loaded
|
||||
|
|
@ -270,5 +296,4 @@ class CrhConverter extends LanguageConverterSpecific {
|
|||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,36 @@
|
|||
*/
|
||||
class EnConverter extends LanguageConverter {
|
||||
|
||||
public function __construct( $langobj ) {
|
||||
parent::__construct( $langobj, 'en', [ 'en', 'en-x-piglatin' ] );
|
||||
/**
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMainCode(): string {
|
||||
return 'en';
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy methods required by base class.
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'en', 'en-x-piglatin' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function loadDefaultTables() {
|
||||
$this->mTables = [
|
||||
'en' => new ReplacementArray(),
|
||||
|
|
|
|||
|
|
@ -24,36 +24,84 @@
|
|||
* @ingroup Language
|
||||
*/
|
||||
class GanConverter extends LanguageConverter {
|
||||
/**
|
||||
* @param Language $langobj
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$this->mDescCodeSep = ':';
|
||||
$this->mDescVarSep = ';';
|
||||
|
||||
$variants = [ 'gan', 'gan-hans', 'gan-hant' ];
|
||||
$variantfallbacks = [
|
||||
/**
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMainCode(): string {
|
||||
return 'gan';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'gan', 'gan-hans', 'gan-hant' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [
|
||||
'gan' => [ 'gan-hans', 'gan-hant' ],
|
||||
'gan-hans' => [ 'gan' ],
|
||||
'gan-hant' => [ 'gan' ],
|
||||
];
|
||||
$ml = [
|
||||
'gan' => 'disable',
|
||||
];
|
||||
}
|
||||
|
||||
parent::__construct( $langobj, 'gan',
|
||||
$variants,
|
||||
$variantfallbacks,
|
||||
[],
|
||||
$ml
|
||||
);
|
||||
/**
|
||||
* Get manual level limit for supported variants.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAdditionalManualLevel(): array {
|
||||
return [ 'gan' => 'disable' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get desc. code separator.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescCodeSeparator(): string {
|
||||
return ': ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get desc. var separator.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescVarSeparator(): string {
|
||||
return '; ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variant names. Overrides parent's implementation
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantNames(): array {
|
||||
$names = [
|
||||
'gan' => '原文',
|
||||
'gan-hans' => '简体',
|
||||
'gan-hant' => '繁體',
|
||||
];
|
||||
$this->mVariantNames = array_merge( $this->mVariantNames, $names );
|
||||
return array_merge( parent::getVariantNames(), $names );
|
||||
}
|
||||
|
||||
protected function loadDefaultTables() {
|
||||
|
|
|
|||
|
|
@ -34,9 +34,6 @@
|
|||
* @ingroup Language
|
||||
*/
|
||||
class IuConverter extends LanguageConverterSpecific {
|
||||
|
||||
protected $mDoContentConvert;
|
||||
|
||||
public $mToLatin = [
|
||||
'ᐦ' => 'h', 'ᐃ' => 'i', 'ᐄ' => 'ii', 'ᐅ' => 'u', 'ᐆ' => 'uu', 'ᐊ' => 'a', 'ᐋ' => 'aa',
|
||||
'ᑉ' => 'p', 'ᐱ' => 'pi', 'ᐲ' => 'pii', 'ᐳ' => 'pu', 'ᐴ' => 'puu', 'ᐸ' => 'pa', 'ᐹ' => 'paa',
|
||||
|
|
@ -89,18 +86,37 @@ class IuConverter extends LanguageConverterSpecific {
|
|||
];
|
||||
|
||||
/**
|
||||
* @param Language $langobj
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$variants = [ 'iu', 'ike-cans', 'ike-latn' ];
|
||||
$variantfallbacks = [
|
||||
public function getMainCode(): string {
|
||||
return 'iu';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'iu', 'ike-cans', 'ike-latn' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [
|
||||
'iu' => 'ike-cans',
|
||||
'ike-cans' => 'iu',
|
||||
'ike-latn' => 'iu',
|
||||
];
|
||||
$flags = [];
|
||||
|
||||
parent::__construct( $langobj, 'iu', $variants, $variantfallbacks, $flags );
|
||||
}
|
||||
|
||||
protected function loadDefaultTables() {
|
||||
|
|
|
|||
|
|
@ -36,14 +36,42 @@ define( 'H_HAMZA', 'ٴ' ); # U+0674 ARABIC LETTER HIGH HAMZA
|
|||
*/
|
||||
class KkConverter extends LanguageConverterSpecific {
|
||||
|
||||
protected $mCyrl2Latn, $mLatn2Cyrl, $mCyLa2Arab;
|
||||
/**
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMainCode(): string {
|
||||
return 'kk';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Language $langobj
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$variants = [ 'kk', 'kk-cyrl', 'kk-latn', 'kk-arab', 'kk-kz', 'kk-tr', 'kk-cn' ];
|
||||
$variantfallbacks = [
|
||||
public function getLanguageVariants(): array {
|
||||
return [
|
||||
'kk',
|
||||
'kk-cyrl',
|
||||
'kk-latn',
|
||||
'kk-arab',
|
||||
'kk-kz',
|
||||
'kk-tr',
|
||||
'kk-cn'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [
|
||||
'kk' => 'kk-cyrl',
|
||||
'kk-cyrl' => 'kk',
|
||||
'kk-latn' => 'kk',
|
||||
|
|
@ -52,14 +80,6 @@ class KkConverter extends LanguageConverterSpecific {
|
|||
'kk-tr' => 'kk-latn',
|
||||
'kk-cn' => 'kk-arab'
|
||||
];
|
||||
|
||||
parent::__construct( $langobj, 'kk',
|
||||
$variants, $variantfallbacks, [] );
|
||||
|
||||
// No point delaying this since they're in code.
|
||||
// Waiting until loadDefaultTables() means they never get loaded
|
||||
// when the tables themselves are loaded from cache.
|
||||
$this->loadRegs();
|
||||
}
|
||||
|
||||
protected function loadDefaultTables() {
|
||||
|
|
@ -90,8 +110,14 @@ class KkConverter extends LanguageConverterSpecific {
|
|||
$this->mTables['kk-cn']->merge( $this->mTables['kk-arab'] );
|
||||
}
|
||||
|
||||
private function loadRegs() {
|
||||
$this->mCyrl2Latn = [
|
||||
/**
|
||||
* Return cyrillic to latin reg conversion table
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getMCyrl2Latn(): array {
|
||||
return [
|
||||
# # Punctuation
|
||||
'/№/u' => 'No.',
|
||||
# # Е after vowels
|
||||
|
|
@ -129,8 +155,16 @@ class KkConverter extends LanguageConverterSpecific {
|
|||
'/Ш/u' => 'Ş', '/ш/u' => 'ş', '/Ы/u' => 'I', '/ы/u' => 'ı',
|
||||
'/І/u' => 'İ', '/і/u' => 'i', '/Э/u' => 'É', '/э/u' => 'é',
|
||||
];
|
||||
}
|
||||
|
||||
$this->mLatn2Cyrl = [
|
||||
/**
|
||||
* Return latin to cyrillic reg conversion table
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getMLatn2Cyrl(): array {
|
||||
return [
|
||||
# # Punctuation
|
||||
'/#|No\./' => '№',
|
||||
# # Şç
|
||||
|
|
@ -168,8 +202,16 @@ class KkConverter extends LanguageConverterSpecific {
|
|||
'/W/u' => 'У', '/w/u' => 'у', '/Ý/u' => 'Й', '/ý/u' => 'й',
|
||||
'/X/u' => 'Х', '/x/u' => 'х', '/Z/u' => 'З', '/z/u' => 'з',
|
||||
];
|
||||
}
|
||||
|
||||
$this->mCyLa2Arab = [
|
||||
/**
|
||||
* Return latin or cyrillic to arab reg conversion table.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMCyLa2Arab() {
|
||||
return [
|
||||
# # Punctuation -> Arabic
|
||||
'/#|№|No\./u' => '', # U+0600
|
||||
'/\,/' => '،', # U+060C
|
||||
|
|
@ -304,19 +346,22 @@ class KkConverter extends LanguageConverterSpecific {
|
|||
$mstart = $m[1] + strlen( $m[0] );
|
||||
}
|
||||
$text =& $ret;
|
||||
foreach ( $this->mCyLa2Arab as $pat => $rep ) {
|
||||
$mCyLa2Arab = $this->getMCyLa2Arab();
|
||||
foreach ( $mCyLa2Arab as $pat => $rep ) {
|
||||
$text = preg_replace( $pat, $rep, $text );
|
||||
}
|
||||
return $text;
|
||||
case 'kk-latn':
|
||||
case 'kk-tr':
|
||||
foreach ( $this->mCyrl2Latn as $pat => $rep ) {
|
||||
$mCyrl2Latn = $this->getMCyrl2Latn();
|
||||
foreach ( $mCyrl2Latn as $pat => $rep ) {
|
||||
$text = preg_replace( $pat, $rep, $text );
|
||||
}
|
||||
return $text;
|
||||
case 'kk-cyrl':
|
||||
case 'kk-kz':
|
||||
foreach ( $this->mLatn2Cyrl as $pat => $rep ) {
|
||||
$mLatn2Cyrl = $this->getMLatn2Cyrl();
|
||||
foreach ( $mLatn2Cyrl as $pat => $rep ) {
|
||||
$text = preg_replace( $pat, $rep, $text );
|
||||
}
|
||||
return $text;
|
||||
|
|
|
|||
|
|
@ -151,17 +151,37 @@ class KuConverter extends LanguageConverterSpecific {
|
|||
];
|
||||
|
||||
/**
|
||||
* @param Language $langobj
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$variants = [ 'ku', 'ku-arab', 'ku-latn' ];
|
||||
$variantfallbacks = [
|
||||
public function getMainCode(): string {
|
||||
return 'ku';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'ku', 'ku-arab', 'ku-latn' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [
|
||||
'ku' => 'ku-latn',
|
||||
'ku-arab' => 'ku-latn',
|
||||
'ku-latn' => 'ku-arab',
|
||||
];
|
||||
|
||||
parent::__construct( $langobj, 'ku', $variants, $variantfallbacks );
|
||||
}
|
||||
|
||||
protected function loadDefaultTables() {
|
||||
|
|
|
|||
|
|
@ -34,9 +34,6 @@
|
|||
* @ingroup Language
|
||||
*/
|
||||
class ShiConverter extends LanguageConverterSpecific {
|
||||
|
||||
protected $mDoContentConvert;
|
||||
|
||||
// The Tifinagh alphabet sequence is based on
|
||||
// "Dictionnaire Général de la Langue Amazighe Informatisé"
|
||||
// by IRCAM (https://tal.ircam.ma/dglai/lexieam.php, DGLAi),
|
||||
|
|
@ -155,18 +152,37 @@ class ShiConverter extends LanguageConverterSpecific {
|
|||
];
|
||||
|
||||
/**
|
||||
* @param Language $langobj
|
||||
* Get main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$variants = [ 'shi', 'shi-tfng', 'shi-latn' ];
|
||||
$variantfallbacks = [
|
||||
public function getMainCode(): string {
|
||||
return 'shi';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'shi', 'shi-tfng', 'shi-latn' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [
|
||||
'shi' => 'shi-tfng',
|
||||
'shi-tfng' => 'shi',
|
||||
'shi-latn' => 'shi',
|
||||
];
|
||||
|
||||
$flags = [];
|
||||
parent::__construct( $langobj, 'shi', $variants, $variantfallbacks, $flags );
|
||||
}
|
||||
|
||||
protected function loadDefaultTables() {
|
||||
|
|
|
|||
|
|
@ -75,21 +75,56 @@ class SrConverter extends LanguageConverterSpecific {
|
|||
];
|
||||
|
||||
/**
|
||||
* @param Language $langobj
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$variants = [ 'sr', 'sr-ec', 'sr-el' ];
|
||||
$variantfallbacks = [
|
||||
public function getMainCode(): string {
|
||||
return 'sr';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'sr', 'sr-ec', 'sr-el' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [
|
||||
'sr' => 'sr-ec',
|
||||
'sr-ec' => 'sr',
|
||||
'sr-el' => 'sr',
|
||||
];
|
||||
}
|
||||
|
||||
$flags = [
|
||||
'S' => 'S', 'писмо' => 'S', 'pismo' => 'S',
|
||||
'W' => 'W', 'реч' => 'W', 'reč' => 'W', 'ријеч' => 'W', 'riječ' => 'W'
|
||||
/**
|
||||
* Get strings that maps to the flags.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAdditionalFlags(): array {
|
||||
return [
|
||||
'S' => 'S',
|
||||
'писмо' => 'S',
|
||||
'pismo' => 'S',
|
||||
'W' => 'W',
|
||||
'реч' => 'W',
|
||||
'reč' => 'W',
|
||||
'ријеч' => 'W',
|
||||
'riječ' => 'W'
|
||||
];
|
||||
parent::__construct( $langobj, 'sr', $variants, $variantfallbacks, $flags );
|
||||
}
|
||||
|
||||
protected function loadDefaultTables() {
|
||||
|
|
@ -162,5 +197,4 @@ class SrConverter extends LanguageConverterSpecific {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@
|
|||
* @ingroup Language
|
||||
*/
|
||||
class TgConverter extends LanguageConverter {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $table = [
|
||||
'а' => 'a',
|
||||
'б' => 'b',
|
||||
|
|
@ -104,11 +108,33 @@ class TgConverter extends LanguageConverter {
|
|||
];
|
||||
|
||||
/**
|
||||
* @param Language $langobj
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$variants = [ 'tg', 'tg-latn' ];
|
||||
parent::__construct( $langobj, 'tg', $variants );
|
||||
public function getMainCode(): string {
|
||||
return 'tg';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'tg', 'tg-latn' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function loadDefaultTables() {
|
||||
|
|
|
|||
|
|
@ -103,16 +103,37 @@ class UzConverter extends LanguageConverter {
|
|||
];
|
||||
|
||||
/**
|
||||
* @param Language $langobj
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$variants = [ 'uz', 'uz-latn', 'uz-cyrl' ];
|
||||
$variantfallbacks = [
|
||||
public function getMainCode(): string {
|
||||
return 'uz';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'uz', 'uz-latn', 'uz-cyrl' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [
|
||||
'uz' => 'uz-latn',
|
||||
'uz-cyrl' => 'uz',
|
||||
'uz-latn' => 'uz',
|
||||
];
|
||||
parent::__construct( $langobj, 'uz', $variants, $variantfallbacks );
|
||||
}
|
||||
|
||||
protected function loadDefaultTables() {
|
||||
|
|
@ -123,6 +144,11 @@ class UzConverter extends LanguageConverter {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
* @param string $toVariant
|
||||
* @return string
|
||||
*/
|
||||
public function translate( $text, $toVariant ) {
|
||||
if ( $toVariant == 'uz-cyrl' ) {
|
||||
$text = str_replace( 'ye', 'е', $text );
|
||||
|
|
@ -134,5 +160,4 @@ class UzConverter extends LanguageConverter {
|
|||
}
|
||||
return parent::translate( $text, $toVariant );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,14 +25,25 @@
|
|||
* @ingroup Language
|
||||
*/
|
||||
class ZhConverter extends LanguageConverter {
|
||||
/**
|
||||
* @param Language $langobj
|
||||
*/
|
||||
public function __construct( $langobj ) {
|
||||
$this->mDescCodeSep = ':';
|
||||
$this->mDescVarSep = ';';
|
||||
|
||||
$variants = [
|
||||
/**
|
||||
* Get Main language code.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMainCode(): string {
|
||||
return 'zh';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [
|
||||
'zh',
|
||||
'zh-hans',
|
||||
'zh-hant',
|
||||
|
|
@ -43,9 +54,26 @@ class ZhConverter extends LanguageConverter {
|
|||
'zh-sg',
|
||||
'zh-tw'
|
||||
];
|
||||
}
|
||||
|
||||
$variantfallbacks = [
|
||||
'zh' => [ 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ],
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [
|
||||
'zh' => [
|
||||
'zh-hans',
|
||||
'zh-hant',
|
||||
'zh-cn',
|
||||
'zh-tw',
|
||||
'zh-hk',
|
||||
'zh-sg',
|
||||
'zh-mo',
|
||||
'zh-my'
|
||||
],
|
||||
'zh-hans' => [ 'zh-cn', 'zh-sg', 'zh-my' ],
|
||||
'zh-hant' => [ 'zh-tw', 'zh-hk', 'zh-mo' ],
|
||||
'zh-cn' => [ 'zh-hans', 'zh-sg', 'zh-my' ],
|
||||
|
|
@ -55,17 +83,49 @@ class ZhConverter extends LanguageConverter {
|
|||
'zh-hk' => [ 'zh-hant', 'zh-mo', 'zh-tw' ],
|
||||
'zh-mo' => [ 'zh-hant', 'zh-hk', 'zh-tw' ],
|
||||
];
|
||||
$ml = [
|
||||
}
|
||||
|
||||
/**
|
||||
* Get manual level limits for variants supported by converter.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAdditionalManualLevel(): array {
|
||||
return [
|
||||
'zh' => 'disable',
|
||||
'zh-hans' => 'unidirectional',
|
||||
'zh-hant' => 'unidirectional',
|
||||
];
|
||||
}
|
||||
|
||||
parent::__construct( $langobj, 'zh',
|
||||
$variants,
|
||||
$variantfallbacks,
|
||||
[],
|
||||
$ml );
|
||||
/**
|
||||
* Get desc. code separator.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescCodeSeparator(): string {
|
||||
return ':';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get desc. var separator.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescVarSeparator(): string {
|
||||
return ';';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variant names.
|
||||
* @since 1.36
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantNames(): array {
|
||||
$names = [
|
||||
'zh' => '原文',
|
||||
'zh-hans' => '简体',
|
||||
|
|
@ -77,7 +137,7 @@ class ZhConverter extends LanguageConverter {
|
|||
'zh-sg' => '新加坡',
|
||||
'zh-my' => '大马',
|
||||
];
|
||||
$this->mVariantNames = array_merge( $this->mVariantNames, $names );
|
||||
return array_merge( parent::getVariantNames(), $names );
|
||||
}
|
||||
|
||||
protected function loadDefaultTables() {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ class DeprecationHelperTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
public function provideGet() {
|
||||
return [
|
||||
[ 'protectedDeprecated', 0, null ],
|
||||
[ 'privateDeprecated', null, null ],
|
||||
[ 'fallbackDeprecated', null, null ],
|
||||
[ 'fallbackGetterOnly', null, null ],
|
||||
[ 'protectedNonDeprecated', E_USER_ERROR,
|
||||
'Cannot access non-public property TestDeprecatedClass::$protectedNonDeprecated' ],
|
||||
[ 'privateNonDeprecated', E_USER_ERROR,
|
||||
|
|
@ -69,6 +73,11 @@ class DeprecationHelperTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
public function provideSet() {
|
||||
return [
|
||||
[ 'protectedDeprecated', null, null ],
|
||||
[ 'privateDeprecated', null, null ],
|
||||
[ 'fallbackDeprecated', null, null ],
|
||||
[ 'fallbackGetterOnly', E_USER_ERROR,
|
||||
'Cannot access non-public property TestDeprecatedClass::$fallbackGetterOnly' ],
|
||||
[ 'protectedNonDeprecated', E_USER_ERROR,
|
||||
'Cannot access non-public property TestDeprecatedClass::$protectedNonDeprecated' ],
|
||||
[ 'privateNonDeprecated', E_USER_ERROR,
|
||||
|
|
@ -146,10 +155,8 @@ class DeprecationHelperTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
protected function assertDeprecationWarningIssued( callable $callback ) {
|
||||
MWDebug::clearLog();
|
||||
$this->expectDeprecation();
|
||||
$callback();
|
||||
$wrapper = TestingAccessWrapper::newFromClass( MWDebug::class );
|
||||
$this->assertNotEmpty( $wrapper->deprecationWarnings );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -8,12 +8,25 @@ class TestDeprecatedClass {
|
|||
protected $protectedNonDeprecated = 1;
|
||||
private $privateDeprecated = 1;
|
||||
private $privateNonDeprecated = 1;
|
||||
private $fallbackDeprecated = 1;
|
||||
|
||||
public function __construct() {
|
||||
$this->deprecatedPublicProperties = [
|
||||
'protectedDeprecated' => '1.23',
|
||||
'privateDeprecated' => '1.24',
|
||||
];
|
||||
$this->deprecatePublicProperty( 'protectedDeprecated', '1.23' );
|
||||
$this->deprecatePublicProperty( 'privateDeprecated', '1.24' );
|
||||
|
||||
$this->deprecatePublicPropertyFallback( 'fallbackDeprecated', '1.25',
|
||||
function () {
|
||||
return $this->fallbackDeprecated;
|
||||
},
|
||||
function ( $value ) {
|
||||
$this->fallbackDeprecated = $value;
|
||||
}
|
||||
);
|
||||
$this->deprecatePublicPropertyFallback( 'fallbackGetterOnly', '1.25',
|
||||
function () {
|
||||
return 1;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function setThings( $prod, $prond, $prid, $prind ) {
|
||||
|
|
|
|||
|
|
@ -167,12 +167,12 @@ class LanguageConverterFactoryTest extends MediaWikiLangTestCase {
|
|||
$testConverter = TestingAccessWrapper::newFromObject( $converter );
|
||||
$this->assertSame( $lang, $testConverter->mLangObj, "Language should be as provided" );
|
||||
|
||||
$this->assertEquals( $code, $testConverter->mMainLanguageCode,
|
||||
$this->assertEquals( $code, $testConverter->getMainCode(),
|
||||
"mMainLanguageCode should be as $code" );
|
||||
$this->assertEquals( $manualLevel, $testConverter->mManualLevel, "Manual Level" );
|
||||
$this->assertEquals( $manualLevel, $testConverter->getManualLevel(), "Manual Level" );
|
||||
|
||||
$this->assertEquals( $variants, $testConverter->mVariants, "Variants" );
|
||||
$this->assertEquals( $variantFallbacks, $testConverter->mVariantFallbacks, "Variant Fallbacks" );
|
||||
$this->assertEquals( $variants, $testConverter->getVariants(), "Variants" );
|
||||
$this->assertEquals( $variantFallbacks, $testConverter->getVariantsFallbacks(), "Variant Fallbacks" );
|
||||
$defaultFlags = [
|
||||
'A' => 'A',
|
||||
'T' => 'T',
|
||||
|
|
@ -184,7 +184,7 @@ class LanguageConverterFactoryTest extends MediaWikiLangTestCase {
|
|||
];
|
||||
$this->assertArraySubmapSame(
|
||||
array_merge( $defaultFlags, $flags ),
|
||||
$converter->mFlags,
|
||||
$converter->getFlags(),
|
||||
"Flags"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,12 +39,7 @@ class LanguageConverterTest extends MediaWikiLangTestCase {
|
|||
} ) );
|
||||
$this->lang->expects( $this->never() )
|
||||
->method( $this->anythingBut( 'factory', 'getNsText', 'ucfirst' ) );
|
||||
$this->lc = new DummyConverter(
|
||||
$this->lang, 'tg',
|
||||
# Adding 'sgs' as a variant to ensure we handle deprecated codes
|
||||
# adding 'simple' as a variant to ensure we handle non BCP 47 codes
|
||||
[ 'tg', 'tg-latn', 'sgs', 'simple' ]
|
||||
);
|
||||
$this->lc = new DummyConverter( $this->lang );
|
||||
}
|
||||
|
||||
protected function tearDown() : void {
|
||||
|
|
|
|||
|
|
@ -5,12 +5,42 @@
|
|||
*/
|
||||
class DummyConverter extends LanguageConverter {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $table = [
|
||||
'б' => 'b',
|
||||
'в' => 'v',
|
||||
'г' => 'g',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get Main language code.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMainCode(): string {
|
||||
return 'tg';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported variants of the language.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageVariants(): array {
|
||||
return [ 'tg', 'tg-latn', 'sgs', 'simple' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language variants fallbacks.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariantsFallbacks(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function loadDefaultTables() {
|
||||
$this->mTables = [
|
||||
'sgs' => new ReplacementArray(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue