MediaWiki REL1_35
LanguageConverterFactory.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Languages;
22
23use CrhConverter;
24use EnConverter;
25use GanConverter;
27use IuConverter;
28use KkConverter;
29use KuConverter;
30use Language;
31use ShiConverter;
32use SrConverter;
33use TgConverter;
35use UzConverter;
36use ZhConverter;
37
45
46 private $cache = [];
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}
Crimean Tatar (Qırımtatarca) converter routines.
Conversion script between Latin and Syllabics for Inuktitut.
Kazakh (Қазақша) converter routines.
Kurdish converter routines.
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition Language.php:41
An interface for creating language converters.
classFromCode(string $code)
Returns Converter's class name for given language code.
__construct( $usePigLatinVariant, callable $defaultLanguage)
getLanguageConverter( $language=null)
Provide a LanguageConverter for given language.
Conversion script between Latin and Tifinagh for Tachelhit.
There are two levels of conversion for Serbian: the script level (Cyrillics <-> Latin),...
Converts Tajiki to Latin orthography.
A trivial language converter.
The shared interface for all language converters.
if(!isset( $args[0])) $lang