Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / languages / classes / LanguageKk.php
blob0f60889abf24d283e4e0b625df7d0ef5075f2f0f
1 <?php
2 /**
3 * Kazakh (Қазақша) specific code.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Language
24 require_once __DIR__ . '/../LanguageConverter.php';
25 require_once __DIR__ . '/LanguageKk_cyrl.php';
27 define( 'KK_C_UC', 'АӘБВГҒДЕЁЖЗИЙКҚЛМНҢОӨПРСТУҰҮФХҺЦЧШЩЪЫІЬЭЮЯ' ); # Kazakh Cyrillic uppercase
28 define( 'KK_C_LC', 'аәбвгғдеёжзийкқлмнңоөпрстуұүфхһцчшщъыіьэюя' ); # Kazakh Cyrillic lowercase
29 define( 'KK_L_UC', 'AÄBCÇDEÉFGĞHIİÏJKLMNÑOÖPQRSŞTUÜVWXYÝZ' ); # Kazakh Latin uppercase
30 define( 'KK_L_LC', 'aäbcçdeéfgğhıiïjklmnñoöpqrsştuüvwxyýz' ); # Kazakh Latin lowercase
31 // define( 'KK_A', 'ٴابپتجحدرزسشعفقكلمنڭەوۇۋۆىيچھ' ); # Kazakh Arabic
32 define( 'H_HAMZA', 'ٴ' ); # U+0674 ARABIC LETTER HIGH HAMZA
33 // define( 'ZWNJ', '‌' ); # U+200C ZERO WIDTH NON-JOINER
35 /**
36 * Kazakh (Қазақша) converter routines
38 * @ingroup Language
40 class KkConverter extends LanguageConverter {
41 protected $mCyrl2Latn, $mLatn2Cyrl, $mCyLa2Arab;
43 /**
44 * @param Language $langobj
45 * @param string $maincode
46 * @param array $variants
47 * @param array $variantfallbacks
48 * @param array $flags
50 function __construct( $langobj, $maincode,
51 $variants = array(),
52 $variantfallbacks = array(),
53 $flags = array() ) {
54 parent::__construct( $langobj, $maincode,
55 $variants, $variantfallbacks, $flags );
57 // No point delaying this since they're in code.
58 // Waiting until loadDefaultTables() means they never get loaded
59 // when the tables themselves are loaded from cache.
60 $this->loadRegs();
63 function loadDefaultTables() {
64 // require __DIR__."/../../includes/KkConversion.php";
65 // Placeholder for future implementing. Remove variables declarations
66 // after generating KkConversion.php
67 $kk2Cyrl = array();
68 $kk2Latn = array();
69 $kk2Arab = array();
70 $kk2KZ = array();
71 $kk2TR = array();
72 $kk2CN = array();
74 $this->mTables = array(
75 'kk-cyrl' => new ReplacementArray( $kk2Cyrl ),
76 'kk-latn' => new ReplacementArray( $kk2Latn ),
77 'kk-arab' => new ReplacementArray( $kk2Arab ),
78 'kk-kz' => new ReplacementArray( array_merge( $kk2Cyrl, $kk2KZ ) ),
79 'kk-tr' => new ReplacementArray( array_merge( $kk2Latn, $kk2TR ) ),
80 'kk-cn' => new ReplacementArray( array_merge( $kk2Arab, $kk2CN ) ),
81 'kk' => new ReplacementArray()
85 function postLoadTables() {
86 $this->mTables['kk-kz']->merge( $this->mTables['kk-cyrl'] );
87 $this->mTables['kk-tr']->merge( $this->mTables['kk-latn'] );
88 $this->mTables['kk-cn']->merge( $this->mTables['kk-arab'] );
91 function loadRegs() {
93 $this->mCyrl2Latn = array(
94 # # Punctuation
95 '/№/u' => 'No.',
96 # # Е after vowels
97 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])Е/u' => '$1YE',
98 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])е/ui' => '$1ye',
99 # # leading ЁЮЯЩ
100 '/^Ё([' . KK_C_UC . ']|$)/u' => 'YO$1', '/^Ё([' . KK_C_LC . ']|$)/u' => 'Yo$1',
101 '/^Ю([' . KK_C_UC . ']|$)/u' => 'YU$1', '/^Ю([' . KK_C_LC . ']|$)/u' => 'Yu$1',
102 '/^Я([' . KK_C_UC . ']|$)/u' => 'YA$1', '/^Я([' . KK_C_LC . ']|$)/u' => 'Ya$1',
103 '/^Щ([' . KK_C_UC . ']|$)/u' => 'ŞÇ$1', '/^Щ([' . KK_C_LC . ']|$)/u' => 'Şç$1',
104 # # other ЁЮЯ
105 '/Ё/u' => 'YO', '/ё/u' => 'yo',
106 '/Ю/u' => 'YU', '/ю/u' => 'yu',
107 '/Я/u' => 'YA', '/я/u' => 'ya',
108 '/Щ/u' => 'ŞÇ', '/щ/u' => 'şç',
109 # # soft and hard signs
110 '/[ъЪ]/u' => 'ʺ', '/[ьЬ]/u' => 'ʹ',
111 # # other characters
112 '/А/u' => 'A', '/а/u' => 'a', '/Ә/u' => 'Ä', '/ә/u' => 'ä',
113 '/Б/u' => 'B', '/б/u' => 'b', '/В/u' => 'V', '/в/u' => 'v',
114 '/Г/u' => 'G', '/г/u' => 'g', '/Ғ/u' => 'Ğ', '/ғ/u' => 'ğ',
115 '/Д/u' => 'D', '/д/u' => 'd', '/Е/u' => 'E', '/е/u' => 'e',
116 '/Ж/u' => 'J', '/ж/u' => 'j', '/З/u' => 'Z', '/з/u' => 'z',
117 '/И/u' => 'Ï', '/и/u' => 'ï', '/Й/u' => 'Ý', '/й/u' => 'ý',
118 '/К/u' => 'K', '/к/u' => 'k', '/Қ/u' => 'Q', '/қ/u' => 'q',
119 '/Л/u' => 'L', '/л/u' => 'l', '/М/u' => 'M', '/м/u' => 'm',
120 '/Н/u' => 'N', '/н/u' => 'n', '/Ң/u' => 'Ñ', '/ң/u' => 'ñ',
121 '/О/u' => 'O', '/о/u' => 'o', '/Ө/u' => 'Ö', '/ө/u' => 'ö',
122 '/П/u' => 'P', '/п/u' => 'p', '/Р/u' => 'R', '/р/u' => 'r',
123 '/С/u' => 'S', '/с/u' => 's', '/Т/u' => 'T', '/т/u' => 't',
124 '/У/u' => 'W', '/у/u' => 'w', '/Ұ/u' => 'U', '/ұ/u' => 'u',
125 '/Ү/u' => 'Ü', '/ү/u' => 'ü', '/Ф/u' => 'F', '/ф/u' => 'f',
126 '/Х/u' => 'X', '/х/u' => 'x', '/Һ/u' => 'H', '/һ/u' => 'h',
127 '/Ц/u' => 'C', '/ц/u' => 'c', '/Ч/u' => 'Ç', '/ч/u' => 'ç',
128 '/Ш/u' => 'Ş', '/ш/u' => 'ş', '/Ы/u' => 'I', '/ы/u' => 'ı',
129 '/І/u' => 'İ', '/і/u' => 'i', '/Э/u' => 'É', '/э/u' => 'é',
132 $this->mLatn2Cyrl = array(
133 # # Punctuation
134 '/#|No\./' => '№',
135 # # Şç
136 '/ŞÇʹ/u' => 'ЩЬ', '/Şçʹ/u' => 'Щь',
137 '/Ş[Çç]/u' => 'Щ', '/şç/u' => 'щ',
138 # # soft and hard signs
139 '/([' . KK_L_UC . '])ʺ([' . KK_L_UC . '])/u' => '$1Ъ$2',
140 '/ʺ([' . KK_L_LC . '])/u' => $1',
141 '/([' . KK_L_UC . '])ʹ([' . KK_L_UC . '])/u' => '$1Ь$2',
142 '/ʹ([' . KK_L_LC . '])/u' => $1',
143 '/ʺ/u' => 'ъ',
144 '/ʹ/u' => 'ь',
145 # # Ye Yo Yu Ya.
146 '/Y[Ee]/u' => 'Е', '/ye/u' => 'е',
147 '/Y[Oo]/u' => 'Ё', '/yo/u' => 'ё',
148 '/Y[UWuw]/u' => 'Ю', '/y[uw]/u' => 'ю',
149 '/Y[Aa]/u' => 'Я', '/ya/u' => 'я',
150 # # other characters
151 '/A/u' => 'А', '/a/u' => 'а', '/Ä/u' => 'Ә', '/ä/u' => 'ә',
152 '/B/u' => 'Б', '/b/u' => 'б', '/C/u' => 'Ц', '/c/u' => 'ц',
153 '/Ç/u' => 'Ч', '/ç/u' => 'ч', '/D/u' => 'Д', '/d/u' => 'д',
154 '/E/u' => 'Е', '/e/u' => 'е', '/É/u' => 'Э', '/é/u' => 'э',
155 '/F/u' => 'Ф', '/f/u' => 'ф', '/G/u' => 'Г', '/g/u' => 'г',
156 '/Ğ/u' => 'Ғ', '/ğ/u' => 'ғ', '/H/u' => 'Һ', '/h/u' => 'һ',
157 '/I/u' => 'Ы', '/ı/u' => 'ы', '/İ/u' => 'І', '/i/u' => 'і',
158 '/Ï/u' => 'И', '/ï/u' => 'и', '/J/u' => 'Ж', '/j/u' => 'ж',
159 '/K/u' => 'К', '/k/u' => 'к', '/L/u' => 'Л', '/l/u' => 'л',
160 '/M/u' => 'М', '/m/u' => 'м', '/N/u' => 'Н', '/n/u' => 'н',
161 '/Ñ/u' => 'Ң', '/ñ/u' => 'ң', '/O/u' => 'О', '/o/u' => 'о',
162 '/Ö/u' => 'Ө', '/ö/u' => 'ө', '/P/u' => 'П', '/p/u' => 'п',
163 '/Q/u' => 'Қ', '/q/u' => 'қ', '/R/u' => 'Р', '/r/u' => 'р',
164 '/S/u' => 'С', '/s/u' => 'с', '/Ş/u' => 'Ш', '/ş/u' => 'ш',
165 '/T/u' => 'Т', '/t/u' => 'т', '/U/u' => 'Ұ', '/u/u' => 'ұ',
166 '/Ü/u' => 'Ү', '/ü/u' => 'ү', '/V/u' => 'В', '/v/u' => 'в',
167 '/W/u' => 'У', '/w/u' => 'у', '/Ý/u' => 'Й', '/ý/u' => 'й',
168 '/X/u' => 'Х', '/x/u' => 'х', '/Z/u' => 'З', '/z/u' => 'з',
171 $this->mCyLa2Arab = array(
172 # # Punctuation -> Arabic
173 '/#|№|No\./u' => '؀', # &#x0600;
174 '/\,/' => '،', # &#x060C;
175 '/;/' => '؛', # &#x061B;
176 '/\?/' => '؟', # &#x061F;
177 '/%/' => '٪', # &#x066A;
178 '/\*/' => '٭', # &#x066D;
179 # # Digits -> Arabic
180 '/0/' => '۰', # &#x06F0;
181 '/1/' => '۱', # &#x06F1;
182 '/2/' => '۲', # &#x06F2;
183 '/3/' => '۳', # &#x06F3;
184 '/4/' => '۴', # &#x06F4;
185 '/5/' => '۵', # &#x06F5;
186 '/6/' => '۶', # &#x06F6;
187 '/7/' => '۷', # &#x06F7;
188 '/8/' => '۸', # &#x06F8;
189 '/9/' => '۹', # &#x06F9;
190 # # Cyrillic -> Arabic
191 '/Аллаһ/ui' => 'ﷲ',
192 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])е/ui' => '$1يە',
193 '/[еэ]/ui' => 'ە', '/[ъь]/ui' => '',
194 '/[аә]/ui' => 'ا', '/[оө]/ui' => 'و', '/[ұү]/ui' => 'ۇ', '/[ыі]/ui' => 'ى',
195 '/[и]/ui' => 'ىي', '/ё/ui' => 'يو', '/ю/ui' => 'يۋ', '/я/ui' => 'يا', '/[й]/ui' => 'ي',
196 '/ц/ui' => 'تس', '/щ/ui' => 'شش',
197 '/һ/ui' => 'ح', '/ч/ui' => 'تش',
198 # '/һ/ui' => 'ھ', '/ч/ui' => 'چ',
199 '/б/ui' => 'ب', '/в/ui' => 'ۆ', '/г/ui' => 'گ', '/ғ/ui' => 'ع',
200 '/д/ui' => 'د', '/ж/ui' => 'ج', '/з/ui' => 'ز', '/к/ui' => 'ك',
201 '/қ/ui' => 'ق', '/л/ui' => 'ل', '/м/ui' => 'م', '/н/ui' => 'ن',
202 '/ң/ui' => 'ڭ', '/п/ui' => 'پ', '/р/ui' => 'ر', '/с/ui' => 'س',
203 '/т/ui' => 'ت', '/у/ui' => 'ۋ', '/ф/ui' => 'ف', '/х/ui' => 'ح',
204 '/ш/ui' => 'ش',
205 # # Latin -> Arabic // commented for now...
206 /*'/Allah/ui' => 'ﷲ',
207 '/[eé]/ui' => 'ە', '/[yý]/ui' => 'ي', '/[ʺʹ]/ui' => '',
208 '/[aä]/ui' => 'ا', '/[oö]/ui' => 'و', '/[uü]/ui' => 'ۇ',
209 '/[ï]/ui' => 'ىي', '/[ıIiİ]/u' => 'ى',
210 '/c/ui' => 'تس',
211 '/ç/ui' => 'تش', '/h/ui' => 'ح',
212 #'/ç/ui' => 'چ', '/h/ui' => 'ھ',
213 '/b/ui' => 'ب','/d/ui' => 'د',
214 '/f/ui' => 'ف', '/g/ui' => 'گ', '/ğ/ui' => 'ع',
215 '/j/ui' => 'ج', '/k/ui' => 'ك', '/l/ui' => 'ل', '/m/ui' => 'م',
216 '/n/ui' => 'ن', '/ñ/ui' => 'ڭ', '/p/ui' => 'پ', '/q/ui' => 'ق',
217 '/r/ui' => 'ر', '/s/ui' => 'س', '/ş/ui' => 'ش', '/t/ui' => 'ت',
218 '/v/ui' => 'ۆ', '/w/ui' => 'ۋ', '/x/ui' => 'ح', '/z/ui' => 'ز',*/
223 * rules should be defined as -{ekavian | iyekavian-} -or-
224 * -{code:text | code:text | ...}-
226 * update: delete all rule parsing because it's not used
227 * currently, and just produces a couple of bugs
229 * @param string $rule
230 * @param array $flags
231 * @return array
233 function parseManualRule( $rule, $flags = array() ) {
234 if ( in_array( 'T', $flags ) ) {
235 return parent::parseManualRule( $rule, $flags );
238 $carray = array();
239 // otherwise ignore all formatting
240 foreach ( $this->mVariants as $v ) {
241 $carray[$v] = $rule;
244 return $carray;
248 * A function wrapper:
249 * - if there is no selected variant, leave the link
250 * names as they were
251 * - do not try to find variants for usernames
253 * @param string &$link
254 * @param Title &$nt
255 * @param bool $ignoreOtherCond
257 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
258 // check for user namespace
259 if ( is_object( $nt ) ) {
260 $ns = $nt->getNamespace();
261 if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
262 return;
266 $oldlink = $link;
267 parent::findVariantLink( $link, $nt, $ignoreOtherCond );
268 if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
269 $link = $oldlink;
274 * It translates text into variant
276 * @param string $text
277 * @param string $toVariant
279 * @return string
281 function translate( $text, $toVariant ) {
282 $text = parent::translate( $text, $toVariant );
284 switch ( $toVariant ) {
285 case 'kk-cyrl':
286 case 'kk-kz':
287 $letters = KK_L_UC . KK_L_LC . 'ʺʹ#0123456789';
288 break;
289 case 'kk-latn':
290 case 'kk-tr':
291 $letters = KK_C_UC . KK_C_LC . '№0123456789';
292 break;
293 case 'kk-arab':
294 case 'kk-cn':
295 $letters = KK_C_UC . KK_C_LC . /*KK_L_UC.KK_L_LC.'ʺʹ'.*/',;\?%\*№0123456789';
296 break;
297 default:
298 return $text;
300 // disable conversion variables like $1, $2...
301 $varsfix = '\$[0-9]';
303 $matches = preg_split(
304 '/' . $varsfix . '[^' . $letters . ']+/u',
305 $text,
307 PREG_SPLIT_OFFSET_CAPTURE
310 $mstart = 0;
311 $ret = '';
313 foreach ( $matches as $m ) {
314 $ret .= substr( $text, $mstart, $m[1] -$mstart );
315 $ret .= $this->regsConverter( $m[0], $toVariant );
316 $mstart = $m[1] + strlen( $m[0] );
319 return $ret;
323 * @param string $text
324 * @param string $toVariant
325 * @return mixed|string
327 function regsConverter( $text, $toVariant ) {
328 if ( $text == '' ) {
329 return $text;
332 switch ( $toVariant ) {
333 case 'kk-arab':
334 case 'kk-cn':
335 $letters = KK_C_LC . KK_C_UC; /*.KK_L_LC.KK_L_UC*/
336 $front = 'әөүіӘӨҮІ'; /*.'äöüiÄÖÜİ'*/
337 $excludes = 'еэгғкқЕЭГҒКҚ'; /*.'eégğkqEÉGĞKQ'*/
338 // split text to words
339 $matches = preg_split( '/[\b\s\-\.:]+/', $text, -1, PREG_SPLIT_OFFSET_CAPTURE );
340 $mstart = 0;
341 $ret = '';
342 foreach ( $matches as $m ) {
343 $ret .= substr( $text, $mstart, $m[1] - $mstart );
344 // is matched the word to front vowels?
345 // exclude a words matched to е, э, г, к, к, қ,
346 // them should be without hamza
347 if ( preg_match( '/[' . $front . ']/u', $m[0] )
348 && !preg_match( '/[' . $excludes . ']/u', $m[0] )
350 $ret .= preg_replace( '/[' . $letters . ']+/u', H_HAMZA . '$0', $m[0] );
351 } else {
352 $ret .= $m[0];
354 $mstart = $m[1] + strlen( $m[0] );
356 $text =& $ret;
357 foreach ( $this->mCyLa2Arab as $pat => $rep ) {
358 $text = preg_replace( $pat, $rep, $text );
360 return $text;
361 break;
362 case 'kk-latn':
363 case 'kk-tr':
364 foreach ( $this->mCyrl2Latn as $pat => $rep ) {
365 $text = preg_replace( $pat, $rep, $text );
367 return $text;
368 break;
369 case 'kk-cyrl':
370 case 'kk-kz':
371 foreach ( $this->mLatn2Cyrl as $pat => $rep ) {
372 $text = preg_replace( $pat, $rep, $text );
374 return $text;
375 break;
376 default:
377 return $text;
382 * @param string $key
383 * @return string
385 function convertCategoryKey( $key ) {
386 return $this->autoConvert( $key, 'kk' );
391 * class that handles Cyrillic, Latin and Arabic scripts for Kazakh
392 * right now it only distinguish kk_cyrl, kk_latn, kk_arab and kk_kz, kk_tr, kk_cn.
394 * @ingroup Language
396 class LanguageKk extends LanguageKk_cyrl {
397 function __construct() {
398 global $wgHooks;
399 parent::__construct();
401 $variants = array( 'kk', 'kk-cyrl', 'kk-latn', 'kk-arab', 'kk-kz', 'kk-tr', 'kk-cn' );
402 $variantfallbacks = array(
403 'kk' => 'kk-cyrl',
404 'kk-cyrl' => 'kk',
405 'kk-latn' => 'kk',
406 'kk-arab' => 'kk',
407 'kk-kz' => 'kk-cyrl',
408 'kk-tr' => 'kk-latn',
409 'kk-cn' => 'kk-arab'
412 $this->mConverter = new KkConverter( $this, 'kk', $variants, $variantfallbacks );
414 $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
418 * It fixes issue with ucfirst for transforming 'i' to 'İ'
420 * @param string $string
422 * @return string
424 function ucfirst( $string ) {
425 if ( $string[0] == 'i' ) {
426 $variant = $this->getPreferredVariant();
427 if ( $variant == 'kk-latn' || $variant == 'kk-tr' ) {
428 return 'İ' . substr( $string, 1 );
431 return parent::ucfirst( $string );
435 * It fixes issue with lcfirst for transforming 'I' to 'ı'
437 * @param string $string
439 * @return string
441 function lcfirst( $string ) {
442 if ( $string[0] == 'I' ) {
443 $variant = $this->getPreferredVariant();
444 if ( $variant == 'kk-latn' || $variant == 'kk-tr' ) {
445 return 'ı' . substr( $string, 1 );
448 return parent::lcfirst( $string );
452 * @param string $word
453 * @param string $case
454 * @return string
456 function convertGrammar( $word, $case ) {
458 $variant = $this->getPreferredVariant();
459 switch ( $variant ) {
460 case 'kk-arab':
461 case 'kk-cn':
462 $word = parent::convertGrammarKk_arab( $word, $case );
463 break;
464 case 'kk-latn':
465 case 'kk-tr':
466 $word = parent::convertGrammarKk_latn( $word, $case );
467 break;
468 case 'kk-cyrl':
469 case 'kk-kz':
470 case 'kk':
471 default:
472 $word = parent::convertGrammarKk_cyrl( $word, $case );
475 return $word;