Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 185 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
LanguageKk_cyrl | |
0.00% |
0 / 185 |
|
0.00% |
0 / 2 |
12656 | |
0.00% |
0 / 1 |
convertGrammarKk_cyrl | |
0.00% |
0 / 178 |
|
0.00% |
0 / 1 |
11990 | |||
lastLetter | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 |
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 | // phpcs:ignoreFile Squiz.Classes.ValidClassName.NotCamelCaps |
21 | |
22 | use MediaWiki\MainConfigNames; |
23 | use MediaWiki\MediaWikiServices; |
24 | use MediaWiki\Language\Language; |
25 | |
26 | /** |
27 | * Kazakh (Қазақша) |
28 | * |
29 | * @ingroup Languages |
30 | */ |
31 | class LanguageKk_cyrl extends Language { |
32 | /** |
33 | * Convert from the nominative form of a noun to some other case |
34 | * Invoked with {{GRAMMAR:case|word}} |
35 | * |
36 | * Cases: genitive, dative, accusative, locative, ablative, comitative + possessive forms |
37 | * |
38 | * @param string $word |
39 | * @param string $case |
40 | * |
41 | * @return string |
42 | */ |
43 | protected function convertGrammarKk_cyrl( $word, $case ) { |
44 | $grammarForms = |
45 | MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::GrammarForms ); |
46 | if ( isset( $grammarForms['kk-kz'][$case][$word] ) ) { |
47 | return $grammarForms['kk-kz'][$case][$word]; |
48 | } |
49 | if ( isset( $grammarForms['kk-cyrl'][$case][$word] ) ) { |
50 | return $grammarForms['kk-cyrl'][$case][$word]; |
51 | } |
52 | // Set up some constants... |
53 | // Vowels in last syllable |
54 | $frontVowels = [ "е", "ө", "ү", "і", "ә", "э", "я", "ё", "и" ]; |
55 | $backVowels = [ "а", "о", "ұ", "ы" ]; |
56 | $allVowels = [ "е", "ө", "ү", "і", "ә", "э", "а", "о", "ұ", "ы", "я", "ё", "и" ]; |
57 | // Preceding letters |
58 | $Nasals = [ "м", "н", "ң" ]; |
59 | $Sonants = [ "и", "й", "л", "р", "у", "ю" ]; |
60 | $Consonants = [ "п", "ф", "к", "қ", "т", "ш", "с", "х", "ц", "ч", "щ", "б", "в", "г", "д" ]; |
61 | $Sibilants = [ "ж", "з" ]; |
62 | $Sonorants = [ "и", "й", "л", "р", "у", "ю", "м", "н", "ң", "ж", "з" ]; |
63 | |
64 | // Possessives |
65 | $firstPerson = [ "м", "ң" ]; // 1st singular, 2nd informal |
66 | $secondPerson = [ "з" ]; // 1st plural, 2nd formal |
67 | $thirdPerson = [ "ы", "і" ]; // 3rd |
68 | |
69 | [ $wordEnding, $wordLastVowel ] = $this->lastLetter( $word, $allVowels ); |
70 | |
71 | // Now convert the word |
72 | switch ( $case ) { |
73 | case "dc1": |
74 | case "genitive": # ilik |
75 | if ( in_array( $wordEnding, $Consonants ) ) { |
76 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
77 | $word .= "тің"; |
78 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
79 | $word .= "тың"; |
80 | } |
81 | } elseif ( in_array( $wordEnding, $allVowels ) || in_array( $wordEnding, $Nasals ) ) { |
82 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
83 | $word .= "нің"; |
84 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
85 | $word .= "ның"; |
86 | } |
87 | } elseif ( in_array( $wordEnding, $Sonants ) || in_array( $wordEnding, $Sibilants ) ) { |
88 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
89 | $word .= "дің"; |
90 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
91 | $word .= "дың"; |
92 | } |
93 | } |
94 | break; |
95 | |
96 | case "dc2": |
97 | case "dative": # barıs |
98 | if ( in_array( $wordEnding, $Consonants ) ) { |
99 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
100 | $word .= "ке"; |
101 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
102 | $word .= "қа"; |
103 | } |
104 | } elseif ( in_array( $wordEnding, $allVowels ) || in_array( $wordEnding, $Sonorants ) ) { |
105 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
106 | $word .= "ге"; |
107 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
108 | $word .= "ға"; |
109 | } |
110 | } |
111 | break; |
112 | |
113 | case "dc21": |
114 | case "possessive dative": # täweldık + barıs |
115 | if ( in_array( $wordEnding, $firstPerson ) ) { |
116 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
117 | $word .= "е"; |
118 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
119 | $word .= "а"; |
120 | } |
121 | } elseif ( in_array( $wordEnding, $secondPerson ) ) { |
122 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
123 | $word .= "ге"; |
124 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
125 | $word .= "ға"; |
126 | } |
127 | } elseif ( in_array( $wordEnding, $thirdPerson ) ) { |
128 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
129 | $word .= "не"; |
130 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
131 | $word .= "на"; |
132 | } |
133 | } |
134 | break; |
135 | |
136 | case "dc3": |
137 | case "accusative": # tabıs |
138 | if ( in_array( $wordEnding, $Consonants ) ) { |
139 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
140 | $word .= "ті"; |
141 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
142 | $word .= "ты"; |
143 | } |
144 | } elseif ( in_array( $wordEnding, $allVowels ) ) { |
145 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
146 | $word .= "ні"; |
147 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
148 | $word .= "ны"; |
149 | } |
150 | } elseif ( in_array( $wordEnding, $Sonorants ) ) { |
151 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
152 | $word .= "ді"; |
153 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
154 | $word .= "ды"; |
155 | } |
156 | } |
157 | break; |
158 | |
159 | case "dc31": |
160 | case "possessive accusative": # täweldık + tabıs |
161 | if ( in_array( $wordEnding, $firstPerson ) || in_array( $wordEnding, $secondPerson ) ) { |
162 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
163 | $word .= "ді"; |
164 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
165 | $word .= "ды"; |
166 | } |
167 | } elseif ( in_array( $wordEnding, $thirdPerson ) ) { |
168 | $word .= "н"; |
169 | } |
170 | break; |
171 | |
172 | case "dc4": |
173 | case "locative": # jatıs |
174 | if ( in_array( $wordEnding, $Consonants ) ) { |
175 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
176 | $word .= "те"; |
177 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
178 | $word .= "та"; |
179 | } |
180 | } elseif ( in_array( $wordEnding, $allVowels ) || in_array( $wordEnding, $Sonorants ) ) { |
181 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
182 | $word .= "де"; |
183 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
184 | $word .= "да"; |
185 | } |
186 | } |
187 | break; |
188 | |
189 | case "dc41": |
190 | case "possessive locative": # täweldık + jatıs |
191 | if ( in_array( $wordEnding, $firstPerson ) || in_array( $wordEnding, $secondPerson ) ) { |
192 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
193 | $word .= "де"; |
194 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
195 | $word .= "да"; |
196 | } |
197 | } elseif ( in_array( $wordEnding, $thirdPerson ) ) { |
198 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
199 | $word .= "нде"; |
200 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
201 | $word .= "нда"; |
202 | } |
203 | } |
204 | break; |
205 | |
206 | case "dc5": |
207 | case "ablative": # şığıs |
208 | if ( in_array( $wordEnding, $Consonants ) ) { |
209 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
210 | $word .= "тен"; |
211 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
212 | $word .= "тан"; |
213 | } |
214 | } elseif ( in_array( $wordEnding, $allVowels ) |
215 | || in_array( $wordEnding, $Sonants ) |
216 | || in_array( $wordEnding, $Sibilants ) |
217 | ) { |
218 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
219 | $word .= "ден"; |
220 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
221 | $word .= "дан"; |
222 | } |
223 | } elseif ( in_array( $wordEnding, $Nasals ) ) { |
224 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
225 | $word .= "нен"; |
226 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
227 | $word .= "нан"; |
228 | } |
229 | } |
230 | break; |
231 | |
232 | case "dc51": |
233 | case "possessive ablative": # täweldık + şığıs |
234 | if ( in_array( $wordEnding, $firstPerson ) || in_array( $wordEnding, $thirdPerson ) ) { |
235 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
236 | $word .= "нен"; |
237 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
238 | $word .= "нан"; |
239 | } |
240 | } elseif ( in_array( $wordEnding, $secondPerson ) ) { |
241 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
242 | $word .= "ден"; |
243 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
244 | $word .= "дан"; |
245 | } |
246 | } |
247 | break; |
248 | |
249 | case "dc6": |
250 | case "comitative": # kömektes |
251 | if ( in_array( $wordEnding, $Consonants ) ) { |
252 | $word .= "пен"; |
253 | } elseif ( in_array( $wordEnding, $allVowels ) |
254 | || in_array( $wordEnding, $Nasals ) |
255 | || in_array( $wordEnding, $Sonants ) |
256 | ) { |
257 | $word .= "мен"; |
258 | } elseif ( in_array( $wordEnding, $Sibilants ) ) { |
259 | $word .= "бен"; |
260 | } |
261 | break; |
262 | case "dc61": |
263 | case "possessive comitative": # täweldık + kömektes |
264 | if ( in_array( $wordEnding, $Consonants ) ) { |
265 | $word .= "пенен"; |
266 | } elseif ( in_array( $wordEnding, $allVowels ) |
267 | || in_array( $wordEnding, $Nasals ) |
268 | || in_array( $wordEnding, $Sonants ) |
269 | ) { |
270 | $word .= "менен"; |
271 | } elseif ( in_array( $wordEnding, $Sibilants ) ) { |
272 | $word .= "бенен"; |
273 | } |
274 | break; |
275 | |
276 | default: # dc0 #nominative #ataw |
277 | break; |
278 | } |
279 | return $word; |
280 | } |
281 | |
282 | /** |
283 | * @param string $word |
284 | * @param string[] $allVowels |
285 | * @return array |
286 | */ |
287 | private function lastLetter( $word, $allVowels ) { |
288 | // Put the word in a form we can play with since we're using UTF-8 |
289 | $ar = mb_str_split( $this->lc( $word ), 1 ); |
290 | |
291 | // Here's the last letter in the word |
292 | $lastLetter = end( $ar ); |
293 | |
294 | // Find the last vowel in the word |
295 | for ( $i = count( $ar ); $i--; ) { |
296 | $lastVowel = $ar[$i]; |
297 | if ( in_array( $lastVowel, $allVowels, true ) ) { |
298 | return [ $lastLetter, $lastVowel ]; |
299 | } |
300 | } |
301 | |
302 | return [ $lastLetter, null ]; |
303 | } |
304 | } |