MediaWiki  REL1_22
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.
 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.

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 84 of file LanguageConverter.php.


Member Function Documentation

LanguageConverter::applyManualConv ( convRule) [protected]

Apply manual conversion rules.

Parameters:
$convRuleConverterRule Object of ConverterRule

Definition at line 512 of file LanguageConverter.php.

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;
Deprecated:
since 1.22 is no longer used

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

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 337 of file LanguageConverter.php.

Referenced by GanConverter\convertCategoryKey(), and ZhConverter\convertCategoryKey().

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

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

Definition at line 479 of file LanguageConverter.php.

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

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

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

Definition at line 503 of file LanguageConverter.php.

LanguageConverter::convertNamespace ( index,
variant = null 
)

Get the namespace display name in the preferred variant.

Parameters:
$indexint namespace id
$variantstring|null variant code or null for preferred variant
Returns:
String: namespace name for display

Definition at line 572 of file LanguageConverter.php.

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 553 of file LanguageConverter.php.

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 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

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 761 of file LanguageConverter.php.

Get the title produced by the conversion rule.

Returns:
String: The converted title text

Definition at line 151 of file LanguageConverter.php.

Get default variant.

This function would not be affected by user's settings

Returns:
String: the default variant code

Definition at line 189 of file LanguageConverter.php.

Returns language specific hash options.

Returns:
string

Definition at line 827 of file LanguageConverter.php.

Determine the language variant from the Accept-Language header.

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

Definition at line 280 of file LanguageConverter.php.

Get preferred language variant.

Returns:
String: the preferred language code

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.

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

Definition at line 225 of file LanguageConverter.php.

Determine if the user has a variant set.

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

Definition at line 247 of file LanguageConverter.php.

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 140 of file LanguageConverter.php.

Get all valid variants.

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

Returns:
Array: contains all valid variants

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.

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 842 of file LanguageConverter.php.

Load default conversion tables.

This method must be implemented in derived class.

Access:
private
Exceptions:
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.

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

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

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.

Parameters:
$pageWikiPage object
$userObject: User object for the current user
$contentContent: new page content
$summaryString: edit summary of the edit
$isMinorBoolean: was the edit marked as minor?
$isWatchBoolean: did the user watch this page or not?
$section
$flagsint Bitfield
$revisionObject: new Revision object or null
Returns:
Boolean: true

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.

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

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.

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

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.

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

Definition at line 641 of file LanguageConverter.php.

Reload the conversion tables.

Access:
private

Definition at line 909 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().

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

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

Definition at line 461 of file LanguageConverter.php.

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 213 of file LanguageConverter.php.


Member Data Documentation

LanguageConverter::$languagesWithVariants [static]
Initial value:
 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.

memcached key name

Definition at line 59 of file LanguageConverter.php.

Definition at line 72 of file LanguageConverter.php.


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