Wikibase
MediaWiki Wikibase extension
Wikibase\Lib\LanguageFallbackChainFactory Class Reference

Object creating TermLanguageFallbackChain objects in Wikibase. More...

Public Member Functions

 __construct (?LanguageFactory $languageFactory=null, ?LanguageConverterFactory $languageConverterFactory=null, ?LanguageFallback $languageFallback=null)
 
 newFromLanguage (Language $language, $mode=self::FALLBACK_ALL)
 Get the fallback chain based a single language, and specified fallback level. More...
 
 newFromLanguageCode ( $languageCode, $mode=self::FALLBACK_ALL)
 Get the fallback chain based a single language code, and specified fallback level. More...
 
 newFromContext (IContextSource $context)
 Construct the fallback chain based on a context. More...
 
 newFromContextAndLanguageCode (IContextSource $context, $languageCode)
 Construct the fallback chain based on a context, but ignore the language info in it and use a specified one instead. More...
 
 newFromUserAndLanguageCode (User $user, $languageCode)
 Construct the fallback chain based on a user and a language, currently from data provided by Extension:Babel. More...
 
 buildFromBabel (array $babel)
 Build fallback chain array for a given babel array. More...
 

Public Attributes

const FALLBACK_ALL = 0xff
 Fallback levels. More...
 
const FALLBACK_SELF = 1
 The language itself, e.g. More...
 
const FALLBACK_VARIANTS = 2
 Other compatible languages that can be translated into the requested language (and translation is automatically done), e.g. More...
 
const FALLBACK_OTHERS = 4
 All other language from the system fallback chain, e.g. More...
 

Private Member Functions

 buildFromLanguage ( $language, $mode, array $chain=[], array &$fetched=[])
 Build fallback chain array for a given language or validated language code. More...
 
 getBabel ( $languageCode, $user)
 
 getBabelCategoryNames ()
 

Private Attributes

 $languageFactory
 
 $languageConverterFactory
 
 $languageFallback
 
 $languageCache = []
 
 $userLanguageCache = []
 

Detailed Description

Object creating TermLanguageFallbackChain objects in Wikibase.

Author
Liangent < liang.nosp@m.ent@.nosp@m.gmail.nosp@m..com >

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Lib\LanguageFallbackChainFactory::__construct ( ?LanguageFactory  $languageFactory = null,
?LanguageConverterFactory  $languageConverterFactory = null,
?LanguageFallback  $languageFallback = null 
)

Member Function Documentation

◆ buildFromBabel()

Wikibase\Lib\LanguageFallbackChainFactory::buildFromBabel ( array  $babel)

Build fallback chain array for a given babel array.

Parameters
array$babel
Returns
LanguageWithConversion[]

◆ buildFromLanguage()

Wikibase\Lib\LanguageFallbackChainFactory::buildFromLanguage (   $language,
  $mode,
array  $chain = [],
array &  $fetched = [] 
)
private

Build fallback chain array for a given language or validated language code.

Parameters
Language | string$languageLanguage object or language code as string
int$modeBitfield of self::FALLBACK_*
TermLanguageFallbackChain[]$chainfor recursive calls
bool[]$fetchedfor recursive calls
Exceptions
InvalidArgumentException
Returns
LanguageWithConversion[]

◆ getBabel()

Wikibase\Lib\LanguageFallbackChainFactory::getBabel (   $languageCode,
  $user 
)
private

◆ getBabelCategoryNames()

Wikibase\Lib\LanguageFallbackChainFactory::getBabelCategoryNames ( )
private

◆ newFromContext()

Wikibase\Lib\LanguageFallbackChainFactory::newFromContext ( IContextSource  $context)

Construct the fallback chain based on a context.

Currently it just uses user and language info in it.

Parameters
IContextSource$context
Returns
TermLanguageFallbackChain

◆ newFromContextAndLanguageCode()

Wikibase\Lib\LanguageFallbackChainFactory::newFromContextAndLanguageCode ( IContextSource  $context,
  $languageCode 
)

Construct the fallback chain based on a context, but ignore the language info in it and use a specified one instead.

Parameters
IContextSource$context
string$languageCode
Returns
TermLanguageFallbackChain

◆ newFromLanguage()

Wikibase\Lib\LanguageFallbackChainFactory::newFromLanguage ( Language  $language,
  $mode = self::FALLBACK_ALL 
)

Get the fallback chain based a single language, and specified fallback level.

Parameters
Language$language
int$modeBitfield of self::FALLBACK_*
Returns
TermLanguageFallbackChain

◆ newFromLanguageCode()

Wikibase\Lib\LanguageFallbackChainFactory::newFromLanguageCode (   $languageCode,
  $mode = self::FALLBACK_ALL 
)

Get the fallback chain based a single language code, and specified fallback level.

Parameters
string$languageCode
int$modeBitfield of self::FALLBACK_*
Returns
TermLanguageFallbackChain

◆ newFromUserAndLanguageCode()

Wikibase\Lib\LanguageFallbackChainFactory::newFromUserAndLanguageCode ( User  $user,
  $languageCode 
)

Construct the fallback chain based on a user and a language, currently from data provided by Extension:Babel.

Parameters
User$user
string$languageCode
Returns
TermLanguageFallbackChain

Member Data Documentation

◆ $languageCache

Wikibase\Lib\LanguageFallbackChainFactory::$languageCache = []
private

◆ $languageConverterFactory

Wikibase\Lib\LanguageFallbackChainFactory::$languageConverterFactory
private

◆ $languageFactory

Wikibase\Lib\LanguageFallbackChainFactory::$languageFactory
private

◆ $languageFallback

Wikibase\Lib\LanguageFallbackChainFactory::$languageFallback
private

◆ $userLanguageCache

Wikibase\Lib\LanguageFallbackChainFactory::$userLanguageCache = []
private

◆ FALLBACK_ALL

const Wikibase\Lib\LanguageFallbackChainFactory::FALLBACK_ALL = 0xff

Fallback levels.

◆ FALLBACK_OTHERS

const Wikibase\Lib\LanguageFallbackChainFactory::FALLBACK_OTHERS = 4

All other language from the system fallback chain, e.g.

'de' and 'en' for 'de-formal'.

◆ FALLBACK_SELF

const Wikibase\Lib\LanguageFallbackChainFactory::FALLBACK_SELF = 1

The language itself, e.g.

'en' for 'en'.

◆ FALLBACK_VARIANTS

const Wikibase\Lib\LanguageFallbackChainFactory::FALLBACK_VARIANTS = 2

Other compatible languages that can be translated into the requested language (and translation is automatically done), e.g.

'sr', 'sr-ec' and 'sr-el' for 'sr'.


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