Localisation updates from http://translatewiki.net.
[mediawiki.git] / languages / classes / LanguageKk.php
blobf96b0d92a4991f40d7ab95f5fe688af6d47369fc
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 {
42 protected $mCyrl2Latn, $mLatn2Cyrl, $mCyLa2Arab;
44 /**
45 * @param $langobj Language
46 * @param $maincode string
47 * @param $variants array
48 * @param $variantfallbacks array
49 * @param $flags array
51 function __construct( $langobj, $maincode,
52 $variants = array(),
53 $variantfallbacks = array(),
54 $flags = array() ) {
55 parent::__construct( $langobj, $maincode,
56 $variants, $variantfallbacks, $flags );
58 // No point delaying this since they're in code.
59 // Waiting until loadDefaultTables() means they never get loaded
60 // when the tables themselves are loaded from cache.
61 $this->loadRegs();
64 function loadDefaultTables() {
65 // require __DIR__."/../../includes/KkConversion.php";
66 // Placeholder for future implementing. Remove variables declarations
67 // after generating KkConversion.php
68 $kk2Cyrl = array();
69 $kk2Latn = array();
70 $kk2Arab = array();
71 $kk2KZ = array();
72 $kk2TR = array();
73 $kk2CN = array();
75 $this->mTables = array(
76 'kk-cyrl' => new ReplacementArray( $kk2Cyrl ),
77 'kk-latn' => new ReplacementArray( $kk2Latn ),
78 'kk-arab' => new ReplacementArray( $kk2Arab ),
79 'kk-kz' => new ReplacementArray( array_merge( $kk2Cyrl, $kk2KZ ) ),
80 'kk-tr' => new ReplacementArray( array_merge( $kk2Latn, $kk2TR ) ),
81 'kk-cn' => new ReplacementArray( array_merge( $kk2Arab, $kk2CN ) ),
82 'kk' => new ReplacementArray()
86 function postLoadTables() {
87 $this->mTables['kk-kz']->merge( $this->mTables['kk-cyrl'] );
88 $this->mTables['kk-tr']->merge( $this->mTables['kk-latn'] );
89 $this->mTables['kk-cn']->merge( $this->mTables['kk-arab'] );
92 function loadRegs() {
94 $this->mCyrl2Latn = array(
95 # # Punctuation
96 '/№/u' => 'No.',
97 # # Е after vowels
98 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])Е/u' => '$1YE',
99 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])е/ui' => '$1ye',
100 # # leading ЁЮЯЩ
101 '/^Ё([' . KK_C_UC . ']|$)/u' => 'YO$1', '/^Ё([' . KK_C_LC . ']|$)/u' => 'Yo$1',
102 '/^Ю([' . KK_C_UC . ']|$)/u' => 'YU$1', '/^Ю([' . KK_C_LC . ']|$)/u' => 'Yu$1',
103 '/^Я([' . KK_C_UC . ']|$)/u' => 'YA$1', '/^Я([' . KK_C_LC . ']|$)/u' => 'Ya$1',
104 '/^Щ([' . KK_C_UC . ']|$)/u' => 'ŞÇ$1', '/^Щ([' . KK_C_LC . ']|$)/u' => 'Şç$1',
105 # # other ЁЮЯ
106 '/Ё/u' => 'YO', '/ё/u' => 'yo',
107 '/Ю/u' => 'YU', '/ю/u' => 'yu',
108 '/Я/u' => 'YA', '/я/u' => 'ya',
109 '/Щ/u' => 'ŞÇ', '/щ/u' => 'şç',
110 # # soft and hard signs
111 '/[ъЪ]/u' => 'ʺ', '/[ьЬ]/u' => 'ʹ',
112 # # other characters
113 '/А/u' => 'A', '/а/u' => 'a', '/Ә/u' => 'Ä', '/ә/u' => 'ä',
114 '/Б/u' => 'B', '/б/u' => 'b', '/В/u' => 'V', '/в/u' => 'v',
115 '/Г/u' => 'G', '/г/u' => 'g', '/Ғ/u' => 'Ğ', '/ғ/u' => 'ğ',
116 '/Д/u' => 'D', '/д/u' => 'd', '/Е/u' => 'E', '/е/u' => 'e',
117 '/Ж/u' => 'J', '/ж/u' => 'j', '/З/u' => 'Z', '/з/u' => 'z',
118 '/И/u' => 'Ï', '/и/u' => 'ï', '/Й/u' => 'Ý', '/й/u' => 'ý',
119 '/К/u' => 'K', '/к/u' => 'k', '/Қ/u' => 'Q', '/қ/u' => 'q',
120 '/Л/u' => 'L', '/л/u' => 'l', '/М/u' => 'M', '/м/u' => 'm',
121 '/Н/u' => 'N', '/н/u' => 'n', '/Ң/u' => 'Ñ', '/ң/u' => 'ñ',
122 '/О/u' => 'O', '/о/u' => 'o', '/Ө/u' => 'Ö', '/ө/u' => 'ö',
123 '/П/u' => 'P', '/п/u' => 'p', '/Р/u' => 'R', '/р/u' => 'r',
124 '/С/u' => 'S', '/с/u' => 's', '/Т/u' => 'T', '/т/u' => 't',
125 '/У/u' => 'W', '/у/u' => 'w', '/Ұ/u' => 'U', '/ұ/u' => 'u',
126 '/Ү/u' => 'Ü', '/ү/u' => 'ü', '/Ф/u' => 'F', '/ф/u' => 'f',
127 '/Х/u' => 'X', '/х/u' => 'x', '/Һ/u' => 'H', '/һ/u' => 'h',
128 '/Ц/u' => 'C', '/ц/u' => 'c', '/Ч/u' => 'Ç', '/ч/u' => 'ç',
129 '/Ш/u' => 'Ş', '/ш/u' => 'ş', '/Ы/u' => 'I', '/ы/u' => 'ı',
130 '/І/u' => 'İ', '/і/u' => 'i', '/Э/u' => 'É', '/э/u' => 'é',
133 $this->mLatn2Cyrl = array(
134 # # Punctuation
135 '/#|No\./' => '№',
136 # # Şç
137 '/ŞÇʹ/u' => 'ЩЬ', '/Şçʹ/u' => 'Щь',
138 '/Ş[Çç]/u' => 'Щ', '/şç/u' => 'щ',
139 # # soft and hard signs
140 '/([' . KK_L_UC . '])ʺ([' . KK_L_UC . '])/u' => '$1Ъ$2',
141 '/ʺ([' . KK_L_LC . '])/u' => $1',
142 '/([' . KK_L_UC . '])ʹ([' . KK_L_UC . '])/u' => '$1Ь$2',
143 '/ʹ([' . KK_L_LC . '])/u' => $1',
144 '/ʺ/u' => 'ъ',
145 '/ʹ/u' => 'ь',
146 # # Ye Yo Yu Ya.
147 '/Y[Ee]/u' => 'Е', '/ye/u' => 'е',
148 '/Y[Oo]/u' => 'Ё', '/yo/u' => 'ё',
149 '/Y[UWuw]/u' => 'Ю', '/y[uw]/u' => 'ю',
150 '/Y[Aa]/u' => 'Я', '/ya/u' => 'я',
151 # # other characters
152 '/A/u' => 'А', '/a/u' => 'а', '/Ä/u' => 'Ә', '/ä/u' => 'ә',
153 '/B/u' => 'Б', '/b/u' => 'б', '/C/u' => 'Ц', '/c/u' => 'ц',
154 '/Ç/u' => 'Ч', '/ç/u' => 'ч', '/D/u' => 'Д', '/d/u' => 'д',
155 '/E/u' => 'Е', '/e/u' => 'е', '/É/u' => 'Э', '/é/u' => 'э',
156 '/F/u' => 'Ф', '/f/u' => 'ф', '/G/u' => 'Г', '/g/u' => 'г',
157 '/Ğ/u' => 'Ғ', '/ğ/u' => 'ғ', '/H/u' => 'Һ', '/h/u' => 'һ',
158 '/I/u' => 'Ы', '/ı/u' => 'ы', '/İ/u' => 'І', '/i/u' => 'і',
159 '/Ï/u' => 'И', '/ï/u' => 'и', '/J/u' => 'Ж', '/j/u' => 'ж',
160 '/K/u' => 'К', '/k/u' => 'к', '/L/u' => 'Л', '/l/u' => 'л',
161 '/M/u' => 'М', '/m/u' => 'м', '/N/u' => 'Н', '/n/u' => 'н',
162 '/Ñ/u' => 'Ң', '/ñ/u' => 'ң', '/O/u' => 'О', '/o/u' => 'о',
163 '/Ö/u' => 'Ө', '/ö/u' => 'ө', '/P/u' => 'П', '/p/u' => 'п',
164 '/Q/u' => 'Қ', '/q/u' => 'қ', '/R/u' => 'Р', '/r/u' => 'р',
165 '/S/u' => 'С', '/s/u' => 'с', '/Ş/u' => 'Ш', '/ş/u' => 'ш',
166 '/T/u' => 'Т', '/t/u' => 'т', '/U/u' => 'Ұ', '/u/u' => 'ұ',
167 '/Ü/u' => 'Ү', '/ü/u' => 'ү', '/V/u' => 'В', '/v/u' => 'в',
168 '/W/u' => 'У', '/w/u' => 'у', '/Ý/u' => 'Й', '/ý/u' => 'й',
169 '/X/u' => 'Х', '/x/u' => 'х', '/Z/u' => 'З', '/z/u' => 'з',
172 $this->mCyLa2Arab = array(
173 # # Punctuation -> Arabic
174 '/#|№|No\./u' => '؀', # &#x0600;
175 '/\,/' => '،', # &#x060C;
176 '/;/' => '؛', # &#x061B;
177 '/\?/' => '؟', # &#x061F;
178 '/%/' => '٪', # &#x066A;
179 '/\*/' => '٭', # &#x066D;
180 # # Digits -> Arabic
181 '/0/' => '۰', # &#x06F0;
182 '/1/' => '۱', # &#x06F1;
183 '/2/' => '۲', # &#x06F2;
184 '/3/' => '۳', # &#x06F3;
185 '/4/' => '۴', # &#x06F4;
186 '/5/' => '۵', # &#x06F5;
187 '/6/' => '۶', # &#x06F6;
188 '/7/' => '۷', # &#x06F7;
189 '/8/' => '۸', # &#x06F8;
190 '/9/' => '۹', # &#x06F9;
191 # # Cyrillic -> Arabic
192 '/Аллаһ/ui' => 'ﷲ',
193 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])е/ui' => '$1يە',
194 '/[еэ]/ui' => 'ە', '/[ъь]/ui' => '',
195 '/[аә]/ui' => 'ا', '/[оө]/ui' => 'و', '/[ұү]/ui' => 'ۇ', '/[ыі]/ui' => 'ى',
196 '/[и]/ui' => 'ىي', '/ё/ui' => 'يو', '/ю/ui' => 'يۋ', '/я/ui' => 'يا', '/[й]/ui' => 'ي',
197 '/ц/ui' => 'تس', '/щ/ui' => 'شش',
198 '/һ/ui' => 'ح', '/ч/ui' => 'تش',
199 # '/һ/ui' => 'ھ', '/ч/ui' => 'چ',
200 '/б/ui' => 'ب', '/в/ui' => 'ۆ', '/г/ui' => 'گ', '/ғ/ui' => 'ع',
201 '/д/ui' => 'د', '/ж/ui' => 'ج', '/з/ui' => 'ز', '/к/ui' => 'ك',
202 '/қ/ui' => 'ق', '/л/ui' => 'ل', '/м/ui' => 'م', '/н/ui' => 'ن',
203 '/ң/ui' => 'ڭ', '/п/ui' => 'پ', '/р/ui' => 'ر', '/с/ui' => 'س',
204 '/т/ui' => 'ت', '/у/ui' => 'ۋ', '/ф/ui' => 'ف', '/х/ui' => 'ح',
205 '/ш/ui' => 'ش',
206 # # Latin -> Arabic // commented for now...
207 /*'/Allah/ui' => 'ﷲ',
208 '/[eé]/ui' => 'ە', '/[yý]/ui' => 'ي', '/[ʺʹ]/ui' => '',
209 '/[aä]/ui' => 'ا', '/[oö]/ui' => 'و', '/[uü]/ui' => 'ۇ',
210 '/[ï]/ui' => 'ىي', '/[ıIiİ]/u' => 'ى',
211 '/c/ui' => 'تس',
212 '/ç/ui' => 'تش', '/h/ui' => 'ح',
213 #'/ç/ui' => 'چ', '/h/ui' => 'ھ',
214 '/b/ui' => 'ب','/d/ui' => 'د',
215 '/f/ui' => 'ف', '/g/ui' => 'گ', '/ğ/ui' => 'ع',
216 '/j/ui' => 'ج', '/k/ui' => 'ك', '/l/ui' => 'ل', '/m/ui' => 'م',
217 '/n/ui' => 'ن', '/ñ/ui' => 'ڭ', '/p/ui' => 'پ', '/q/ui' => 'ق',
218 '/r/ui' => 'ر', '/s/ui' => 'س', '/ş/ui' => 'ش', '/t/ui' => 'ت',
219 '/v/ui' => 'ۆ', '/w/ui' => 'ۋ', '/x/ui' => 'ح', '/z/ui' => 'ز',*/
224 * rules should be defined as -{ekavian | iyekavian-} -or-
225 * -{code:text | code:text | ...}-
227 * update: delete all rule parsing because it's not used
228 * currently, and just produces a couple of bugs
230 * @param $rule string
231 * @param $flags array
232 * @return array
234 function parseManualRule( $rule, $flags = array() ) {
235 if ( in_array( 'T', $flags ) ) {
236 return parent::parseManualRule( $rule, $flags );
239 $carray = array();
240 // otherwise ignore all formatting
241 foreach ( $this->mVariants as $v ) {
242 $carray[$v] = $rule;
245 return $carray;
249 * A function wrapper:
250 * - if there is no selected variant, leave the link
251 * names as they were
252 * - do not try to find variants for usernames
254 * @param $link string
255 * @param $nt Title
256 * @param bool $ignoreOtherCond
258 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
259 // check for user namespace
260 if ( is_object( $nt ) ) {
261 $ns = $nt->getNamespace();
262 if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
263 return;
267 $oldlink = $link;
268 parent::findVariantLink( $link, $nt, $ignoreOtherCond );
269 if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
270 $link = $oldlink;
275 * An ugly function wrapper for parsing Image titles
276 * (to prevent image name conversion)
278 * @param $text string
279 * @param $toVariant bool
281 * @return string
283 function autoConvert( $text, $toVariant = false ) {
284 global $wgTitle;
285 if ( is_object( $wgTitle ) && $wgTitle->getNamespace() == NS_FILE ) {
286 $imagename = $wgTitle->getNsText();
287 if ( preg_match( "/^$imagename:/", $text ) ) {
288 return $text;
291 return parent::autoConvert( $text, $toVariant );
295 * It translates text into variant
297 * @param $text string
298 * @param $toVariant string
300 * @return string
302 function translate( $text, $toVariant ) {
303 global $wgLanguageCode;
304 $text = parent::translate( $text, $toVariant );
306 switch ( $toVariant ) {
307 case 'kk-cyrl':
308 case 'kk-kz':
309 $letters = KK_L_UC . KK_L_LC . 'ʺʹ#0123456789';
310 $wgLanguageCode = 'kk';
311 break;
312 case 'kk-latn':
313 case 'kk-tr':
314 $letters = KK_C_UC . KK_C_LC . '№0123456789';
315 $wgLanguageCode = 'kk-Latn';
316 break;
317 case 'kk-arab':
318 case 'kk-cn':
319 $letters = KK_C_UC . KK_C_LC . /*KK_L_UC.KK_L_LC.'ʺʹ'.*/',;\?%\*№0123456789';
320 $wgLanguageCode = 'kk-Arab';
321 break;
322 default:
323 $wgLanguageCode = 'kk';
324 return $text;
326 // disable conversion variables like $1, $2...
327 $varsfix = '\$[0-9]';
329 $matches = preg_split( '/' . $varsfix . '[^' . $letters . ']+/u', $text, -1, PREG_SPLIT_OFFSET_CAPTURE );
330 $mstart = 0;
331 $ret = '';
332 foreach ( $matches as $m ) {
333 $ret .= substr( $text, $mstart, $m[1] -$mstart );
334 $ret .= $this->regsConverter( $m[0], $toVariant );
335 $mstart = $m[1] + strlen( $m[0] );
337 return $ret;
341 * @param $text string
342 * @param $toVariant string
343 * @return mixed|string
345 function regsConverter( $text, $toVariant ) {
346 if ( $text == '' ) {
347 return $text;
350 switch ( $toVariant ) {
351 case 'kk-arab':
352 case 'kk-cn':
353 $letters = KK_C_LC . KK_C_UC/*.KK_L_LC.KK_L_UC*/;
354 $front = 'әөүіӘӨҮІ'/*.'äöüiÄÖÜİ'*/;
355 $excludes = 'еэгғкқЕЭГҒКҚ'/*.'eégğkqEÉGĞKQ'*/;
356 // split text to words
357 $matches = preg_split( '/[\b\s\-\.:]+/', $text, -1, PREG_SPLIT_OFFSET_CAPTURE );
358 $mstart = 0;
359 $ret = '';
360 foreach ( $matches as $m ) {
361 $ret .= substr( $text, $mstart, $m[1] - $mstart );
362 // is matched the word to front vowels?
363 // exclude a words matched to е, э, г, к, к, қ,
364 // them should be without hamza
365 if ( preg_match( '/[' . $front . ']/u', $m[0] ) && !preg_match( '/[' . $excludes . ']/u', $m[0] ) ) {
366 $ret .= preg_replace( '/[' . $letters . ']+/u', H_HAMZA . '$0', $m[0] );
367 } else {
368 $ret .= $m[0];
370 $mstart = $m[1] + strlen( $m[0] );
372 $text =& $ret;
373 foreach ( $this->mCyLa2Arab as $pat => $rep ) {
374 $text = preg_replace( $pat, $rep, $text );
376 return $text;
377 break;
378 case 'kk-latn':
379 case 'kk-tr':
380 foreach ( $this->mCyrl2Latn as $pat => $rep ) {
381 $text = preg_replace( $pat, $rep, $text );
383 return $text;
384 break;
385 case 'kk-cyrl':
386 case 'kk-kz':
387 foreach ( $this->mLatn2Cyrl as $pat => $rep ) {
388 $text = preg_replace( $pat, $rep, $text );
390 return $text;
391 break;
392 default:
393 return $text;
398 * @param $key string
399 * @return String
401 function convertCategoryKey( $key ) {
402 return $this->autoConvert( $key, 'kk' );
408 * class that handles Cyrillic, Latin and Arabic scripts for Kazakh
409 * right now it only distinguish kk_cyrl, kk_latn, kk_arab and kk_kz, kk_tr, kk_cn.
411 * @ingroup Language
413 class LanguageKk extends LanguageKk_cyrl {
415 function __construct() {
416 global $wgHooks;
417 parent::__construct();
419 $variants = array( 'kk', 'kk-cyrl', 'kk-latn', 'kk-arab', 'kk-kz', 'kk-tr', 'kk-cn' );
420 $variantfallbacks = array(
421 'kk' => 'kk-cyrl',
422 'kk-cyrl' => 'kk',
423 'kk-latn' => 'kk',
424 'kk-arab' => 'kk',
425 'kk-kz' => 'kk-cyrl',
426 'kk-tr' => 'kk-latn',
427 'kk-cn' => 'kk-arab'
430 $this->mConverter = new KkConverter( $this, 'kk', $variants, $variantfallbacks );
432 $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
436 * It fixes issue with ucfirst for transforming 'i' to 'İ'
438 * @param $string string
440 * @return string
442 function ucfirst( $string ) {
443 $variant = $this->getPreferredVariant();
444 if ( ( $variant == 'kk-latn' || $variant == 'kk-tr' ) && $string[0] == 'i' ) {
445 $string = 'İ' . substr( $string, 1 );
446 } else {
447 $string = parent::ucfirst( $string );
449 return $string;
453 * It fixes issue with lcfirst for transforming 'I' to 'ı'
455 * @param $string string
457 * @return string
459 function lcfirst( $string ) {
460 $variant = $this->getPreferredVariant();
461 if ( ( $variant == 'kk-latn' || $variant == 'kk-tr' ) && $string[0] == 'I' ) {
462 $string = 'ı' . substr( $string, 1 );
463 } else {
464 $string = parent::lcfirst( $string );
466 return $string;
470 * @param $word string
471 * @param $case string
472 * @return string
474 function convertGrammar( $word, $case ) {
475 wfProfileIn( __METHOD__ );
477 $variant = $this->getPreferredVariant();
478 switch ( $variant ) {
479 case 'kk-arab':
480 case 'kk-cn':
481 $word = parent::convertGrammarKk_arab( $word, $case );
482 break;
483 case 'kk-latn':
484 case 'kk-tr':
485 $word = parent::convertGrammarKk_latn( $word, $case );
486 break;
487 case 'kk-cyrl':
488 case 'kk-kz':
489 case 'kk':
490 default:
491 $word = parent::convertGrammarKk_cyrl( $word, $case );
494 wfProfileOut( __METHOD__ );
495 return $word;