f01251c00dfef067d8168a9eba28d58faa1006e9
[lhc/web/wiklou.git] / languages / classes / LanguageKk_kz.php
1 <?php
2 /** Kazakh (Қазақша)
3 *
4 *
5 * @package MediaWiki
6 * @subpackage Language
7 */
8
9
10 class LanguageKk_kz extends Language {
11
12 # Convert from the nominative form of a noun to some other case
13 # Invoked with {{GRAMMAR:case|word}}
14 /**
15 * Cases: genitive, dative, accusative, locative, ablative, comitative + possessive forms
16 */
17 function convertGrammar( $word, $case ) {
18 global $wgGrammarForms;
19 if ( isset( $wgGrammarForms['kk'][$case][$word] ) ) {
20 return $wgGrammarForms['kk'][$case][$word];
21 }
22 // Set up some constants...
23 // Vowels in last syllable
24 $frontVowels = array( "е", "ө", "ү", "і", "ә", "э" );
25 $backVowels = array( "а", "о", "ұ", "ы", "я", "ё" );
26 $allVowels = array( "е", "ө", "ү", "і", "ә", "э", "а", "о", "ұ", "ы", "я", "ё" );
27 // Preceding letters
28 $preVowels = $allVowels;
29 $preNasals = array( "м", "н", "ң" );
30 $preSonants = array( "и", "й", "л", "р", "у", "ю");
31 # $preVoiceds = array( "б", "в", "г", "ғ", "д", "ж", "з", "һ" );
32 # $preVoicelesses = array( "п", "ф", "к", "қ", "т", "ш", "с", "х", "ц", "ч", "щ" );
33 $preConsonants = array( "п", "ф", "к", "қ", "т", "ш", "с", "х", "ц", "ч", "щ", "б", "в", "г", "д" );
34 $preEzhZet = array( "ж", "з" );
35 $preSonorants = array( "и", "й", "л", "р", "у", "ю", "м", "н", "ң", "ж", "з");
36
37 // Possessives
38 $firsts = array( "м", "ң" ); // 1st singular, 2nd unformal
39 $seconds = array( "з" ); // 1st plural, 2nd formal
40 $thirds = array( "ы", "і" ); // 3rd
41
42 // Put the word in a form we can play with since we're using UTF-8
43 $ar = array();
44 $ar = preg_split('//u', $word, -1, PREG_SPLIT_NO_EMPTY);
45 $wordEnding = $ar[count( $ar ) - 1]; //Here's the last letter in the word
46 $wordReversed = array_reverse( $ar ); //Here's an array with the order of the letters in the word reversed so we can find a match quicker *shrug*
47
48 // Find the last vowel in the word
49 $wordLastVowel = NULL;
50 foreach ( $wordReversed as $xvalue ) {
51 foreach ( $allVowels as $yvalue ) {
52 if ( strcmp( $xvalue, $yvalue ) == 0 ) {
53 $wordLastVowel = $xvalue;
54 break;
55 } else {
56 continue;
57 }
58 }
59 if ( $wordLastVowel !== NULL ) {
60 break;
61 } else {
62 continue;
63 }
64 }
65
66 // Now convert the word
67 switch ( $case ) {
68 case "dc1":
69 case "genitive": #ilik
70 if ( in_array( $wordEnding, $preConsonants ) ) {
71 if ( in_array( $wordLastVowel, $frontVowels ) ) {
72 $word = implode( "", $ar ) . "тің";
73 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
74 $word = implode( "", $ar ) . "тың";
75 }
76 } elseif ( in_array( $wordEnding, $preVowels ) || in_array( $wordEnding, $preNasals ) ) {
77 if ( in_array( $wordLastVowel, $frontVowels ) ) {
78 $word = implode( "", $ar ) . "нің";
79 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
80 $word = implode( "", $ar ) . "ның";
81 }
82 } elseif ( in_array( $wordEnding, $preSonants ) || in_array( $wordEnding, $preEzhZet )) {
83 if ( in_array( $wordLastVowel, $frontVowels ) ) {
84 $word = implode( "", $ar ) . "дің";
85 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
86 $word = implode( "", $ar ) . "дың";
87 }
88 }
89 break;
90 case "dc2":
91 case "dative": #barıs
92 if ( in_array( $wordEnding, $preConsonants ) ) {
93 if ( in_array( $wordLastVowel, $frontVowels ) ) {
94 $word = implode( "", $ar ) . "ке";
95 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
96 $word = implode( "", $ar ) . "қа";
97 }
98 } elseif ( in_array( $wordEnding, $preVowels ) || in_array( $wordEnding, $preSonorants ) ) {
99 if ( in_array( $wordLastVowel, $frontVowels ) ) {
100 $word = implode( "", $ar ) . "ге";
101 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
102 $word = implode( "", $ar ) . "ға";
103 }
104 }
105 break;
106 case "dc21":
107 case "possessive dative": #täweldık + barıs
108 if ( in_array( $wordEnding, $firsts ) ) {
109 if ( in_array( $wordLastVowel, $frontVowels ) ) {
110 $word = implode( "", $ar ) . "е";
111 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
112 $word = implode( "", $ar ) . "а";
113 }
114 } elseif ( in_array( $wordEnding, $seconds ) ) {
115 if ( in_array( $wordLastVowel, $frontVowels ) ) {
116 $word = implode( "", $ar ) . "ге";
117 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
118 $word = implode( "", $ar ) . "ға";
119 }
120 } elseif ( in_array( $wordEnding, $thirds ) ) {
121 if ( in_array( $wordLastVowel, $frontVowels ) ) {
122 $word = implode( "", $ar ) . "не";
123 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
124 $word = implode( "", $ar ) . "на";
125 }
126 }
127 break;
128 case "dc3":
129 case "accusative": #tabıs
130 if ( in_array( $wordEnding, $preConsonants ) ) {
131 if ( in_array( $wordLastVowel, $frontVowels ) ) {
132 $word = implode( "", $ar ) . "ті";
133 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
134 $word = implode( "", $ar ) . "ты";
135 }
136 } elseif ( in_array( $wordEnding, $preVowels ) ) {
137 if ( in_array($wordLastVowel, $frontVowels ) ) {
138 $word = implode( "", $ar ) . "ні";
139 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
140 $word = implode( "", $ar ) . "ны";
141 }
142 } elseif ( in_array( $wordEnding, $preSonorants) ) {
143 if ( in_array( $wordLastVowel, $frontVowels) ) {
144 $word = implode( "", $ar ) . "ді";
145 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
146 $word = implode( "", $ar ) . "ды";
147 }
148 }
149 break;
150 case "dc31":
151 case "possessive accusative": #täweldık + tabıs
152 if ( in_array( $wordEnding, $firsts ) || in_array( $wordEnding, $seconds ) ) {
153 if ( in_array( $wordLastVowel, $frontVowels ) ) {
154 $word = implode( "", $ar ) . "ді";
155 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
156 $word = implode( "", $ar ) . "ды";
157 }
158 } elseif ( in_array( $wordEnding, $thirds ) ) {
159 $word = implode( "", $ar ) . "н";
160 }
161 break;
162 case "dc4":
163 case "locative": #jatıs
164 if ( in_array( $wordEnding, $preConsonants ) ) {
165 if ( in_array( $wordLastVowel, $frontVowels ) ) {
166 $word = implode( "", $ar ) . "те";
167 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
168 $word = implode( "", $ar ) . "та";
169 }
170 } elseif ( in_array( $wordEnding, $preVowels ) || in_array( $wordEnding, $preSonorants ) ) {
171 if ( in_array( $wordLastVowel, $frontVowels) ) {
172 $word = implode( "", $ar ) . "де";
173 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
174 $word = implode( "",$ar ) . "да";
175 }
176 }
177 break;
178 case "dc41":
179 case "possessive locative": #täweldık + jatıs
180 if ( in_array( $wordEnding, $firsts ) || in_array( $wordEnding, $seconds ) ) {
181 if ( in_array( $wordLastVowel, $frontVowels ) ) {
182 $word = implode( "", $ar ) . "де";
183 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
184 $word = implode( "", $ar ) . "да";
185 }
186 } elseif ( in_array( $wordEnding, $thirds ) ) {
187 if ( in_array( $wordLastVowel, $frontVowels) ) {
188 $word = implode( "", $ar ) . "нде";
189 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
190 $word = implode( "",$ar ) . "нда";
191 }
192 }
193 break;
194 case "dc5":
195 case "ablative": #şığıs
196 if ( in_array( $wordEnding, $preConsonants ) ) {
197 if ( in_array( $wordLastVowel, $frontVowels ) ) {
198 $word = implode( "", $ar ) . "тен";
199 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
200 $word = implode( "", $ar ) . "тан";
201 }
202 } elseif ( in_array($wordEnding, $preVowels ) || in_array($wordEnding, $preSonants ) || in_array($wordEnding, $preEzhZet ) ) {
203 if ( in_array( $wordLastVowel, $frontVowels ) ) {
204 $word = implode( "", $ar ) . "ден";
205 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
206 $word = implode( "", $ar ) . "дан";
207 }
208 } elseif ( in_array($wordEnding, $preNasals ) ) {
209 if ( in_array( $wordLastVowel, $frontVowels ) ) {
210 $word = implode( "", $ar ) . "нен";
211 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
212 $word = implode( "", $ar ) . "нан";
213 }
214 }
215 break;
216 case "dc51":
217 case "possessive ablative": #täweldık + şığıs
218 if ( in_array( $wordEnding, $firsts ) || in_array( $wordEnding, $thirds ) ) {
219 if ( in_array( $wordLastVowel, $frontVowels ) ) {
220 $word = implode( "", $ar ) . "нен";
221 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
222 $word = implode( "", $ar ) . "нан";
223 }
224 } elseif ( in_array($wordEnding, $seconds ) ) {
225 if ( in_array( $wordLastVowel, $frontVowels ) ) {
226 $word = implode( "", $ar ) . "ден";
227 } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
228 $word = implode( "", $ar ) . "дан";
229 }
230 }
231 break;
232 case "dc6":
233 case "comitative": #kömektes
234 if ( in_array( $wordEnding, $preConsonants ) ) {
235 $word = implode( "", $ar ) . "пен";
236 } elseif ( in_array( $wordEnding, $preVowels ) || in_array( $wordEnding, $preNasals ) || in_array( $wordEnding, $preSonants ) ) {
237 $word = implode( "", $ar ) . "мен";
238 } elseif ( in_array( $wordEnding, $preEzhZet ) ) {
239 $word = implode( "", $ar ) . "бен";
240 }
241 break;
242 case "dc61":
243 case "possessive comitative": #täweldık + kömektes
244 if ( in_array( $wordEnding, $preConsonants ) ) {
245 $word = implode( "", $ar ) . "пенен";
246 } elseif ( in_array( $wordEnding, $preVowels ) || in_array( $wordEnding, $preNasals ) || in_array( $wordEnding, $preSonants ) ) {
247 $word = implode( "", $ar ) . "менен";
248 } elseif ( in_array( $wordEnding, $preEzhZet ) ) {
249 $word = implode( "", $ar ) . "бенен";
250 }
251 break;
252 default: #dc0 #nominative #ataw
253 }
254 return $word;
255 }
256
257 /**
258 * Avoid grouping whole numbers between 0 to 9999
259 */
260 function commafy( $_ ) {
261 if ( !preg_match( '/^\d{1,4}$/', $_ ) ) {
262 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev($_) ) );
263 } else {
264 return $_;
265 }
266 }
267 }
268
269 ?>