MediaWiki
1.28.0
|
Base class for language conversion. More...
Public Member Functions | |
__construct ($langobj, $maincode, $variants=[], $variantfallbacks=[], $flags=[], $manualLevel=[]) | |
Constructor. More... | |
autoConvert ($text, $toVariant=false) | |
Dictionary-based conversion. More... | |
autoConvertToAllVariants ($text) | |
Call translate() to convert text to all valid variants. More... | |
convert ($text) | |
Convert text to different variants of a language. More... | |
convertCategoryKey ($key) | |
Convert the sorting key for category links. More... | |
convertNamespace ($index, $variant=null) | |
Get the namespace display name in the preferred variant. More... | |
convertTitle ($title) | |
Auto convert a Title object to a readable string in the preferred variant. More... | |
convertTo ($text, $variant) | |
Same as convert() except a extra parameter to custom variant. More... | |
findVariantLink (&$link, &$nt, $ignoreOtherCond=false) | |
If a language supports multiple variants, it is possible that non-existing link in one variant actually exists in another variant. More... | |
getConvRuleTitle () | |
Get the title produced by the conversion rule. More... | |
getDefaultVariant () | |
Get default variant. More... | |
getExtraHashOptions () | |
Returns language specific hash options. More... | |
getPreferredVariant () | |
Get preferred language variant. More... | |
getURLVariant () | |
Get the variant specified in the URL. More... | |
getVariantFallbacks ($variant) | |
In case some variant is not defined in the markup, we need to have some fallback. More... | |
getVariants () | |
Get all valid variants. More... | |
getVarSeparatorPattern () | |
Get the cached separator pattern for ConverterRule::parseRules() More... | |
guessVariant ($text, $variant) | |
Guess if a text is written in a variant. More... | |
loadDefaultTables () | |
Load default conversion tables. More... | |
loadTables ($fromCache=true) | |
Load conversion tables either from the cache or the disk. More... | |
markNoConversion ($text, $noParse=false) | |
Enclose a string with the "no conversion" tag. More... | |
parseCachedTable ($code, $subpage= '', $recursive=true) | |
Parse the conversion table stored in the cache. More... | |
postLoadTables () | |
Hook for post processing after conversion tables are loaded. More... | |
reloadTables () | |
Reload the conversion tables. More... | |
translate ($text, $variant) | |
Translate a string to a variant. More... | |
updateConversionTable (Title $titleobj) | |
Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated. More... | |
validateVariant ($variant=null) | |
Validate the variant. More... | |
Public Attributes | |
string | $mCacheKey |
Memcached key name. More... | |
$mConvRuleTitle = false | |
$mDescCodeSep = ':' | |
$mDescVarSep = ';' | |
$mFlags | |
$mHeaderVariant | |
$mLangObj | |
$mMainLanguageCode | |
$mManualLevel | |
$mMaxDepth = 10 | |
$mTables | |
$mTablesLoaded = false | |
$mUcfirst = false | |
$mURLVariant | |
$mUserVariant | |
$mVariantFallbacks | |
$mVariantNames | |
$mVariants | |
$mVarSeparatorPattern | |
const | CACHE_VERSION_KEY = 'VERSION 7' |
Static Public Attributes | |
static array | $languagesWithVariants |
languages supporting variants More... | |
Protected Member Functions | |
applyManualConv ($convRule) | |
Apply manual conversion rules. More... | |
getHeaderVariant () | |
Determine the language variant from the Accept-Language header. More... | |
getUserVariant () | |
Determine if the user has a variant set. More... | |
recursiveConvertRule ($text, $variant, &$startPos, $depth=0) | |
Recursively convert text on the inside. More... | |
recursiveConvertTopLevel ($text, $variant, $depth=0) | |
Recursively convert text on the outside. More... | |
Base class for language conversion.
Definition at line 32 of file LanguageConverter.php.
LanguageConverter::__construct | ( | $langobj, | |
$maincode, | |||
$variants = [] , |
|||
$variantfallbacks = [] , |
|||
$flags = [] , |
|||
$manualLevel = [] |
|||
) |
Constructor.
Language | $langobj | |
string | $maincode | The main language code of this language |
array | $variants | The supported variants of this language |
array | $variantfallbacks | The fallback language of each variant |
array | $flags | Defining the custom strings that maps to the flags |
array | $manualLevel | Limit for supported variants |
Definition at line 87 of file LanguageConverter.php.
References $flags, $wgDisabledVariants, as, Language\fetchLanguageNames(), global, and wfMemcKey().
|
protected |
Apply manual conversion rules.
ConverterRule | $convRule |
Definition at line 491 of file LanguageConverter.php.
References $from, as, and validateVariant().
Referenced by recursiveConvertRule().
LanguageConverter::autoConvert | ( | $text, | |
$toVariant = false |
|||
) |
Dictionary-based conversion.
This function would not parse the conversion rules. If you want to parse rules, try to use convert() or convertTo().
string | $text | The text to be converted |
bool | string | $toVariant | The target language code |
Definition at line 344 of file LanguageConverter.php.
References $output, as, Sanitizer\decodeTagAttributes(), Html\expandAttributes(), StringUtils\explode(), getPreferredVariant(), guessVariant(), loadTables(), Parser\MARKER_PREFIX, recursiveConvertTopLevel(), and translate().
Referenced by GanConverter\convertCategoryKey(), ZhConverter\convertCategoryKey(), KkConverter\convertCategoryKey(), recursiveConvertRule(), and recursiveConvertTopLevel().
LanguageConverter::autoConvertToAllVariants | ( | $text | ) |
Call translate() to convert text to all valid variants.
string | $text | The text to be converted |
Definition at line 475 of file LanguageConverter.php.
References $ret, as, loadTables(), and translate().
Referenced by findVariantLink().
LanguageConverter::convert | ( | $text | ) |
Convert text to different variants of a language.
The automatic conversion is done in autoConvert(). Here we parse the text marked with -{}-, which specifies special conversions of the text that can not be accomplished in autoConvert().
Syntax of the markup: -{code1:text1;code2:text2;...}- or -{flags|code1:text1;code2:text2;...}- or -{text}- in which case no conversion should take place for text
string | $text | Text to be converted |
Definition at line 603 of file LanguageConverter.php.
References convertTo(), and getPreferredVariant().
LanguageConverter::convertCategoryKey | ( | $key | ) |
Convert the sorting key for category links.
This should make different keys that are variants of each other map to the same key.
string | $key |
Definition at line 1057 of file LanguageConverter.php.
LanguageConverter::convertNamespace | ( | $index, | |
$variant = null |
|||
) |
Get the namespace display name in the preferred variant.
int | $index | Namespace id |
string | null | $variant | Variant code or null for preferred variant |
Definition at line 547 of file LanguageConverter.php.
References $cache, getPreferredVariant(), NS_MAIN, translate(), and wfMessage().
Referenced by convertTitle().
LanguageConverter::convertTitle | ( | $title | ) |
Auto convert a Title object to a readable string in the preferred variant.
Definition at line 528 of file LanguageConverter.php.
References $title, convertNamespace(), getPreferredVariant(), NS_MAIN, and translate().
LanguageConverter::convertTo | ( | $text, | |
$variant | |||
) |
Same as convert() except a extra parameter to custom variant.
string | $text | Text to be converted |
string | $variant | The target variant code |
Definition at line 615 of file LanguageConverter.php.
References $wgDisableLangConversion, global, and recursiveConvertTopLevel().
Referenced by convert().
LanguageConverter::findVariantLink | ( | & | $link, |
& | $nt, | ||
$ignoreOtherCond = false |
|||
) |
If a language supports multiple variants, it is possible that non-existing link in one variant actually exists in another variant.
This function tries to find it. See e.g. LanguageZh.php The input parameters may be modified upon return
string | &$link | The name of the link |
Title | &$nt | The title object of the link |
bool | $ignoreOtherCond | To disable other conditions when we need to transclude a template or update a category's link |
Definition at line 754 of file LanguageConverter.php.
References $link, $titles, $wgDisableLangConversion, $wgDisableTitleConversion, $wgRequest, as, autoConvertToAllVariants(), global, Title\newFromText(), and NS_MAIN.
LanguageConverter::getConvRuleTitle | ( | ) |
Get the title produced by the conversion rule.
Definition at line 153 of file LanguageConverter.php.
References $mConvRuleTitle.
LanguageConverter::getDefaultVariant | ( | ) |
Get default variant.
This function would not be affected by user's settings
Definition at line 191 of file LanguageConverter.php.
References $mMainLanguageCode, $req, $wgDefaultLanguageVariant, getHeaderVariant(), getURLVariant(), global, and validateVariant().
LanguageConverter::getExtraHashOptions | ( | ) |
Returns language specific hash options.
Definition at line 821 of file LanguageConverter.php.
References getPreferredVariant().
|
protected |
Determine the language variant from the Accept-Language header.
Definition at line 287 of file LanguageConverter.php.
References $languages, $mHeaderVariant, $wgRequest, as, getVariantFallbacks(), global, and validateVariant().
Referenced by getDefaultVariant(), and getPreferredVariant().
LanguageConverter::getPreferredVariant | ( | ) |
Get preferred language variant.
Definition at line 161 of file LanguageConverter.php.
References $mMainLanguageCode, $req, $wgDefaultLanguageVariant, $wgUser, getHeaderVariant(), getURLVariant(), getUserVariant(), global, and validateVariant().
Referenced by autoConvert(), convert(), convertNamespace(), convertTitle(), SrConverter\findVariantLink(), ShiConverter\findVariantLink(), IuConverter\findVariantLink(), KuConverter\findVariantLink(), KkConverter\findVariantLink(), and getExtraHashOptions().
LanguageConverter::getURLVariant | ( | ) |
Get the variant specified in the URL.
Definition at line 227 of file LanguageConverter.php.
References $mURLVariant, $ret, $wgRequest, global, and validateVariant().
Referenced by getDefaultVariant(), and getPreferredVariant().
|
protected |
Determine if the user has a variant set.
Definition at line 250 of file LanguageConverter.php.
References $mUserVariant, $ret, $wgContLang, $wgUser, global, and validateVariant().
Referenced by getPreferredVariant().
LanguageConverter::getVariantFallbacks | ( | $variant | ) |
In case some variant is not defined in the markup, we need to have some fallback.
For example, in zh, normally people will define zh-hans and zh-hant, but less so for zh-sg or zh-hk. when zh-sg is preferred but not defined, we will pick zh-hans in this case. Right now this is only used by zh.
string | $variant | The language code of the variant |
Definition at line 142 of file LanguageConverter.php.
References $mMainLanguageCode.
Referenced by getHeaderVariant().
LanguageConverter::getVariants | ( | ) |
Get all valid variants.
Call this instead of using $this->mVariants directly.
Definition at line 127 of file LanguageConverter.php.
References $mVariants.
LanguageConverter::getVarSeparatorPattern | ( | ) |
Get the cached separator pattern for ConverterRule::parseRules()
Definition at line 1084 of file LanguageConverter.php.
References $mVarSeparatorPattern, and as.
LanguageConverter::guessVariant | ( | $text, | |
$variant | |||
) |
Guess if a text is written in a variant.
This should be implemented in subclasses.
string | $text | The text to be checked |
string | $variant | Language code of the variant to be checked for |
Definition at line 837 of file LanguageConverter.php.
Referenced by autoConvert(), and recursiveConvertTopLevel().
LanguageConverter::loadDefaultTables | ( | ) |
Load default conversion tables.
This method must be implemented in derived class.
MWException |
Definition at line 848 of file LanguageConverter.php.
References $name.
Referenced by loadTables().
LanguageConverter::loadTables | ( | $fromCache = true | ) |
Load conversion tables either from the cache or the disk.
bool | $fromCache | Load from memcached? Defaults to true. |
Definition at line 859 of file LanguageConverter.php.
References $cache, $wgLanguageConverterCacheType, as, ObjectCache\getInstance(), global, loadDefaultTables(), parseCachedTable(), postLoadTables(), wfProfileIn(), and wfProfileOut().
Referenced by autoConvert(), autoConvertToAllVariants(), reloadTables(), SrConverter\translate(), ShiConverter\translate(), IuConverter\translate(), KuConverter\translate(), and translate().
LanguageConverter::markNoConversion | ( | $text, | |
$noParse = false |
|||
) |
Enclose a string with the "no conversion" tag.
This is used by various functions in the Parser.
string | $text | Text to be tagged for no conversion |
bool | $noParse | Unused |
Definition at line 1039 of file LanguageConverter.php.
References $ret.
LanguageConverter::parseCachedTable | ( | $code, | |
$subpage = '' , |
|||
$recursive = true |
|||
) |
Parse the conversion table stored in the cache.
The tables should be in blocks of the following form: -{ word => word ; word => word ; ... }-
To make the tables more manageable, subpages are allowed and will be parsed recursively if $recursive == true.
string | $code | Language code |
string | $subpage | Subpage name |
bool | $recursive | Parse subpages recursively? Defaults to true. |
Definition at line 932 of file LanguageConverter.php.
References $code, $link, $ret, $s, $t, $title, as, CONTENT_MODEL_WIKITEXT, StringUtils\explode(), Title\makeTitleSafe(), Revision\newFromTitle(), NS_MEDIAWIKI, Revision\RAW, and MessageCache\singleton().
Referenced by loadTables().
LanguageConverter::postLoadTables | ( | ) |
Hook for post processing after conversion tables are loaded.
Definition at line 896 of file LanguageConverter.php.
Referenced by loadTables().
|
protected |
Recursively convert text on the inside.
string | $text | Text to be converted |
string | $variant | The target variant code |
int | $startPos | |
int | $depth | Depth of recursion |
MWException |
Definition at line 676 of file LanguageConverter.php.
References applyManualConv(), autoConvert(), and wfMessage().
Referenced by recursiveConvertTopLevel().
|
protected |
Recursively convert text on the outside.
Allow to use nested markups to custom rules.
string | $text | Text to be converted |
string | $variant | The target variant code |
int | $depth | Depth of recursion |
Definition at line 634 of file LanguageConverter.php.
References $out, autoConvert(), guessVariant(), and recursiveConvertRule().
Referenced by autoConvert(), and convertTo().
LanguageConverter::reloadTables | ( | ) |
Reload the conversion tables.
Definition at line 904 of file LanguageConverter.php.
References loadTables().
Referenced by updateConversionTable().
LanguageConverter::translate | ( | $text, | |
$variant | |||
) |
Translate a string to a variant.
Doesn't parse rules or do any of that other stuff, for that use convert() or convertTo().
string | $text | Text to convert |
string | $variant | Variant language code |
Definition at line 459 of file LanguageConverter.php.
References loadTables().
Referenced by autoConvert(), autoConvertToAllVariants(), convertNamespace(), and convertTitle().
LanguageConverter::updateConversionTable | ( | Title | $titleobj | ) |
Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
Definition at line 1067 of file LanguageConverter.php.
References $t, $title, Title\getDBkey(), Title\getNamespace(), NS_MEDIAWIKI, reloadTables(), and validateVariant().
LanguageConverter::validateVariant | ( | $variant = null | ) |
Validate the variant.
string | $variant | The variant to validate |
Definition at line 215 of file LanguageConverter.php.
Referenced by applyManualConv(), getDefaultVariant(), getHeaderVariant(), getPreferredVariant(), getURLVariant(), getUserVariant(), and updateConversionTable().
|
static |
languages supporting variants
Definition at line 38 of file LanguageConverter.php.
Referenced by ListVariants\execute(), ApiPageSet\getAllowedParams(), User\getDefaultOptions(), Language\getParentLanguage(), and Preferences\profilePreferences().
string LanguageConverter::$mCacheKey |
Memcached key name.
Definition at line 62 of file LanguageConverter.php.
LanguageConverter::$mConvRuleTitle = false |
Definition at line 68 of file LanguageConverter.php.
Referenced by getConvRuleTitle().
LanguageConverter::$mDescCodeSep = ':' |
Definition at line 66 of file LanguageConverter.php.
LanguageConverter::$mDescVarSep = ';' |
Definition at line 66 of file LanguageConverter.php.
LanguageConverter::$mFlags |
Definition at line 65 of file LanguageConverter.php.
LanguageConverter::$mHeaderVariant |
Definition at line 71 of file LanguageConverter.php.
Referenced by getHeaderVariant().
LanguageConverter::$mLangObj |
Definition at line 64 of file LanguageConverter.php.
LanguageConverter::$mMainLanguageCode |
Definition at line 50 of file LanguageConverter.php.
Referenced by getDefaultVariant(), getPreferredVariant(), and getVariantFallbacks().
LanguageConverter::$mManualLevel |
Definition at line 57 of file LanguageConverter.php.
LanguageConverter::$mMaxDepth = 10 |
Definition at line 72 of file LanguageConverter.php.
LanguageConverter::$mTables |
Definition at line 55 of file LanguageConverter.php.
LanguageConverter::$mTablesLoaded = false |
Definition at line 54 of file LanguageConverter.php.
LanguageConverter::$mUcfirst = false |
Definition at line 67 of file LanguageConverter.php.
LanguageConverter::$mURLVariant |
Definition at line 69 of file LanguageConverter.php.
Referenced by getURLVariant().
LanguageConverter::$mUserVariant |
Definition at line 70 of file LanguageConverter.php.
Referenced by getUserVariant().
LanguageConverter::$mVariantFallbacks |
Definition at line 52 of file LanguageConverter.php.
LanguageConverter::$mVariantNames |
Definition at line 53 of file LanguageConverter.php.
LanguageConverter::$mVariants |
Definition at line 51 of file LanguageConverter.php.
Referenced by getVariants().
LanguageConverter::$mVarSeparatorPattern |
Definition at line 73 of file LanguageConverter.php.
Referenced by getVarSeparatorPattern().
const LanguageConverter::CACHE_VERSION_KEY = 'VERSION 7' |
Definition at line 75 of file LanguageConverter.php.