MediaWiki REL1_30
LanguageKk.php
Go to the documentation of this file.
1<?php
24define( 'KK_C_UC', 'АӘБВГҒДЕЁЖЗИЙКҚЛМНҢОӨПРСТУҰҮФХҺЦЧШЩЪЫІЬЭЮЯ' ); # Kazakh Cyrillic uppercase
25define( 'KK_C_LC', 'аәбвгғдеёжзийкқлмнңоөпрстуұүфхһцчшщъыіьэюя' ); # Kazakh Cyrillic lowercase
26define( 'KK_L_UC', 'AÄBCÇDEÉFGĞHIİÏJKLMNÑOÖPQRSŞTUÜVWXYÝZ' ); # Kazakh Latin uppercase
27define( 'KK_L_LC', 'aäbcçdeéfgğhıiïjklmnñoöpqrsştuüvwxyýz' ); # Kazakh Latin lowercase
28// define( 'KK_A', 'ٴابپتجحدرزسشعفقكلمنڭەوۇۋۆىيچھ' ); # Kazakh Arabic
29define( 'H_HAMZA', 'ٴ' ); # U+0674 ARABIC LETTER HIGH HAMZA
30// define( 'ZWNJ', '‌' ); # U+200C ZERO WIDTH NON-JOINER
31
39
47 function __construct( $langobj, $maincode,
48 $variants = [],
49 $variantfallbacks = [],
50 $flags = [] ) {
51 parent::__construct( $langobj, $maincode,
52 $variants, $variantfallbacks, $flags );
53
54 // No point delaying this since they're in code.
55 // Waiting until loadDefaultTables() means they never get loaded
56 // when the tables themselves are loaded from cache.
57 $this->loadRegs();
58 }
59
60 function loadDefaultTables() {
61 // require __DIR__."/../../includes/KkConversion.php";
62 // Placeholder for future implementing. Remove variables declarations
63 // after generating KkConversion.php
64 $kk2Cyrl = [];
65 $kk2Latn = [];
66 $kk2Arab = [];
67 $kk2KZ = [];
68 $kk2TR = [];
69 $kk2CN = [];
70
71 $this->mTables = [
72 'kk-cyrl' => new ReplacementArray( $kk2Cyrl ),
73 'kk-latn' => new ReplacementArray( $kk2Latn ),
74 'kk-arab' => new ReplacementArray( $kk2Arab ),
75 'kk-kz' => new ReplacementArray( array_merge( $kk2Cyrl, $kk2KZ ) ),
76 'kk-tr' => new ReplacementArray( array_merge( $kk2Latn, $kk2TR ) ),
77 'kk-cn' => new ReplacementArray( array_merge( $kk2Arab, $kk2CN ) ),
78 'kk' => new ReplacementArray()
79 ];
80 }
81
82 function postLoadTables() {
83 $this->mTables['kk-kz']->merge( $this->mTables['kk-cyrl'] );
84 $this->mTables['kk-tr']->merge( $this->mTables['kk-latn'] );
85 $this->mTables['kk-cn']->merge( $this->mTables['kk-arab'] );
86 }
87
88 function loadRegs() {
89 $this->mCyrl2Latn = [
90 # # Punctuation
91 '/№/u' => 'No.',
92 # # Е after vowels
93 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])Е/u' => '$1YE',
94 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])е/ui' => '$1ye',
95 # # leading ЁЮЯЩ
96 '/^Ё([' . KK_C_UC . ']|$)/u' => 'YO$1', '/^Ё([' . KK_C_LC . ']|$)/u' => 'Yo$1',
97 '/^Ю([' . KK_C_UC . ']|$)/u' => 'YU$1', '/^Ю([' . KK_C_LC . ']|$)/u' => 'Yu$1',
98 '/^Я([' . KK_C_UC . ']|$)/u' => 'YA$1', '/^Я([' . KK_C_LC . ']|$)/u' => 'Ya$1',
99 '/^Щ([' . KK_C_UC . ']|$)/u' => 'ŞÇ$1', '/^Щ([' . KK_C_LC . ']|$)/u' => 'Şç$1',
100 # # other ЁЮЯ
101 '/Ё/u' => 'YO', '/ё/u' => 'yo',
102 '/Ю/u' => 'YU', '/ю/u' => 'yu',
103 '/Я/u' => 'YA', '/я/u' => 'ya',
104 '/Щ/u' => 'ŞÇ', '/щ/u' => 'şç',
105 # # soft and hard signs
106 '/[ъЪ]/u' => 'ʺ', '/[ьЬ]/u' => 'ʹ',
107 # # other characters
108 '/А/u' => 'A', '/а/u' => 'a', '/Ә/u' => 'Ä', '/ә/u' => 'ä',
109 '/Б/u' => 'B', '/б/u' => 'b', '/В/u' => 'V', '/в/u' => 'v',
110 '/Г/u' => 'G', '/г/u' => 'g', '/Ғ/u' => 'Ğ', '/ғ/u' => 'ğ',
111 '/Д/u' => 'D', '/д/u' => 'd', '/Е/u' => 'E', '/е/u' => 'e',
112 '/Ж/u' => 'J', '/ж/u' => 'j', '/З/u' => 'Z', '/з/u' => 'z',
113 '/И/u' => 'Ï', '/и/u' => 'ï', '/Й/u' => 'Ý', '/й/u' => 'ý',
114 '/К/u' => 'K', '/к/u' => 'k', '/Қ/u' => 'Q', '/қ/u' => 'q',
115 '/Л/u' => 'L', '/л/u' => 'l', '/М/u' => 'M', '/м/u' => 'm',
116 '/Н/u' => 'N', '/н/u' => 'n', '/Ң/u' => 'Ñ', '/ң/u' => 'ñ',
117 '/О/u' => 'O', '/о/u' => 'o', '/Ө/u' => 'Ö', '/ө/u' => 'ö',
118 '/П/u' => 'P', '/п/u' => 'p', '/Р/u' => 'R', '/р/u' => 'r',
119 '/С/u' => 'S', '/с/u' => 's', '/Т/u' => 'T', '/т/u' => 't',
120 '/У/u' => 'W', '/у/u' => 'w', '/Ұ/u' => 'U', '/ұ/u' => 'u',
121 '/Ү/u' => 'Ü', '/ү/u' => 'ü', '/Ф/u' => 'F', '/ф/u' => 'f',
122 '/Х/u' => 'X', '/х/u' => 'x', '/Һ/u' => 'H', '/һ/u' => 'h',
123 '/Ц/u' => 'C', '/ц/u' => 'c', '/Ч/u' => 'Ç', '/ч/u' => 'ç',
124 '/Ш/u' => 'Ş', '/ш/u' => 'ş', '/Ы/u' => 'I', '/ы/u' => 'ı',
125 '/І/u' => 'İ', '/і/u' => 'i', '/Э/u' => 'É', '/э/u' => 'é',
126 ];
127
128 $this->mLatn2Cyrl = [
129 # # Punctuation
130 '/#|No\./' => '№',
131 # # Şç
132 '/ŞÇʹ/u' => 'ЩЬ', '/Şçʹ/u' => 'Щь',
133 '/Ş[Çç]/u' => 'Щ', '/şç/u' => 'щ',
134 # # soft and hard signs
135 '/([' . KK_L_UC . '])ʺ([' . KK_L_UC . '])/u' => '$1Ъ$2',
136 '/ʺ([' . KK_L_LC . '])/u' => 'ъ$1',
137 '/([' . KK_L_UC . '])ʹ([' . KK_L_UC . '])/u' => '$1Ь$2',
138 '/ʹ([' . KK_L_LC . '])/u' => 'ь$1',
139 '/ʺ/u' => 'ъ',
140 '/ʹ/u' => 'ь',
141 # # Ye Yo Yu Ya.
142 '/Y[Ee]/u' => 'Е', '/ye/u' => 'е',
143 '/Y[Oo]/u' => 'Ё', '/yo/u' => 'ё',
144 '/Y[UWuw]/u' => 'Ю', '/y[uw]/u' => 'ю',
145 '/Y[Aa]/u' => 'Я', '/ya/u' => 'я',
146 # # other characters
147 '/A/u' => 'А', '/a/u' => 'а', '/Ä/u' => 'Ә', '/ä/u' => 'ә',
148 '/B/u' => 'Б', '/b/u' => 'б', '/C/u' => 'Ц', '/c/u' => 'ц',
149 '/Ç/u' => 'Ч', '/ç/u' => 'ч', '/D/u' => 'Д', '/d/u' => 'д',
150 '/E/u' => 'Е', '/e/u' => 'е', '/É/u' => 'Э', '/é/u' => 'э',
151 '/F/u' => 'Ф', '/f/u' => 'ф', '/G/u' => 'Г', '/g/u' => 'г',
152 '/Ğ/u' => 'Ғ', '/ğ/u' => 'ғ', '/H/u' => 'Һ', '/h/u' => 'һ',
153 '/I/u' => 'Ы', '/ı/u' => 'ы', '/İ/u' => 'І', '/i/u' => 'і',
154 '/Ï/u' => 'И', '/ï/u' => 'и', '/J/u' => 'Ж', '/j/u' => 'ж',
155 '/K/u' => 'К', '/k/u' => 'к', '/L/u' => 'Л', '/l/u' => 'л',
156 '/M/u' => 'М', '/m/u' => 'м', '/N/u' => 'Н', '/n/u' => 'н',
157 '/Ñ/u' => 'Ң', '/ñ/u' => 'ң', '/O/u' => 'О', '/o/u' => 'о',
158 '/Ö/u' => 'Ө', '/ö/u' => 'ө', '/P/u' => 'П', '/p/u' => 'п',
159 '/Q/u' => 'Қ', '/q/u' => 'қ', '/R/u' => 'Р', '/r/u' => 'р',
160 '/S/u' => 'С', '/s/u' => 'с', '/Ş/u' => 'Ш', '/ş/u' => 'ш',
161 '/T/u' => 'Т', '/t/u' => 'т', '/U/u' => 'Ұ', '/u/u' => 'ұ',
162 '/Ü/u' => 'Ү', '/ü/u' => 'ү', '/V/u' => 'В', '/v/u' => 'в',
163 '/W/u' => 'У', '/w/u' => 'у', '/Ý/u' => 'Й', '/ý/u' => 'й',
164 '/X/u' => 'Х', '/x/u' => 'х', '/Z/u' => 'З', '/z/u' => 'з',
165 ];
166
167 $this->mCyLa2Arab = [
168 # # Punctuation -> Arabic
169 '/#|№|No\./u' => '؀', # &#x0600;
170 '/\,/' => '،', # &#x060C;
171 '/;/' => '؛', # &#x061B;
172 '/\?/' => '؟', # &#x061F;
173 '/%/' => '٪', # &#x066A;
174 '/\*/' => '٭', # &#x066D;
175 # # Digits -> Arabic
176 '/0/' => '۰', # &#x06F0;
177 '/1/' => '۱', # &#x06F1;
178 '/2/' => '۲', # &#x06F2;
179 '/3/' => '۳', # &#x06F3;
180 '/4/' => '۴', # &#x06F4;
181 '/5/' => '۵', # &#x06F5;
182 '/6/' => '۶', # &#x06F6;
183 '/7/' => '۷', # &#x06F7;
184 '/8/' => '۸', # &#x06F8;
185 '/9/' => '۹', # &#x06F9;
186 # # Cyrillic -> Arabic
187 '/Аллаһ/ui' => 'ﷲ',
188 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])е/ui' => '$1يە',
189 '/[еэ]/ui' => 'ە', '/[ъь]/ui' => '',
190 '/[аә]/ui' => 'ا', '/[оө]/ui' => 'و', '/[ұү]/ui' => 'ۇ', '/[ыі]/ui' => 'ى',
191 '/[и]/ui' => 'ىي', '/ё/ui' => 'يو', '/ю/ui' => 'يۋ', '/я/ui' => 'يا', '/[й]/ui' => 'ي',
192 '/ц/ui' => 'تس', '/щ/ui' => 'شش',
193 '/һ/ui' => 'ح', '/ч/ui' => 'تش',
194 # '/һ/ui' => 'ھ', '/ч/ui' => 'چ',
195 '/б/ui' => 'ب', '/в/ui' => 'ۆ', '/г/ui' => 'گ', '/ғ/ui' => 'ع',
196 '/д/ui' => 'د', '/ж/ui' => 'ج', '/з/ui' => 'ز', '/к/ui' => 'ك',
197 '/қ/ui' => 'ق', '/л/ui' => 'ل', '/м/ui' => 'م', '/н/ui' => 'ن',
198 '/ң/ui' => 'ڭ', '/п/ui' => 'پ', '/р/ui' => 'ر', '/с/ui' => 'س',
199 '/т/ui' => 'ت', '/у/ui' => 'ۋ', '/ф/ui' => 'ف', '/х/ui' => 'ح',
200 '/ш/ui' => 'ش',
201 # # Latin -> Arabic // commented for now...
202 /*'/Allah/ui' => 'ﷲ',
203 '/[eé]/ui' => 'ە', '/[yý]/ui' => 'ي', '/[ʺʹ]/ui' => '',
204 '/[aä]/ui' => 'ا', '/[oö]/ui' => 'و', '/[uü]/ui' => 'ۇ',
205 '/[ï]/ui' => 'ىي', '/[ıIiİ]/u' => 'ى',
206 '/c/ui' => 'تس',
207 '/ç/ui' => 'تش', '/h/ui' => 'ح',
208 #'/ç/ui' => 'چ', '/h/ui' => 'ھ',
209 '/b/ui' => 'ب','/d/ui' => 'د',
210 '/f/ui' => 'ف', '/g/ui' => 'گ', '/ğ/ui' => 'ع',
211 '/j/ui' => 'ج', '/k/ui' => 'ك', '/l/ui' => 'ل', '/m/ui' => 'م',
212 '/n/ui' => 'ن', '/ñ/ui' => 'ڭ', '/p/ui' => 'پ', '/q/ui' => 'ق',
213 '/r/ui' => 'ر', '/s/ui' => 'س', '/ş/ui' => 'ش', '/t/ui' => 'ت',
214 '/v/ui' => 'ۆ', '/w/ui' => 'ۋ', '/x/ui' => 'ح', '/z/ui' => 'ز',*/
215 ];
216 }
217
228 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
229 // check for user namespace
230 if ( is_object( $nt ) ) {
231 $ns = $nt->getNamespace();
232 if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
233 return;
234 }
235 }
236
237 $oldlink = $link;
238 parent::findVariantLink( $link, $nt, $ignoreOtherCond );
239 if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
240 $link = $oldlink;
241 }
242 }
243
252 function translate( $text, $toVariant ) {
253 $text = parent::translate( $text, $toVariant );
254
255 switch ( $toVariant ) {
256 case 'kk-cyrl':
257 case 'kk-kz':
258 $letters = KK_L_UC . KK_L_LC . 'ʺʹ#0123456789';
259 break;
260 case 'kk-latn':
261 case 'kk-tr':
262 $letters = KK_C_UC . KK_C_LC . '№0123456789';
263 break;
264 case 'kk-arab':
265 case 'kk-cn':
266 $letters = KK_C_UC . KK_C_LC . /*KK_L_UC.KK_L_LC.'ʺʹ'.*/',;\?%\*№0123456789';
267 break;
268 default:
269 return $text;
270 }
271 // disable conversion variables like $1, $2...
272 $varsfix = '\$[0-9]';
273
274 $matches = preg_split(
275 '/' . $varsfix . '[^' . $letters . ']+/u',
276 $text,
277 -1,
278 PREG_SPLIT_OFFSET_CAPTURE
279 );
280
281 $mstart = 0;
282 $ret = '';
283
284 foreach ( $matches as $m ) {
285 $ret .= substr( $text, $mstart, $m[1] - $mstart );
286 $ret .= $this->regsConverter( $m[0], $toVariant );
287 $mstart = $m[1] + strlen( $m[0] );
288 }
289
290 return $ret;
291 }
292
298 function regsConverter( $text, $toVariant ) {
299 if ( $text == '' ) {
300 return $text;
301 }
302
303 switch ( $toVariant ) {
304 case 'kk-arab':
305 case 'kk-cn':
306 $letters = KK_C_LC . KK_C_UC; /*.KK_L_LC.KK_L_UC*/
307 $front = 'әөүіӘӨҮІ'; /*.'äöüiÄÖÜİ'*/
308 $excludes = 'еэгғкқЕЭГҒКҚ'; /*.'eégğkqEÉGĞKQ'*/
309 // split text to words
310 $matches = preg_split( '/[\b\s\-\.:]+/', $text, -1, PREG_SPLIT_OFFSET_CAPTURE );
311 $mstart = 0;
312 $ret = '';
313 foreach ( $matches as $m ) {
314 $ret .= substr( $text, $mstart, $m[1] - $mstart );
315 // is matched the word to front vowels?
316 // exclude a words matched to е, э, г, к, к, қ,
317 // them should be without hamza
318 if ( preg_match( '/[' . $front . ']/u', $m[0] )
319 && !preg_match( '/[' . $excludes . ']/u', $m[0] )
320 ) {
321 $ret .= preg_replace( '/[' . $letters . ']+/u', H_HAMZA . '$0', $m[0] );
322 } else {
323 $ret .= $m[0];
324 }
325 $mstart = $m[1] + strlen( $m[0] );
326 }
327 $text =& $ret;
328 foreach ( $this->mCyLa2Arab as $pat => $rep ) {
329 $text = preg_replace( $pat, $rep, $text );
330 }
331 return $text;
332 break;
333 case 'kk-latn':
334 case 'kk-tr':
335 foreach ( $this->mCyrl2Latn as $pat => $rep ) {
336 $text = preg_replace( $pat, $rep, $text );
337 }
338 return $text;
339 break;
340 case 'kk-cyrl':
341 case 'kk-kz':
342 foreach ( $this->mLatn2Cyrl as $pat => $rep ) {
343 $text = preg_replace( $pat, $rep, $text );
344 }
345 return $text;
346 break;
347 default:
348 return $text;
349 }
350 }
351
356 function convertCategoryKey( $key ) {
357 return $this->autoConvert( $key, 'kk' );
358 }
359}
360
368 function __construct() {
369 parent::__construct();
370
371 $variants = [ 'kk', 'kk-cyrl', 'kk-latn', 'kk-arab', 'kk-kz', 'kk-tr', 'kk-cn' ];
372 $variantfallbacks = [
373 'kk' => 'kk-cyrl',
374 'kk-cyrl' => 'kk',
375 'kk-latn' => 'kk',
376 'kk-arab' => 'kk',
377 'kk-kz' => 'kk-cyrl',
378 'kk-tr' => 'kk-latn',
379 'kk-cn' => 'kk-arab'
380 ];
381
382 $this->mConverter = new KkConverter( $this, 'kk', $variants, $variantfallbacks );
383 }
384
392 public function ucfirst( $string ) {
393 if ( substr( $string, 0, 1 ) === 'i' ) {
394 $variant = $this->getPreferredVariant();
395 if ( $variant == 'kk-latn' || $variant == 'kk-tr' ) {
396 return 'İ' . substr( $string, 1 );
397 }
398 }
399 return parent::ucfirst( $string );
400 }
401
409 function lcfirst( $string ) {
410 if ( substr( $string, 0, 1 ) === 'I' ) {
411 $variant = $this->getPreferredVariant();
412 if ( $variant == 'kk-latn' || $variant == 'kk-tr' ) {
413 return 'ı' . substr( $string, 1 );
414 }
415 }
416 return parent::lcfirst( $string );
417 }
418
424 function convertGrammar( $word, $case ) {
425 $variant = $this->getPreferredVariant();
426 switch ( $variant ) {
427 case 'kk-arab':
428 case 'kk-cn':
429 $word = parent::convertGrammarKk_arab( $word, $case );
430 break;
431 case 'kk-latn':
432 case 'kk-tr':
433 $word = parent::convertGrammarKk_latn( $word, $case );
434 break;
435 case 'kk-cyrl':
436 case 'kk-kz':
437 case 'kk':
438 default:
439 $word = parent::convertGrammarKk_cyrl( $word, $case );
440 }
441
442 return $word;
443 }
444}
const H_HAMZA
const KK_C_UC
const KK_L_LC
const KK_L_UC
const KK_C_LC
Kazakh (Қазақша) converter routines.
convertCategoryKey( $key)
postLoadTables()
Hook for post processing after conversion tables are loaded.
loadDefaultTables()
Load default conversion tables.
regsConverter( $text, $toVariant)
__construct( $langobj, $maincode, $variants=[], $variantfallbacks=[], $flags=[])
translate( $text, $toVariant)
It translates text into variant.
findVariantLink(&$link, &$nt, $ignoreOtherCond=false)
A function wrapper:
Base class for language conversion.
getPreferredVariant()
Get preferred language variant.
autoConvert( $text, $toVariant=false)
Dictionary-based conversion.
Kazakh (Қазақша)
class that handles Cyrillic, Latin and Arabic scripts for Kazakh right now it only distinguish kk_cyr...
convertGrammar( $word, $case)
lcfirst( $string)
It fixes issue with lcfirst for transforming 'I' to 'ı'.
ucfirst( $string)
It fixes issue with ucfirst for transforming 'i' to 'İ'.
getPreferredVariant()
Wrapper around strtr() that holds replacements.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2805
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:1975
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:2989
const NS_USER_TALK
Definition Defines.php:68