MediaWiki
REL1_19
|
Base class for language conversion. More...
Public Member Functions | |
__construct ($langobj, $maincode, $variants=array(), $variantfallbacks=array(), $flags=array(), $manualLevel=array()) | |
Constructor. | |
armourMath ($text) | |
Armour rendered math against conversion. | |
autoConvert ($text, $toVariant=false) | |
Dictionary-based conversion. | |
autoConvertToAllVariants ($text) | |
Call translate() to convert text to all valid variants. | |
convert ($text) | |
Convert text to different variants of a language. | |
convertCategoryKey ($key) | |
Convert the sorting key for category links. | |
convertLinkToAllVariants ($text) | |
Convert link text to all valid variants. | |
convertTitle ($title) | |
Auto convert a Title object to a readable string in the preferred variant. | |
convertTo ($text, $variant) | |
Same as convert() except a extra parameter to custom variant. | |
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. | |
getConvRuleTitle () | |
Get the title produced by the conversion rule. | |
getDefaultVariant () | |
Get default variant. | |
getExtraHashOptions () | |
Returns language specific hash options. | |
getPreferredVariant () | |
Get preferred language variant. | |
getURLVariant () | |
Get the variant specified in the URL. | |
getVariantFallbacks ($variant) | |
In case some variant is not defined in the markup, we need to have some fallback. | |
getVariants () | |
Get all valid variants. | |
getVarSeparatorPattern () | |
Get the cached separator pattern for ConverterRule::parseRules() | |
guessVariant ($text, $variant) | |
Guess if a text is written in a variant. | |
loadDefaultTables () | |
Load default conversion tables. | |
loadTables ($fromCache=true) | |
Load conversion tables either from the cache or the disk. | |
markNoConversion ($text, $noParse=false) | |
Enclose a string with the "no conversion" tag. | |
parseCachedTable ($code, $subpage= '', $recursive=true) | |
Parse the conversion table stored in the cache. | |
postLoadTables () | |
Hook for post processing after conversion tables are loaded. | |
reloadTables () | |
Reload the conversion tables. | |
translate ($text, $variant) | |
Translate a string to a variant. | |
validateVariant ($variant=null) | |
Validate the variant. | |
Public Attributes | |
$mCacheKey | |
$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 6' |
Protected Member Functions | |
applyManualConv ($convRule) | |
Apply manual conversion rules. | |
getHeaderVariant () | |
Determine the language variant from the Accept-Language header. | |
getUserVariant () | |
Determine if the user has a variant set. | |
recursiveConvertRule ($text, $variant, &$startPos, $depth=0) | |
Recursively convert text on the inside. | |
recursiveConvertTopLevel ($text, $variant, $depth=0) | |
Recursively convert text on the outside. | |
Private Member Functions | |
OnArticleSaveComplete ($article, $user, $text, $summary, $isMinor, $isWatch, $section, $flags, $revision) | |
Hook to refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated. |
Base class for language conversion.
Definition at line 31 of file LanguageConverter.php.
LanguageConverter::__construct | ( | $ | langobj, |
$ | maincode, | ||
$ | variants = array() , |
||
$ | variantfallbacks = array() , |
||
$ | flags = array() , |
||
$ | manualLevel = array() |
||
) |
Constructor.
$langobj | Language: the Language Object |
$maincode | String: the main language code of this language |
$variants | Array: the supported variants of this language |
$variantfallbacks | Array: the fallback language of each variant |
$flags | Array: defining the custom strings that maps to the flags |
$manualLevel | Array: limit for supported variants |
Reimplemented in GanConverter, and ZhConverter.
Definition at line 67 of file LanguageConverter.php.
References $wgDisabledVariants, Language\getLanguageNames(), and wfMemcKey().
LanguageConverter::applyManualConv | ( | $ | convRule | ) | [protected] |
Apply manual conversion rules.
$convRule | ConverterRule Object of ConverterRule |
Definition at line 487 of file LanguageConverter.php.
References validateVariant().
Referenced by recursiveConvertRule().
LanguageConverter::armourMath | ( | $ | text | ) |
Armour rendered math against conversion.
Escape special chars in parsed math text. (in most cases are img elements)
$text | String: text to armour against conversion |
Definition at line 1047 of file LanguageConverter.php.
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().
$text | String the text to be converted |
$toVariant | bool|string the target language code |
Reimplemented in KkConverter, KuConverter, IuConverter, ShiConverter, and SrConverter.
Definition at line 312 of file LanguageConverter.php.
References $changed, $output, $wgParser, Sanitizer\decodeTagAttributes(), Html\expandAttributes(), StringUtils\explode(), getPreferredVariant(), guessVariant(), loadTables(), translate(), wfProfileIn(), and wfProfileOut().
Referenced by GanConverter\convertCategoryKey(), ZhConverter\convertCategoryKey(), recursiveConvertRule(), and recursiveConvertTopLevel().
Call translate() to convert text to all valid variants.
$text | String: the text to be converted |
Definition at line 454 of file LanguageConverter.php.
References loadTables(), translate(), wfProfileIn(), and wfProfileOut().
Referenced by convertLinkToAllVariants(), and 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
$text | String: text to be converted |
Definition at line 565 of file LanguageConverter.php.
References convertTo(), and getPreferredVariant().
Convert the sorting key for category links.
This should make different keys that are variants of each other map to the same key.
$key | string |
Reimplemented in KkConverter, ZhConverter, and GanConverter.
Definition at line 1003 of file LanguageConverter.php.
Convert link text to all valid variants.
In the first, this function only convert text outside the "-{" "}-" markups. Since the "{" and "}" are not allowed in titles, the text will get all converted always. So I removed this feature and deprecated the function.
$text | String: the text to be converted |
Definition at line 478 of file LanguageConverter.php.
References autoConvertToAllVariants().
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, getPreferredVariant(), translate(), and wfMessage().
LanguageConverter::convertTo | ( | $ | text, |
$ | variant | ||
) |
Same as convert() except a extra parameter to custom variant.
$text | String: text to be converted |
$variant | String: the target variant code |
Definition at line 577 of file LanguageConverter.php.
References $wgDisableLangConversion, guessVariant(), 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
$link | String: the name of the link |
$nt | Mixed: the title object of the link |
$ignoreOtherCond | Boolean: to disable other conditions when we need to transclude a template or update a category's link |
Reimplemented in KkConverter, KuConverter, IuConverter, ShiConverter, and SrConverter.
Definition at line 709 of file LanguageConverter.php.
References $wgDisableLangConversion, $wgDisableTitleConversion, $wgUser, autoConvertToAllVariants(), and Title\newFromText().
Get the title produced by the conversion rule.
Definition at line 134 of file LanguageConverter.php.
Get default variant.
This function would not be affected by user's settings or headers
Definition at line 172 of file LanguageConverter.php.
References $wgDefaultLanguageVariant, getURLVariant(), and validateVariant().
Returns language specific hash options.
Definition at line 775 of file LanguageConverter.php.
References getPreferredVariant().
LanguageConverter::getHeaderVariant | ( | ) | [protected] |
Determine the language variant from the Accept-Language header.
Definition at line 255 of file LanguageConverter.php.
References $language, $languages, getVariantFallbacks(), and validateVariant().
Referenced by getPreferredVariant().
Get preferred language variant.
Definition at line 142 of file LanguageConverter.php.
References $wgDefaultLanguageVariant, $wgUser, getHeaderVariant(), getURLVariant(), getUserVariant(), and validateVariant().
Referenced by autoConvert(), convert(), convertTitle(), SrConverter\findVariantLink(), ShiConverter\findVariantLink(), IuConverter\findVariantLink(), KuConverter\findVariantLink(), KkConverter\findVariantLink(), and getExtraHashOptions().
Get the variant specified in the URL.
Definition at line 204 of file LanguageConverter.php.
References validateVariant().
Referenced by getDefaultVariant(), and getPreferredVariant().
LanguageConverter::getUserVariant | ( | ) | [protected] |
Determine if the user has a variant set.
Definition at line 226 of file LanguageConverter.php.
References $wgUser, 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.
$variant | String: the language code of the variant |
Definition at line 123 of file LanguageConverter.php.
Referenced by getHeaderVariant().
Get all valid variants.
Call this instead of using $this->mVariants directly.
Definition at line 108 of file LanguageConverter.php.
Get the cached separator pattern for ConverterRule::parseRules()
Definition at line 1057 of file LanguageConverter.php.
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 |
Reimplemented in SrConverter.
Definition at line 790 of file LanguageConverter.php.
Referenced by autoConvert(), and convertTo().
Load default conversion tables.
This method must be implemented in derived class.
Reimplemented in KuConverter, TestConverter, TgConverter, IuConverter, ShiConverter, SrConverter, ZhConverter, KkConverter, and GanConverter.
Definition at line 800 of file LanguageConverter.php.
Referenced by loadTables().
LanguageConverter::loadTables | ( | $ | fromCache = true | ) |
Load conversion tables either from the cache or the disk.
$fromCache | Boolean: load from memcached? Defaults to true. |
Definition at line 810 of file LanguageConverter.php.
References $wgMemc, CACHE_VERSION_KEY, loadDefaultTables(), parseCachedTable(), postLoadTables(), wfProfileIn(), and wfProfileOut().
Referenced by autoConvert(), autoConvertToAllVariants(), reloadTables(), ShiConverter\translate(), IuConverter\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.
$text | String: text to be tagged for no conversion |
$noParse | Boolean: unused |
Reimplemented in KkConverter, KuConverter, IuConverter, ShiConverter, SrConverter, ZhConverter, and GanConverter.
Definition at line 985 of file LanguageConverter.php.
LanguageConverter::OnArticleSaveComplete | ( | $ | article, |
$ | user, | ||
$ | text, | ||
$ | summary, | ||
$ | isMinor, | ||
$ | isWatch, | ||
$ | section, | ||
$ | flags, | ||
$ | revision | ||
) | [private] |
Hook to refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
$article | Article object |
$user | Object: User object for the current user |
$text | String: article text (?) |
$summary | String: edit summary of the edit |
$isMinor | Boolean: was the edit marked as minor? |
$isWatch | Boolean: did the user watch this page or not? |
$section | Unused |
$flags | Bitfield |
$revision | Object: new Revision object or null |
Definition at line 1023 of file LanguageConverter.php.
References $t, $title, reloadTables(), and validateVariant().
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.
$code | String: language code |
$subpage | String: subpage name |
$recursive | Boolean: parse subpages recursively? Defaults to true. |
Definition at line 881 of file LanguageConverter.php.
References $t, $title, StringUtils\explode(), Title\makeTitleSafe(), Revision\newFromTitle(), and MessageCache\singleton().
Referenced by loadTables().
Hook for post processing after conversion tables are loaded.
Reimplemented in KkConverter, and ZhConverter.
Definition at line 847 of file LanguageConverter.php.
Referenced by loadTables().
LanguageConverter::recursiveConvertRule | ( | $ | text, |
$ | variant, | ||
&$ | startPos, | ||
$ | depth = 0 |
||
) | [protected] |
Recursively convert text on the inside.
$text | String: text to be converted |
$variant | String: the target variant code |
$startPos | int |
$depth | Integer: depth of recursion |
Definition at line 631 of file LanguageConverter.php.
References applyManualConv(), autoConvert(), and wfMsgForContent().
Referenced by recursiveConvertTopLevel().
LanguageConverter::recursiveConvertTopLevel | ( | $ | text, |
$ | variant, | ||
$ | depth = 0 |
||
) | [protected] |
Recursively convert text on the outside.
Allow to use nested markups to custom rules.
$text | String: text to be converted |
$variant | String: the target variant code |
$depth | Integer: depth of recursion |
Definition at line 594 of file LanguageConverter.php.
References $out, autoConvert(), and recursiveConvertRule().
Referenced by convertTo().
Reload the conversion tables.
Definition at line 854 of file LanguageConverter.php.
References loadTables().
Referenced by OnArticleSaveComplete().
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().
$text | String: text to convert |
$variant | String: variant language code |
Reimplemented in KkConverter, KuConverter, IuConverter, ShiConverter, and SrConverter.
Definition at line 436 of file LanguageConverter.php.
References loadTables(), wfProfileIn(), and wfProfileOut().
Referenced by autoConvert(), autoConvertToAllVariants(), and convertTitle().
LanguageConverter::validateVariant | ( | $ | variant = null | ) |
Validate the variant.
$variant | String: the variant to validate |
Definition at line 192 of file LanguageConverter.php.
Referenced by applyManualConv(), getDefaultVariant(), getHeaderVariant(), getPreferredVariant(), getURLVariant(), getUserVariant(), and OnArticleSaveComplete().
LanguageConverter::$mCacheKey |
Definition at line 42 of file LanguageConverter.php.
LanguageConverter::$mConvRuleTitle = false |
Definition at line 48 of file LanguageConverter.php.
LanguageConverter::$mDescCodeSep = ':' |
Definition at line 46 of file LanguageConverter.php.
LanguageConverter::$mDescVarSep = ';' |
Definition at line 46 of file LanguageConverter.php.
LanguageConverter::$mFlags |
Definition at line 45 of file LanguageConverter.php.
LanguageConverter::$mHeaderVariant |
Definition at line 51 of file LanguageConverter.php.
LanguageConverter::$mLangObj |
Definition at line 44 of file LanguageConverter.php.
LanguageConverter::$mMainLanguageCode |
Definition at line 32 of file LanguageConverter.php.
LanguageConverter::$mManualLevel |
Definition at line 37 of file LanguageConverter.php.
LanguageConverter::$mMaxDepth = 10 |
Definition at line 52 of file LanguageConverter.php.
LanguageConverter::$mTables |
Definition at line 35 of file LanguageConverter.php.
LanguageConverter::$mTablesLoaded = false |
Definition at line 34 of file LanguageConverter.php.
LanguageConverter::$mUcfirst = false |
Definition at line 47 of file LanguageConverter.php.
LanguageConverter::$mURLVariant |
Definition at line 49 of file LanguageConverter.php.
LanguageConverter::$mUserVariant |
Definition at line 50 of file LanguageConverter.php.
LanguageConverter::$mVariantFallbacks |
Definition at line 33 of file LanguageConverter.php.
LanguageConverter::$mVariantNames |
Definition at line 33 of file LanguageConverter.php.
LanguageConverter::$mVariants |
Definition at line 33 of file LanguageConverter.php.
LanguageConverter::$mVarSeparatorPattern |
Definition at line 53 of file LanguageConverter.php.
const LanguageConverter::CACHE_VERSION_KEY = 'VERSION 6' |
Definition at line 55 of file LanguageConverter.php.
Referenced by loadTables().