BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
LanguageConverter Class Reference
Inheritance diagram for LanguageConverter:

Public Member Functions

 __construct ($langobj, $maincode, $variants=[], $variantfallbacks=[], $flags=[], $manualLevel=[])
 
 getVariants ()
 
 getVariantFallbacks ($variant)
 
 getConvRuleTitle ()
 
 getPreferredVariant ()
 
 getDefaultVariant ()
 
 validateVariant ($variant=null)
 
 getURLVariant ()
 
 autoConvert ($text, $toVariant=false)
 
 translate ($text, $variant)
 
 autoConvertToAllVariants ($text)
 
 convertTitle ($title)
 
 convertNamespace ($index, $variant=null)
 
 convert ($text)
 
 convertTo ($text, $variant)
 
 findVariantLink (&$link, &$nt, $ignoreOtherCond=false)
 
 getExtraHashOptions ()
 
 guessVariant ($text, $variant)
 
 postLoadTables ()
 
 parseCachedTable ($code, $subpage= '', $recursive=true)
 
 markNoConversion ($text, $noParse=false)
 
 convertCategoryKey ($key)
 
 updateConversionTable (Title $titleobj)
 
 getVarSeparatorPattern ()
 

Public Attributes

 $mMainLanguageCode
 
 $mVariants
 
 $mVariantFallbacks
 
 $mVariantNames
 
 $mTablesLoaded = false
 
 $mTables
 
 $mManualLevel
 
 $mCacheKey
 
 $mLangObj
 
 $mFlags
 
 $mDescCodeSep = ':'
 
 $mDescVarSep = ';'
 
 $mUcfirst = false
 
 $mConvRuleTitle = false
 
 $mURLVariant
 
 $mUserVariant
 
 $mHeaderVariant
 
 $mMaxDepth = 10
 
 $mVarSeparatorPattern
 
const CACHE_VERSION_KEY = 'VERSION 7'
 

Static Public Attributes

static $languagesWithVariants
 

Protected Member Functions

 getUserVariant ()
 
 getHeaderVariant ()
 
 applyManualConv ($convRule)
 
 recursiveConvertTopLevel ($text, $variant, $depth=0)
 
 recursiveConvertRule ($text, $variant, &$startPos, $depth=0)
 

Detailed Description

Constructor & Destructor Documentation

LanguageConverter::__construct (   $langobj,
  $maincode,
  $variants = [],
  $variantfallbacks = [],
  $flags = [],
  $manualLevel = [] 
)

Constructor

Parameters
Language$langobj
string$maincodeThe main language code of this language
array$variantsThe supported variants of this language
array$variantfallbacksThe fallback language of each variant
array$flagsDefining the custom strings that maps to the flags
array$manualLevelLimit for supported variants

Member Function Documentation

LanguageConverter::applyManualConv (   $convRule)
protected

Apply manual conversion rules.

Parameters
ConverterRule$convRule
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
string$textThe text to be converted
bool | string$toVariantThe target language code
Returns
string The converted text
LanguageConverter::autoConvertToAllVariants (   $text)

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

Parameters
string$textThe text to be converted
Returns
array Variant => converted text
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

Parameters
string$textText to be converted
Returns
string Converted text
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.

Parameters
string$key
Returns
string
LanguageConverter::convertNamespace (   $index,
  $variant = null 
)

Get the namespace display name in the preferred variant.

Parameters
int$indexNamespace id
string | null$variantVariant code or null for preferred variant
Returns
string Namespace name for display
LanguageConverter::convertTitle (   $title)

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

Parameters
Title$titleA object of Title
Returns
string Converted title text
LanguageConverter::convertTo (   $text,
  $variant 
)

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

Parameters
string$textText to be converted
string$variantThe target variant code
Returns
string Converted text
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

Parameters
string&$linkThe name of the link
Title&$ntThe title object of the link
bool$ignoreOtherCondTo disable other conditions when we need to transclude a template or update a category's link
LanguageConverter::getConvRuleTitle ( )

Get the title produced by the conversion rule.

Returns
string The converted title text
LanguageConverter::getDefaultVariant ( )

Get default variant. This function would not be affected by user's settings

Returns
string The default variant code
LanguageConverter::getExtraHashOptions ( )

Returns language specific hash options.

Returns
string
LanguageConverter::getHeaderVariant ( )
protected

Determine the language variant from the Accept-Language header.

Returns
mixed Variant if one found, false otherwise.
LanguageConverter::getPreferredVariant ( )

Get preferred language variant.

Returns
string The preferred language code
LanguageConverter::getURLVariant ( )

Get the variant specified in the URL

Returns
mixed Variant if one found, false otherwise.
LanguageConverter::getUserVariant ( )
protected

Determine if the user has a variant set.

Returns
mixed Variant if one found, false otherwise.
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.

Parameters
string$variantThe language code of the variant
Returns
string|array The code of the fallback language or the main code if there is no fallback
LanguageConverter::getVariants ( )

Get all valid variants. Call this instead of using $this->mVariants directly.

Returns
array Contains all valid variants
LanguageConverter::getVarSeparatorPattern ( )

Get the cached separator pattern for ConverterRule::parseRules()

Returns
string
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 smole.nosp@m.nsk@.nosp@m.eunet.nosp@m..rs
Since
1.19
LanguageConverter::markNoConversion (   $text,
  $noParse = false 
)

Enclose a string with the "no conversion" tag. This is used by various functions in the Parser.

Parameters
string$textText to be tagged for no conversion
bool$noParseUnused
Returns
string The tagged text
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
string$codeLanguage code
string$subpageSubpage name
bool$recursiveParse subpages recursively? Defaults to true.
Returns
array
LanguageConverter::postLoadTables ( )

Hook for post processing after conversion tables are loaded.

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

Recursively convert text on the inside.

Parameters
string$textText to be converted
string$variantThe target variant code
int$startPos
int$depthDepth of recursion
Exceptions
MWException
Returns
string Converted text
LanguageConverter::recursiveConvertTopLevel (   $text,
  $variant,
  $depth = 0 
)
protected

Recursively convert text on the outside. Allow to use nested markups to custom rules.

Parameters
string$textText to be converted
string$variantThe target variant code
int$depthDepth of recursion
Returns
string Converted text
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
string$textText to convert
string$variantVariant language code
Returns
string Translated text
LanguageConverter::updateConversionTable ( Title  $titleobj)

Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.

Parameters
Title$titleobjThe Title of the page being updated
LanguageConverter::validateVariant (   $variant = null)

Validate the variant

Parameters
string$variantThe variant to validate
Returns
mixed Returns the variant if it is valid, null otherwise

Member Data Documentation

LanguageConverter::$languagesWithVariants
static
Initial value:
= [
'gan',
'iu',
'kk',
'ku',
'shi',
'sr',
'tg',
'uz',
'zh',
]

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