Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
73.68% |
14 / 19 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
ShiConverter | |
73.68% |
14 / 19 |
|
80.00% |
4 / 5 |
7.89 | |
0.00% |
0 / 1 |
getMainCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLanguageVariants | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getVariantsFallbacks | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
loadDefaultTables | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
translate | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | /** |
22 | * Shilha specific code. |
23 | * |
24 | * Conversion script between Latin and Tifinagh for Tachelhit. |
25 | * - Tifinagh -> lowercase Latin |
26 | * - lowercase/uppercase Latin -> Tifinagh |
27 | * |
28 | * |
29 | * Based on: |
30 | * - https://en.wikipedia.org/wiki/Shilha_language |
31 | * - LanguageSr.php |
32 | * |
33 | * @ingroup Languages |
34 | */ |
35 | class ShiConverter extends LanguageConverterSpecific { |
36 | /** |
37 | * The Tifinagh alphabet sequence is based on |
38 | * "Dictionnaire Général de la Langue Amazighe Informatisé" |
39 | * by IRCAM (https://tal.ircam.ma/dglai/lexieam.php, DGLAi), |
40 | * with the labio-velarization mark in the end |
41 | */ |
42 | private const TO_LATIN = [ |
43 | 'ⴰ' => 'a', |
44 | 'ⴱ' => 'b', |
45 | 'ⴳ' => 'g', |
46 | 'ⴷ' => 'd', |
47 | 'ⴹ' => 'ḍ', |
48 | 'ⴻ' => 'e', |
49 | 'ⴼ' => 'f', |
50 | 'ⴽ' => 'k', |
51 | 'ⵀ' => 'h', |
52 | 'ⵃ' => 'ḥ', |
53 | 'ⵄ' => 'ɛ', |
54 | 'ⵅ' => 'x', |
55 | 'ⵇ' => 'q', |
56 | 'ⵉ' => 'i', |
57 | 'ⵊ' => 'j', |
58 | 'ⵍ' => 'l', |
59 | 'ⵎ' => 'm', |
60 | 'ⵏ' => 'n', |
61 | 'ⵓ' => 'u', |
62 | 'ⵔ' => 'r', |
63 | 'ⵕ' => 'ṛ', |
64 | 'ⵖ' => 'ɣ', |
65 | 'ⵙ' => 's', |
66 | 'ⵚ' => 'ṣ', |
67 | 'ⵛ' => 'c', |
68 | 'ⵜ' => 't', |
69 | 'ⵟ' => 'ṭ', |
70 | 'ⵡ' => 'w', |
71 | 'ⵢ' => 'y', |
72 | 'ⵣ' => 'z', |
73 | 'ⵥ' => 'ẓ', |
74 | 'ⵯ' => 'ʷ', |
75 | ]; |
76 | |
77 | /** The sequence is based on DGLAi, with the non-standard letters in the end */ |
78 | private const UPPER_TO_LOWER_CASE_LATIN = [ |
79 | 'A' => 'a', |
80 | 'B' => 'b', |
81 | 'G' => 'g', |
82 | 'D' => 'd', |
83 | 'Ḍ' => 'ḍ', |
84 | 'E' => 'e', |
85 | 'F' => 'f', |
86 | 'K' => 'k', |
87 | 'H' => 'h', |
88 | 'Ḥ' => 'ḥ', |
89 | 'Ɛ' => 'ɛ', |
90 | 'X' => 'x', |
91 | 'Q' => 'q', |
92 | 'I' => 'i', |
93 | 'J' => 'j', |
94 | 'L' => 'l', |
95 | 'M' => 'm', |
96 | 'N' => 'n', |
97 | 'U' => 'u', |
98 | 'R' => 'r', |
99 | 'Ṛ' => 'ṛ', |
100 | 'Ɣ' => 'ɣ', |
101 | 'S' => 's', |
102 | 'Ṣ' => 'ṣ', |
103 | 'C' => 'c', |
104 | 'T' => 't', |
105 | 'Ṭ' => 'ṭ', |
106 | 'W' => 'w', |
107 | 'Y' => 'y', |
108 | 'Z' => 'z', |
109 | 'Ẓ' => 'ẓ', |
110 | 'O' => 'o', |
111 | 'P' => 'p', |
112 | 'V' => 'v', |
113 | ]; |
114 | |
115 | /** |
116 | * The sequence is based on DGLAi, with the labio-velarization mark and |
117 | * the non-standard letters in the end |
118 | */ |
119 | private const TO_TIFINAGH = [ |
120 | 'a' => 'ⴰ', |
121 | 'b' => 'ⴱ', |
122 | 'g' => 'ⴳ', |
123 | 'd' => 'ⴷ', |
124 | 'ḍ' => 'ⴹ', |
125 | 'e' => 'ⴻ', |
126 | 'f' => 'ⴼ', |
127 | 'k' => 'ⴽ', |
128 | 'h' => 'ⵀ', |
129 | 'ḥ' => 'ⵃ', |
130 | 'ɛ' => 'ⵄ', |
131 | 'x' => 'ⵅ', |
132 | 'q' => 'ⵇ', |
133 | 'i' => 'ⵉ', |
134 | 'j' => 'ⵊ', |
135 | 'l' => 'ⵍ', |
136 | 'm' => 'ⵎ', |
137 | 'n' => 'ⵏ', |
138 | 'u' => 'ⵓ', |
139 | 'r' => 'ⵔ', |
140 | 'ṛ' => 'ⵕ', |
141 | 'ɣ' => 'ⵖ', |
142 | 's' => 'ⵙ', |
143 | 'ṣ' => 'ⵚ', |
144 | 'c' => 'ⵛ', |
145 | 't' => 'ⵜ', |
146 | 'ṭ' => 'ⵟ', |
147 | 'w' => 'ⵡ', |
148 | 'y' => 'ⵢ', |
149 | 'z' => 'ⵣ', |
150 | 'ẓ' => 'ⵥ', |
151 | 'ʷ' => 'ⵯ', |
152 | 'o' => 'ⵓ', |
153 | 'p' => 'ⴱ', |
154 | 'v' => 'ⴼ', |
155 | ]; |
156 | |
157 | public function getMainCode(): string { |
158 | return 'shi'; |
159 | } |
160 | |
161 | public function getLanguageVariants(): array { |
162 | return [ 'shi', 'shi-tfng', 'shi-latn' ]; |
163 | } |
164 | |
165 | public function getVariantsFallbacks(): array { |
166 | return [ |
167 | 'shi' => [ 'shi-latn', 'shi-tfng' ], |
168 | 'shi-tfng' => 'shi', |
169 | 'shi-latn' => 'shi', |
170 | ]; |
171 | } |
172 | |
173 | protected function loadDefaultTables(): array { |
174 | return [ |
175 | 'lowercase' => new ReplacementArray( self::UPPER_TO_LOWER_CASE_LATIN ), |
176 | 'shi-tfng' => new ReplacementArray( self::TO_TIFINAGH ), |
177 | 'shi-latn' => new ReplacementArray( self::TO_LATIN ), |
178 | 'shi' => new ReplacementArray() |
179 | ]; |
180 | } |
181 | |
182 | public function translate( $text, $toVariant ) { |
183 | // If $text is empty or only includes spaces, do nothing |
184 | // Otherwise translate it |
185 | if ( trim( $text ) ) { |
186 | $this->loadTables(); |
187 | // For Tifinagh, first translate uppercase to lowercase Latin |
188 | if ( $toVariant == 'shi-tfng' ) { |
189 | $text = $this->mTables['lowercase']->replace( $text ); |
190 | } |
191 | $text = $this->mTables[$toVariant]->replace( $text ); |
192 | } |
193 | return $text; |
194 | } |
195 | } |