MediaWiki  REL1_19
LanguageConverter Class Reference

Base class for language conversion. More...

Inheritance diagram for LanguageConverter:

List of all members.

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.

Detailed Description

Base class for language conversion.

Author:
Zhengzhu Feng <[email protected]> fdcn <[email protected]>, shinjiman <[email protected]>, PhiLiP <[email protected]>

Definition at line 31 of file LanguageConverter.php.


Constructor & Destructor Documentation

LanguageConverter::__construct ( langobj,
maincode,
variants = array(),
variantfallbacks = array(),
flags = array(),
manualLevel = array() 
)

Constructor.

Parameters:
$langobjLanguage: the Language Object
$maincodeString: the main language code of this language
$variantsArray: the supported variants of this language
$variantfallbacksArray: the fallback language of each variant
$flagsArray: defining the custom strings that maps to the flags
$manualLevelArray: limit for supported variants

Reimplemented in GanConverter, and ZhConverter.

Definition at line 67 of file LanguageConverter.php.

References $wgDisabledVariants, Language\getLanguageNames(), and wfMemcKey().

Here is the call graph for this function:


Member Function Documentation

LanguageConverter::applyManualConv ( convRule) [protected]

Apply manual conversion rules.

Parameters:
$convRuleConverterRule Object of ConverterRule

Definition at line 487 of file LanguageConverter.php.

References validateVariant().

Referenced by recursiveConvertRule().

Here is the call graph for this function:

Here is the caller graph for this function:

Armour rendered math against conversion.

Escape special chars in parsed math text. (in most cases are img elements)

Parameters:
$textString: text to armour against conversion
Returns:
String: armoured text where { and } have been converted to &#123; and &#125;

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().

Parameters:
$textString the text to be converted
$toVariantbool|string the target language code
Returns:
String the converted text

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().

Here is the call graph for this function:

Here is the caller graph for this function:

Call translate() to convert text to all valid variants.

Parameters:
$textString: the text to be converted
Returns:
Array: variant => converted text

Definition at line 454 of file LanguageConverter.php.

References loadTables(), translate(), wfProfileIn(), and wfProfileOut().

Referenced by convertLinkToAllVariants(), and findVariantLink().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Parameters:
$textString: text to be converted
Returns:
String: converted text

Definition at line 565 of file LanguageConverter.php.

References convertTo(), and getPreferredVariant().

Here is the call graph for this function:

Convert the sorting key for category links.

This should make different keys that are variants of each other map to the same key.

Parameters:
$keystring
Returns:
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.

Parameters:
$textString: the text to be converted
Returns:
Array: variant => converted text
Deprecated:
since 1.17 Use autoConvertToAllVariants() instead

Definition at line 478 of file LanguageConverter.php.

References autoConvertToAllVariants().

Here is the call graph for this function:

Auto convert a Title object to a readable string in the preferred variant.

Parameters:
$titleTitle a object of Title
Returns:
String: converted title text

Definition at line 528 of file LanguageConverter.php.

References $title, getPreferredVariant(), translate(), and wfMessage().

Here is the call graph for this function:

LanguageConverter::convertTo ( text,
variant 
)

Same as convert() except a extra parameter to custom variant.

Parameters:
$textString: text to be converted
$variantString: the target variant code
Returns:
String: converted text

Definition at line 577 of file LanguageConverter.php.

References $wgDisableLangConversion, guessVariant(), and recursiveConvertTopLevel().

Referenced by convert().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Parameters:
$linkString: the name of the link
$ntMixed: the title object of the link
$ignoreOtherCondBoolean: to disable other conditions when we need to transclude a template or update a category's link
Returns:
Null, the input parameters may be modified upon return

Reimplemented in KkConverter, KuConverter, IuConverter, ShiConverter, and SrConverter.

Definition at line 709 of file LanguageConverter.php.

References $wgDisableLangConversion, $wgDisableTitleConversion, $wgUser, autoConvertToAllVariants(), and Title\newFromText().

Here is the call graph for this function:

Get the title produced by the conversion rule.

Returns:
String: The converted title text

Definition at line 134 of file LanguageConverter.php.

Get default variant.

This function would not be affected by user's settings or headers

Returns:
String: the default variant code

Definition at line 172 of file LanguageConverter.php.

References $wgDefaultLanguageVariant, getURLVariant(), and validateVariant().

Here is the call graph for this function:

Returns language specific hash options.

Returns:
string

Definition at line 775 of file LanguageConverter.php.

References getPreferredVariant().

Here is the call graph for this function:

Determine the language variant from the Accept-Language header.

Returns:
Mixed: variant if one found, false otherwise.

Definition at line 255 of file LanguageConverter.php.

References $language, $languages, getVariantFallbacks(), and validateVariant().

Referenced by getPreferredVariant().

Here is the call graph for this function:

Here is the caller graph for this function:

Get preferred language variant.

Returns:
String: the preferred language code

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().

Here is the call graph for this function:

Here is the caller graph for this function:

Get the variant specified in the URL.

Returns:
Mixed: variant if one found, false otherwise.

Definition at line 204 of file LanguageConverter.php.

References validateVariant().

Referenced by getDefaultVariant(), and getPreferredVariant().

Here is the call graph for this function:

Here is the caller graph for this function:

Determine if the user has a variant set.

Returns:
Mixed: variant if one found, false otherwise.

Definition at line 226 of file LanguageConverter.php.

References $wgUser, and validateVariant().

Referenced by getPreferredVariant().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
$variantString: the language code of the variant
Returns:
String|array: The code of the fallback language or the main code if there is no fallback

Definition at line 123 of file LanguageConverter.php.

Referenced by getHeaderVariant().

Here is the caller graph for this function:

Get all valid variants.

Call this instead of using $this->mVariants directly.

Returns:
Array: contains all valid variants

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.

Parameters:
string$textthe text to be checked
string$variantlanguage code of the variant to be checked for
Returns:
bool true if $text appears to be written in $variant, false if not
Author:
Nikola Smolenski <[email protected]>
Since:
1.19

Reimplemented in SrConverter.

Definition at line 790 of file LanguageConverter.php.

Referenced by autoConvert(), and convertTo().

Here is the caller graph for this function:

Load default conversion tables.

This method must be implemented in derived class.

Access:
private

Reimplemented in KuConverter, TestConverter, TgConverter, IuConverter, ShiConverter, SrConverter, ZhConverter, KkConverter, and GanConverter.

Definition at line 800 of file LanguageConverter.php.

Referenced by loadTables().

Here is the caller graph for this function:

LanguageConverter::loadTables ( fromCache = true)

Load conversion tables either from the cache or the disk.

Access:
private
Parameters:
$fromCacheBoolean: 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().

Here is the call graph for this function:

Here is the caller graph for this function:

LanguageConverter::markNoConversion ( text,
noParse = false 
)

Enclose a string with the "no conversion" tag.

This is used by various functions in the Parser.

Parameters:
$textString: text to be tagged for no conversion
$noParseBoolean: unused
Returns:
String: the tagged text

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.

Parameters:
$articleArticle object
$userObject: User object for the current user
$textString: article text (?)
$summaryString: edit summary of the edit
$isMinorBoolean: was the edit marked as minor?
$isWatchBoolean: did the user watch this page or not?
$sectionUnused
$flagsBitfield
$revisionObject: new Revision object or null
Returns:
Boolean: true

Definition at line 1023 of file LanguageConverter.php.

References $t, $title, reloadTables(), and validateVariant().

Here is the call graph for this function:

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.

Parameters:
$codeString: language code
$subpageString: subpage name
$recursiveBoolean: parse subpages recursively? Defaults to true.
Returns:
array

Definition at line 881 of file LanguageConverter.php.

References $t, $title, StringUtils\explode(), Title\makeTitleSafe(), Revision\newFromTitle(), and MessageCache\singleton().

Referenced by loadTables().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

LanguageConverter::recursiveConvertRule ( text,
variant,
&$  startPos,
depth = 0 
) [protected]

Recursively convert text on the inside.

Parameters:
$textString: text to be converted
$variantString: the target variant code
$startPosint
$depthInteger: depth of recursion
Returns:
String: converted text

Definition at line 631 of file LanguageConverter.php.

References applyManualConv(), autoConvert(), and wfMsgForContent().

Referenced by recursiveConvertTopLevel().

Here is the call graph for this function:

Here is the caller graph for this function:

LanguageConverter::recursiveConvertTopLevel ( text,
variant,
depth = 0 
) [protected]

Recursively convert text on the outside.

Allow to use nested markups to custom rules.

Parameters:
$textString: text to be converted
$variantString: the target variant code
$depthInteger: depth of recursion
Returns:
String: converted text

Definition at line 594 of file LanguageConverter.php.

References $out, autoConvert(), and recursiveConvertRule().

Referenced by convertTo().

Here is the call graph for this function:

Here is the caller graph for this function:

Reload the conversion tables.

Access:
private

Definition at line 854 of file LanguageConverter.php.

References loadTables().

Referenced by OnArticleSaveComplete().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Parameters:
$textString: text to convert
$variantString: variant language code
Returns:
String: translated text

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().

Here is the call graph for this function:

Here is the caller graph for this function:

LanguageConverter::validateVariant ( variant = null)

Validate the variant.

Parameters:
$variantString: the variant to validate
Returns:
Mixed: returns the variant if it is valid, null otherwise

Definition at line 192 of file LanguageConverter.php.

Referenced by applyManualConv(), getDefaultVariant(), getHeaderVariant(), getPreferredVariant(), getURLVariant(), getUserVariant(), and OnArticleSaveComplete().

Here is the caller graph for this function:


Member Data Documentation

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.

Definition at line 55 of file LanguageConverter.php.

Referenced by loadTables().


The documentation for this class was generated from the following file: