MediaWiki
REL1_22
|
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. | |
convertNamespace ($index, $variant=null) | |
Get the namespace display name in the preferred variant. | |
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 | |
$mConvRuleTitle = false | |
$mDescCodeSep = ':' | |
$mDescVarSep = ';' | |
$mFlags | |
$mHeaderVariant | |
$mLangObj | |
$mMainLanguageCode | |
$mManualLevel | |
$mMaxDepth = 10 | |
$mTables | |
$mTablesLoaded = false | |
$mUcfirst = false | |
$mURLVariant | |
$mUserVariant | |
$mVariantFallbacks | |
$mVariantNames | |
$mVariants | |
$mVarSeparatorPattern | |
String | __pad0__: $mCacheKey |
memcached key name | |
const | CACHE_VERSION_KEY = 'VERSION 6' |
Static Public Attributes | |
static | $languagesWithVariants |
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 | |
OnPageContentSaveComplete ($page, $user, $content, $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 84 of file LanguageConverter.php.
LanguageConverter::applyManualConv | ( | $ | convRule | ) | [protected] |
Apply manual conversion rules.
$convRule | ConverterRule Object of ConverterRule |
Definition at line 512 of file LanguageConverter.php.
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 1107 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 337 of file LanguageConverter.php.
Referenced by GanConverter\convertCategoryKey(), and ZhConverter\convertCategoryKey().
Call translate() to convert text to all valid variants.
$text | String: the text to be converted |
Definition at line 479 of file LanguageConverter.php.
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 610 of file LanguageConverter.php.
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 1062 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 503 of file LanguageConverter.php.
LanguageConverter::convertNamespace | ( | $ | index, |
$ | variant = null |
||
) |
Get the namespace display name in the preferred variant.
$index | int namespace id |
$variant | string|null variant code or null for preferred variant |
Definition at line 572 of file LanguageConverter.php.
LanguageConverter::convertTitle | ( | $ | title | ) |
Auto convert a Title object to a readable string in the preferred variant.
Definition at line 553 of file LanguageConverter.php.
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 622 of file LanguageConverter.php.
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 761 of file LanguageConverter.php.
Get the title produced by the conversion rule.
Definition at line 151 of file LanguageConverter.php.
Get default variant.
This function would not be affected by user's settings
Definition at line 189 of file LanguageConverter.php.
Returns language specific hash options.
Definition at line 827 of file LanguageConverter.php.
LanguageConverter::getHeaderVariant | ( | ) | [protected] |
Determine the language variant from the Accept-Language header.
Definition at line 280 of file LanguageConverter.php.
Get preferred language variant.
Definition at line 159 of file LanguageConverter.php.
Referenced by SrConverter\findVariantLink(), ShiConverter\findVariantLink(), IuConverter\findVariantLink(), KuConverter\findVariantLink(), and KkConverter\findVariantLink().
Get the variant specified in the URL.
Definition at line 225 of file LanguageConverter.php.
LanguageConverter::getUserVariant | ( | ) | [protected] |
Determine if the user has a variant set.
Definition at line 247 of file LanguageConverter.php.
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 140 of file LanguageConverter.php.
Get all valid variants.
Call this instead of using $this->mVariants directly.
Definition at line 125 of file LanguageConverter.php.
Get the cached separator pattern for ConverterRule::parseRules()
Definition at line 1117 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 842 of file LanguageConverter.php.
Load default conversion tables.
This method must be implemented in derived class.
MWException |
Reimplemented in KuConverter, TestConverter, TgConverter, UzConverter, IuConverter, SrConverter, ShiConverter, ZhConverter, KkConverter, and GanConverter.
Definition at line 853 of file LanguageConverter.php.
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 863 of file LanguageConverter.php.
Referenced by SrConverter\translate(), ShiConverter\translate(), IuConverter\translate(), and KuConverter\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 |
Definition at line 1044 of file LanguageConverter.php.
LanguageConverter::OnPageContentSaveComplete | ( | $ | page, |
$ | user, | ||
$ | content, | ||
$ | summary, | ||
$ | isMinor, | ||
$ | isWatch, | ||
$ | section, | ||
$ | flags, | ||
$ | revision | ||
) | [private] |
Hook to refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
$page | WikiPage object |
$user | Object: User object for the current user |
$content | Content: new page content |
$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 | |
$flags | int Bitfield |
$revision | Object: new Revision object or null |
Definition at line 1082 of file LanguageConverter.php.
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 936 of file LanguageConverter.php.
Hook for post processing after conversion tables are loaded.
Reimplemented in KkConverter, and ZhConverter.
Definition at line 902 of file LanguageConverter.php.
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 |
MWException |
Definition at line 683 of file LanguageConverter.php.
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 641 of file LanguageConverter.php.
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 461 of file LanguageConverter.php.
LanguageConverter::validateVariant | ( | $ | variant = null | ) |
Validate the variant.
$variant | String: the variant to validate |
Definition at line 213 of file LanguageConverter.php.
LanguageConverter::$languagesWithVariants [static] |
array( 'gan', 'iu', 'kk', 'ku', 'shi', 'sr', 'tg', 'uz', 'zh', )
Definition at line 38 of file LanguageConverter.php.
Referenced by ApiPageSet\getParamDescription(), and Preferences\profilePreferences().
LanguageConverter::$mConvRuleTitle = false |
Definition at line 65 of file LanguageConverter.php.
LanguageConverter::$mDescCodeSep = ':' |
Definition at line 63 of file LanguageConverter.php.
LanguageConverter::$mDescVarSep = ';' |
Definition at line 63 of file LanguageConverter.php.
LanguageConverter::$mFlags |
Definition at line 62 of file LanguageConverter.php.
LanguageConverter::$mHeaderVariant |
Definition at line 68 of file LanguageConverter.php.
LanguageConverter::$mLangObj |
Definition at line 61 of file LanguageConverter.php.
LanguageConverter::$mMainLanguageCode |
Definition at line 50 of file LanguageConverter.php.
LanguageConverter::$mManualLevel |
Definition at line 55 of file LanguageConverter.php.
LanguageConverter::$mMaxDepth = 10 |
Definition at line 69 of file LanguageConverter.php.
LanguageConverter::$mTables |
Definition at line 53 of file LanguageConverter.php.
LanguageConverter::$mTablesLoaded = false |
Definition at line 52 of file LanguageConverter.php.
LanguageConverter::$mUcfirst = false |
Definition at line 64 of file LanguageConverter.php.
LanguageConverter::$mURLVariant |
Definition at line 66 of file LanguageConverter.php.
LanguageConverter::$mUserVariant |
Definition at line 67 of file LanguageConverter.php.
LanguageConverter::$mVariantFallbacks |
Definition at line 51 of file LanguageConverter.php.
LanguageConverter::$mVariantNames |
Definition at line 51 of file LanguageConverter.php.
LanguageConverter::$mVariants |
Definition at line 51 of file LanguageConverter.php.
LanguageConverter::$mVarSeparatorPattern |
Definition at line 70 of file LanguageConverter.php.
String LanguageConverter::__pad0__ |
memcached key name
Definition at line 59 of file LanguageConverter.php.
const LanguageConverter::CACHE_VERSION_KEY = 'VERSION 6' |
Definition at line 72 of file LanguageConverter.php.