Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 185
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
LanguageKk_cyrl
0.00% covered (danger)
0.00%
0 / 185
0.00% covered (danger)
0.00%
0 / 2
12656
0.00% covered (danger)
0.00%
0 / 1
 convertGrammarKk_cyrl
0.00% covered (danger)
0.00%
0 / 178
0.00% covered (danger)
0.00%
0 / 1
11990
 lastLetter
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
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
22use MediaWiki\MainConfigNames;
23use MediaWiki\MediaWikiServices;
24
25/**
26 * Kazakh (Қазақша)
27 *
28 * @ingroup Languages
29 */
30class LanguageKk_cyrl extends Language {
31    /**
32     * Convert from the nominative form of a noun to some other case
33     * Invoked with {{GRAMMAR:case|word}}
34     *
35     * Cases: genitive, dative, accusative, locative, ablative, comitative + possessive forms
36     *
37     * @param string $word
38     * @param string $case
39     *
40     * @return string
41     */
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
281    /**
282     * @param string $word
283     * @param string[] $allVowels
284     * @return array
285     */
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}