MediaWiki  master
ShiConverter.php
Go to the documentation of this file.
1 <?php
37 
38  protected $mDoContentConvert;
39 
40  public $mToLatin = [
41  'ⴰ' => 'a', 'ⴱ' => 'b', 'ⴳ' => 'g', 'ⴷ' => 'd', 'ⴹ' => 'ḍ', 'ⴻ' => 'e',
42  'ⴼ' => 'f', 'ⴽ' => 'k', 'ⵀ' => 'h', 'ⵃ' => 'ḥ', 'ⵄ' => 'ε', 'ⵅ' => 'x',
43  'ⵇ' => 'q', 'ⵉ' => 'i', 'ⵊ' => 'j', 'ⵍ' => 'l', 'ⵎ' => 'm', 'ⵏ' => 'n',
44  'ⵓ' => 'u', 'ⵔ' => 'r', 'ⵕ' => 'ṛ', 'ⵙ' => 's', 'ⵚ' => 'ṣ',
45  'ⵛ' => 'š', 'ⵜ' => 't', 'ⵟ' => 'ṭ', 'ⵡ' => 'w', 'ⵢ' => 'y', 'ⵣ' => 'z',
46  'ⵥ' => 'ẓ', 'ⵯ' => 'ʷ', 'ⵖ' => 'ɣ', 'ⵠ' => 'v', 'ⵒ' => 'p',
47  ];
48 
50  'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e',
51  'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j',
52  'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o',
53  'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't',
54  'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y',
55  'Z' => 'z', 'Ɣ' => 'ɣ',
56  ];
57 
58  public $mToTifinagh = [
59  'a' => 'ⴰ', 'b' => 'ⴱ', 'g' => 'ⴳ', 'd' => 'ⴷ', 'ḍ' => 'ⴹ', 'e' => 'ⴻ',
60  'f' => 'ⴼ', 'k' => 'ⴽ', 'h' => 'ⵀ', 'ḥ' => 'ⵃ', 'ε' => 'ⵄ', 'x' => 'ⵅ',
61  'q' => 'ⵇ', 'i' => 'ⵉ', 'j' => 'ⵊ', 'l' => 'ⵍ', 'm' => 'ⵎ', 'n' => 'ⵏ',
62  'u' => 'ⵓ', 'r' => 'ⵔ', 'ṛ' => 'ⵕ', 'γ' => 'ⵖ', 's' => 'ⵙ', 'ṣ' => 'ⵚ',
63  'š' => 'ⵛ', 't' => 'ⵜ', 'ṭ' => 'ⵟ', 'w' => 'ⵡ', 'y' => 'ⵢ', 'z' => 'ⵣ',
64  'ẓ' => 'ⵥ', 'ʷ' => 'ⵯ', 'ɣ' => 'ⵖ', 'v' => 'ⵠ', 'p' => 'ⵒ',
65  ];
66 
70  public function __construct( $langobj ) {
71  $variants = [ 'shi', 'shi-tfng', 'shi-latn' ];
72  $variantfallbacks = [
73  'shi' => 'shi-tfng',
74  'shi-tfng' => 'shi',
75  'shi-latn' => 'shi',
76  ];
77 
78  $flags = [];
79  parent::__construct( $langobj, 'shi', $variants, $variantfallbacks, $flags );
80  }
81 
82  protected function loadDefaultTables() {
83  $this->mTables = [
84  'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ),
85  'shi-tfng' => new ReplacementArray( $this->mToTifinagh ),
86  'shi-latn' => new ReplacementArray( $this->mToLatin ),
87  'shi' => new ReplacementArray()
88  ];
89  }
90 
99  public function translate( $text, $toVariant ) {
100  // If $text is empty or only includes spaces, do nothing
101  // Otherwise translate it
102  if ( trim( $text ) ) {
103  $this->loadTables();
104  // To Tifinagh, first translate uppercase to lowercase Latin
105  if ( $toVariant == 'shi-tfng' ) {
106  $text = $this->mTables['lowercase']->replace( $text );
107  }
108  $text = $this->mTables[$toVariant]->replace( $text );
109  }
110  return $text;
111  }
112 }
ShiConverter\$mDoContentConvert
$mDoContentConvert
Definition: ShiConverter.php:38
ShiConverter\translate
translate( $text, $toVariant)
It translates text into variant.
Definition: ShiConverter.php:99
ShiConverter\$mToTifinagh
$mToTifinagh
Definition: ShiConverter.php:58
ReplacementArray
Wrapper around strtr() that holds replacements.
Definition: ReplacementArray.php:24
LanguageConverter\loadTables
loadTables( $fromCache=true)
Load conversion tables either from the cache or the disk.
Definition: LanguageConverter.php:979
LanguageConverterSpecific
A class that extends LanguageConverter with specific behaviour.
Definition: LanguageConverterSpecific.php:26
ShiConverter\loadDefaultTables
loadDefaultTables()
Load default conversion tables.
Definition: ShiConverter.php:82
ShiConverter
Conversion script between Latin and Tifinagh for Tachelhit.
Definition: ShiConverter.php:36
ShiConverter\__construct
__construct( $langobj)
Definition: ShiConverter.php:70
ShiConverter\$mToLatin
$mToLatin
Definition: ShiConverter.php:40
ShiConverter\$mUpperToLowerCaseLatin
$mUpperToLowerCaseLatin
Definition: ShiConverter.php:49