MediaWiki REL1_32
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( Language $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' => '؀', # U+0600
170 '/\,/' => '،', # U+060C
171 '/;/' => '؛', # U+061B
172 '/\?/' => '؟', # U+061F
173 '/%/' => '٪', # U+066A
174 '/\*/' => '٭', # U+066D
175 # # Digits -> Arabic
176 '/0/' => '۰', # U+06F0
177 '/1/' => '۱', # U+06F1
178 '/2/' => '۲', # U+06F2
179 '/3/' => '۳', # U+06F3
180 '/4/' => '۴', # U+06F4
181 '/5/' => '۵', # U+06F5
182 '/6/' => '۶', # U+06F6
183 '/7/' => '۷', # U+06F7
184 '/8/' => '۸', # U+06F8
185 '/9/' => '۹', # U+06F9
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 case 'kk-latn':
333 case 'kk-tr':
334 foreach ( $this->mCyrl2Latn as $pat => $rep ) {
335 $text = preg_replace( $pat, $rep, $text );
336 }
337 return $text;
338 case 'kk-cyrl':
339 case 'kk-kz':
340 foreach ( $this->mLatn2Cyrl as $pat => $rep ) {
341 $text = preg_replace( $pat, $rep, $text );
342 }
343 return $text;
344 default:
345 return $text;
346 }
347 }
348
353 function convertCategoryKey( $key ) {
354 return $this->autoConvert( $key, 'kk' );
355 }
356}
357
365 function __construct() {
366 parent::__construct();
367
368 $variants = [ 'kk', 'kk-cyrl', 'kk-latn', 'kk-arab', 'kk-kz', 'kk-tr', 'kk-cn' ];
369 $variantfallbacks = [
370 'kk' => 'kk-cyrl',
371 'kk-cyrl' => 'kk',
372 'kk-latn' => 'kk',
373 'kk-arab' => 'kk',
374 'kk-kz' => 'kk-cyrl',
375 'kk-tr' => 'kk-latn',
376 'kk-cn' => 'kk-arab'
377 ];
378
379 $this->mConverter = new KkConverter( $this, 'kk', $variants, $variantfallbacks );
380 }
381
389 public function ucfirst( $string ) {
390 if ( substr( $string, 0, 1 ) === 'i' ) {
391 $variant = $this->getPreferredVariant();
392 if ( $variant == 'kk-latn' || $variant == 'kk-tr' ) {
393 return 'İ' . substr( $string, 1 );
394 }
395 }
396 return parent::ucfirst( $string );
397 }
398
406 function lcfirst( $string ) {
407 if ( substr( $string, 0, 1 ) === 'I' ) {
408 $variant = $this->getPreferredVariant();
409 if ( $variant == 'kk-latn' || $variant == 'kk-tr' ) {
410 return 'ı' . substr( $string, 1 );
411 }
412 }
413 return parent::lcfirst( $string );
414 }
415
421 function convertGrammar( $word, $case ) {
422 $variant = $this->getPreferredVariant();
423 switch ( $variant ) {
424 case 'kk-arab':
425 case 'kk-cn':
426 $word = parent::convertGrammarKk_arab( $word, $case );
427 break;
428 case 'kk-latn':
429 case 'kk-tr':
430 $word = parent::convertGrammarKk_latn( $word, $case );
431 break;
432 case 'kk-cyrl':
433 case 'kk-kz':
434 case 'kk':
435 default:
436 $word = parent::convertGrammarKk_cyrl( $word, $case );
437 }
438
439 return $word;
440 }
441}
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)
translate( $text, $toVariant)
It translates text into variant.
__construct(Language $langobj, $maincode, $variants=[], $variantfallbacks=[], $flags=[])
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 'İ'.
Internationalisation code.
Definition Language.php:35
getPreferredVariant()
Wrapper around strtr() that holds replacements.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const NS_USER
Definition Defines.php:66
const NS_USER_TALK
Definition Defines.php:67
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:2054
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:3106
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37