MediaWiki  master
LanguageConverterFactory.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Languages;
22 
23 use CrhConverter;
24 use EnConverter;
25 use GanConverter;
27 use IuConverter;
28 use KkConverter;
29 use KuConverter;
30 use Language;
31 use ShiConverter;
32 use SrConverter;
33 use TgConverter;
35 use UzConverter;
36 use ZhConverter;
37 
45 
46  private $cache = [];
50  private $converterClasses = [
51  'crh' => CrhConverter::class,
52  'gan' => GanConverter::class,
53  'iu' => IuConverter::class,
54  'kk' => KkConverter::class,
55  'ku' => KuConverter::class,
56  'shi' => ShiConverter::class,
57  'sr' => SrConverter::class,
58  'tg' => TgConverter::class,
59  'uz' => UzConverter::class,
60  'zh' => ZhConverter::class,
61  ];
62 
63  private $defaultConverterClass = TrivialLanguageConverter::class;
64 
69 
77  public function __construct( $usePigLatinVariant, callable $defaultLanguage ) {
78  if ( $usePigLatinVariant ) {
79  $this->converterClasses['en'] = EnConverter::class;
80  }
81  $this->defaultLanguage = $defaultLanguage;
82  }
83 
90  private function classFromCode( string $code ) : string {
91  $code = mb_strtolower( $code );
92  return $this->converterClasses[$code] ?? $this->defaultConverterClass;
93  }
94 
104  public function getLanguageConverter( $language = null ) : ILanguageConverter {
105  $lang = $language ?? ( $this->defaultLanguage )();
106  if ( isset( $this->cache[$lang->getCode()] ) ) {
107  return $this->cache[$lang->getCode()];
108  }
109  $class = $this->classFromCode( $lang->getCode() );
110 
111  $converter = new $class( $lang );
112  $this->cache[$lang->getCode()] = $converter;
113  return $converter;
114  }
115 }
MediaWiki\Languages
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
SrConverter
There are two levels of conversion for Serbian: the script level (Cyrillics <-> Latin),...
Definition: SrConverter.php:33
ZhConverter
Definition: ZhConverter.php:27
MediaWiki\Languages\LanguageConverterFactory
An interface for creating language converters.
Definition: LanguageConverterFactory.php:44
MediaWiki\Languages\LanguageConverterFactory\$converterClasses
array $converterClasses
Definition: LanguageConverterFactory.php:50
MediaWiki\Languages\LanguageConverterFactory\getLanguageConverter
getLanguageConverter( $language=null)
Provide a LanguageConverter for given language.
Definition: LanguageConverterFactory.php:104
KkConverter
Kazakh (Қазақша) converter routines.
Definition: KkConverter.php:37
UzConverter
Definition: UzConverter.php:27
MediaWiki\Languages\LanguageConverterFactory\$cache
$cache
Definition: LanguageConverterFactory.php:46
MediaWiki\Languages\LanguageConverterFactory\classFromCode
classFromCode(string $code)
Returns Converter's class name for given language code.
Definition: LanguageConverterFactory.php:90
EnConverter
Definition: EnConverter.php:26
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:28
MediaWiki\Languages\LanguageConverterFactory\$defaultLanguage
callable $defaultLanguage
callback of () : Language
Definition: LanguageConverterFactory.php:68
KuConverter
Kurdish converter routines.
Definition: KuConverter.php:29
CrhConverter
Crimean Tatar (Qırımtatarca) converter routines.
Definition: CrhConverter.php:31
MediaWiki\Languages\LanguageConverterFactory\$defaultConverterClass
$defaultConverterClass
Definition: LanguageConverterFactory.php:63
GanConverter
Definition: GanConverter.php:26
MediaWiki\Languages\LanguageConverterFactory\__construct
__construct( $usePigLatinVariant, callable $defaultLanguage)
Definition: LanguageConverterFactory.php:77
TgConverter
Converts Tajiki to Latin orthography.
Definition: TgConverter.php:29
ShiConverter
Conversion script between Latin and Tifinagh for Tachelhit.
Definition: ShiConverter.php:36
IuConverter
Conversion script between Latin and Syllabics for Inuktitut.
Definition: IuConverter.php:36
TrivialLanguageConverter
A trivial language converter.
Definition: TrivialLanguageConverter.php:36
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:41