Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 137 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
LanguageTyv | |
0.00% |
0 / 137 |
|
0.00% |
0 / 1 |
4422 | |
0.00% |
0 / 1 |
convertGrammar | |
0.00% |
0 / 137 |
|
0.00% |
0 / 1 |
4422 |
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 | use MediaWiki\Language\Language; |
22 | use MediaWiki\MainConfigNames; |
23 | use MediaWiki\MediaWikiServices; |
24 | |
25 | /** |
26 | * Tyvan localization (Тыва дыл) |
27 | * |
28 | * From friends at tyvawiki.org |
29 | * |
30 | * @ingroup Languages |
31 | */ |
32 | class LanguageTyv extends Language { |
33 | |
34 | public function convertGrammar( $word, $case ) { |
35 | $grammarForms = |
36 | MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::GrammarForms ); |
37 | if ( isset( $grammarForms['tyv'][$case][$word] ) ) { |
38 | return $grammarForms['tyv'][$case][$word]; |
39 | } |
40 | |
41 | // Set up some constants... |
42 | $allVowels = [ "е", "и", "э", "ө", "ү", "а", "ё", "о", "у", "ы", "ю", "я" ]; |
43 | $frontVowels = [ "е", "и", "э", "ө", "ү" ]; |
44 | $backVowels = [ "а", "ё", "о", "у", "ы", "ю", "я" ]; |
45 | $unroundFrontVowels = [ "е", "и", "э" ]; |
46 | $roundFrontVowels = [ "ө", "ү" ]; |
47 | $unroundBackVowels = [ "а", "ы", "я" ]; |
48 | $roundBackVowels = [ "ё", "о", "у", "ю" ]; |
49 | $unvoicedPhonemes = [ "т", "п", "с", "ш", "к", "ч", "х" ]; |
50 | $directiveUnvoicedStems = [ "т", "п", "с", "ш", "к", "ч", "х", "л", "м", "н", "ң" ]; |
51 | $directiveVoicedStems = [ "д", "б", "з", "ж", "г", "р", "й" ]; |
52 | |
53 | // Put the word in a form we can play with since we're using UTF-8 |
54 | $ar = mb_str_split( $word, 1 ); |
55 | |
56 | // Here's the last letter in the word |
57 | $wordEnding = end( $ar ); |
58 | |
59 | // Find the last vowel in the word |
60 | $wordLastVowel = null; |
61 | for ( $i = count( $ar ); $i--; ) { |
62 | if ( in_array( $ar[$i], $allVowels, true ) ) { |
63 | $wordLastVowel = $ar[$i]; |
64 | break; |
65 | } |
66 | } |
67 | |
68 | // Now convert the word |
69 | switch ( $case ) { |
70 | case "genitive": |
71 | if ( in_array( $wordEnding, $unvoicedPhonemes ) ) { |
72 | if ( in_array( $wordLastVowel, $roundFrontVowels ) ) { |
73 | $word .= "түң"; |
74 | } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) { |
75 | $word .= "тиң"; |
76 | } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) { |
77 | $word .= "туң"; |
78 | } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) { |
79 | $word .= "тың"; |
80 | } |
81 | } elseif ( $wordEnding === "л" ) { |
82 | if ( in_array( $wordLastVowel, $roundFrontVowels ) ) { |
83 | $word .= "дүң"; |
84 | } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) { |
85 | $word .= "диң"; |
86 | } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) { |
87 | $word .= "дуң"; |
88 | } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) { |
89 | $word .= "дың"; |
90 | } |
91 | } else { |
92 | if ( in_array( $wordLastVowel, $roundFrontVowels ) ) { |
93 | $word .= "нүң"; |
94 | } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) { |
95 | $word .= "ниң"; |
96 | } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) { |
97 | $word .= "нуң"; |
98 | } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) { |
99 | $word .= "ның"; |
100 | } |
101 | } |
102 | break; |
103 | |
104 | case "dative": |
105 | if ( in_array( $wordEnding, $unvoicedPhonemes ) ) { |
106 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
107 | $word .= "ке"; |
108 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
109 | $word .= "ка"; |
110 | } |
111 | } else { |
112 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
113 | $word .= "ге"; |
114 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
115 | $word .= "га"; |
116 | } |
117 | } |
118 | break; |
119 | |
120 | case "accusative": |
121 | if ( in_array( $wordEnding, $unvoicedPhonemes ) ) { |
122 | if ( in_array( $wordLastVowel, $roundFrontVowels ) ) { |
123 | $word .= "тү"; |
124 | } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) { |
125 | $word .= "ти"; |
126 | } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) { |
127 | $word .= "ту"; |
128 | } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) { |
129 | $word .= "ты"; |
130 | } |
131 | } elseif ( $wordEnding === "л" ) { |
132 | if ( in_array( $wordLastVowel, $roundFrontVowels ) ) { |
133 | $word .= "дү"; |
134 | } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) { |
135 | $word .= "ди"; |
136 | } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) { |
137 | $word .= "ду"; |
138 | } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) { |
139 | $word .= "ды"; |
140 | } |
141 | } else { |
142 | if ( in_array( $wordLastVowel, $roundFrontVowels ) ) { |
143 | $word .= "нү"; |
144 | } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) { |
145 | $word .= "ни"; |
146 | } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) { |
147 | $word .= "ну"; |
148 | } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) { |
149 | $word .= "ны"; |
150 | } |
151 | } |
152 | break; |
153 | |
154 | case "locative": |
155 | if ( in_array( $wordEnding, $unvoicedPhonemes ) ) { |
156 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
157 | $word .= "те"; |
158 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
159 | $word .= "та"; |
160 | } |
161 | } else { |
162 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
163 | $word .= "де"; |
164 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
165 | $word .= "да"; |
166 | } |
167 | } |
168 | break; |
169 | |
170 | case "ablative": |
171 | if ( in_array( $wordEnding, $unvoicedPhonemes ) ) { |
172 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
173 | $word .= "тен"; |
174 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
175 | $word .= "тан"; |
176 | } |
177 | } else { |
178 | if ( in_array( $wordLastVowel, $frontVowels ) ) { |
179 | $word .= "ден"; |
180 | } elseif ( in_array( $wordLastVowel, $backVowels ) ) { |
181 | $word .= "дан"; |
182 | } |
183 | } |
184 | break; |
185 | |
186 | case "directive1": |
187 | if ( in_array( $wordEnding, $directiveVoicedStems ) ) { |
188 | $word .= "же"; |
189 | } elseif ( in_array( $wordEnding, $directiveUnvoicedStems ) ) { |
190 | $word .= "че"; |
191 | } |
192 | break; |
193 | |
194 | case "directive2": |
195 | if ( in_array( $wordEnding, $unvoicedPhonemes ) ) { |
196 | if ( in_array( $wordLastVowel, $roundFrontVowels ) ) { |
197 | $word .= "түве"; |
198 | } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) { |
199 | $word .= "тиве"; |
200 | } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) { |
201 | $word .= "туве"; |
202 | } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) { |
203 | $word .= "тыве"; |
204 | } |
205 | } else { |
206 | if ( in_array( $wordLastVowel, $roundFrontVowels ) ) { |
207 | $word .= "дүве"; |
208 | } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) { |
209 | $word .= "диве"; |
210 | } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) { |
211 | $word .= "дуве"; |
212 | } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) { |
213 | $word .= "дыве"; |
214 | } |
215 | } |
216 | break; |
217 | |
218 | default: |
219 | break; |
220 | } |
221 | |
222 | return $word; |
223 | } |
224 | } |