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