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