MediaWiki REL1_40
LanguageConverterIcu.php
Go to the documentation of this file.
1<?php
28
33
37 protected function loadDefaultTables() {
38 $this->mTables = [];
39 foreach ( $this->getVariants() as $variant ) {
40 $this->mTables[$variant] = new ReplacementArray();
41 }
42 }
43
44 public function translate( $text, $variant ) {
45 $text = parent::translate( $text, $variant );
46 if ( trim( $text ) ) {
47 $text = $this->icuTranslate( $text, $variant );
48 }
49 return $text;
50 }
51
59 public function icuTranslate( $text, $variant ) {
60 return $this->getTransliterators()[$variant]->transliterate( $text );
61 }
62
69 abstract protected function getIcuRules();
70
76 protected function getTransliterators() {
77 if ( $this->mTransliterators === null ) {
78 $this->mTransliterators = [];
79 foreach ( $this->getIcuRules() as $variant => $rule ) {
80 $this->mTransliterators[$variant] = Transliterator::createFromRules( $rule );
81 }
82 foreach ( $this->getTransliteratorAliases() as $alias => $variant ) {
83 $this->mTransliterators[$alias] = $this->mTransliterators[$variant];
84 }
85 }
87 }
88
94 protected function getTransliteratorAliases() {
95 return [];
96 }
97}
A class that extends LanguageConverterSpecific for converts that use ICU rule-based transliterators.
icuTranslate( $text, $variant)
Translate a string to a variant using ICU transliterator.
getIcuRules()
Get the array mapping variants to ICU transliteration rules.
Transliterator[] $mTransliterators
getTransliterators()
Get the array mapping variants to ICU transliterators.
loadDefaultTables()
Creates empty tables.
translate( $text, $variant)
Translate a string to a variant.
getTransliteratorAliases()
Get the array mapping variant aliases to main variant.
A class that extends LanguageConverter with specific behaviour.
getVariants()
Get all valid variants for current Converter.
Wrapper around strtr() that holds replacements.