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
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
33 * Kazakh (Қазақша) converter routines
37 class KkConverter
extends LanguageConverter
{
38 protected $mCyrl2Latn, $mLatn2Cyrl, $mCyLa2Arab;
41 * @param Language $langobj
42 * @param string $maincode
43 * @param array $variants
44 * @param array $variantfallbacks
47 function __construct( $langobj, $maincode,
49 $variantfallbacks = [],
51 parent
::__construct( $langobj, $maincode,
52 $variants, $variantfallbacks, $flags );
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.
60 function loadDefaultTables() {
61 // require __DIR__."/../../includes/KkConversion.php";
62 // Placeholder for future implementing. Remove variables declarations
63 // after generating KkConversion.php
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()
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'] );
94 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])Е/u' => '$1YE',
95 '/([АӘЕЁИОӨҰҮЭЮЯЪЬ])е/ui' => '$1ye',
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',
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' => 'ʹ',
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' => 'é',
129 $this->mLatn2Cyrl
= [
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',
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' => 'я',
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' => 'з',
168 $this->mCyLa2Arab
= [
169 # # Punctuation -> Arabic
170 '/#|№|No\./u' => '', # ؀
171 '/\,/' => '،', # ،
172 '/;/' => '؛', # ؛
173 '/\?/' => '؟', # ؟
174 '/%/' => '٪', # ٪
175 '/\*/' => '٭', # ٭
177 '/0/' => '۰', # ۰
178 '/1/' => '۱', # ۱
179 '/2/' => '۲', # ۲
180 '/3/' => '۳', # ۳
181 '/4/' => '۴', # ۴
182 '/5/' => '۵', # ۵
183 '/6/' => '۶', # ۶
184 '/7/' => '۷', # ۷
185 '/8/' => '۸', # ۸
186 '/9/' => '۹', # ۹
187 # # Cyrillic -> Arabic
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' => 'ح',
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' => 'ى',
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' => 'ز',*/
220 * A function wrapper:
221 * - if there is no selected variant, leave the link
223 * - do not try to find variants for usernames
225 * @param string &$link
227 * @param bool $ignoreOtherCond
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
) {
239 parent
::findVariantLink( $link, $nt, $ignoreOtherCond );
240 if ( $this->getPreferredVariant() == $this->mMainLanguageCode
) {
246 * It translates text into variant
248 * @param string $text
249 * @param string $toVariant
253 function translate( $text, $toVariant ) {
254 $text = parent
::translate( $text, $toVariant );
256 switch ( $toVariant ) {
259 $letters = KK_L_UC
. KK_L_LC
. 'ʺʹ#0123456789';
263 $letters = KK_C_UC
. KK_C_LC
. '№0123456789';
267 $letters = KK_C_UC
. KK_C_LC
. /*KK_L_UC.KK_L_LC.'ʺʹ'.*/',;\?%\*№0123456789';
272 // disable conversion variables like $1, $2...
273 $varsfix = '\$[0-9]';
275 $matches = preg_split(
276 '/' . $varsfix . '[^' . $letters . ']+/u',
279 PREG_SPLIT_OFFSET_CAPTURE
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] );
295 * @param string $text
296 * @param string $toVariant
297 * @return mixed|string
299 function regsConverter( $text, $toVariant ) {
304 switch ( $toVariant ) {
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
);
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] )
322 $ret .= preg_replace( '/[' . $letters . ']+/u', H_HAMZA
. '$0', $m[0] );
326 $mstart = $m[1] +
strlen( $m[0] );
329 foreach ( $this->mCyLa2Arab
as $pat => $rep ) {
330 $text = preg_replace( $pat, $rep, $text );
336 foreach ( $this->mCyrl2Latn
as $pat => $rep ) {
337 $text = preg_replace( $pat, $rep, $text );
343 foreach ( $this->mLatn2Cyrl
as $pat => $rep ) {
344 $text = preg_replace( $pat, $rep, $text );
357 function convertCategoryKey( $key ) {
358 return $this->autoConvert( $key, 'kk' );
363 * class that handles Cyrillic, Latin and Arabic scripts for Kazakh
364 * right now it only distinguish kk_cyrl, kk_latn, kk_arab and kk_kz, kk_tr, kk_cn.
368 class LanguageKk
extends LanguageKk_cyrl
{
369 function __construct() {
370 parent
::__construct();
372 $variants = [ 'kk', 'kk-cyrl', 'kk-latn', 'kk-arab', 'kk-kz', 'kk-tr', 'kk-cn' ];
373 $variantfallbacks = [
378 'kk-kz' => 'kk-cyrl',
379 'kk-tr' => 'kk-latn',
383 $this->mConverter
= new KkConverter( $this, 'kk', $variants, $variantfallbacks );
387 * It fixes issue with ucfirst for transforming 'i' to 'İ'
389 * @param string $string
393 public function ucfirst( $string ) {
394 if ( $string[0] == 'i' ) {
395 $variant = $this->getPreferredVariant();
396 if ( $variant == 'kk-latn' ||
$variant == 'kk-tr' ) {
397 return 'İ' . substr( $string, 1 );
400 return parent
::ucfirst( $string );
404 * It fixes issue with lcfirst for transforming 'I' to 'ı'
406 * @param string $string
410 function lcfirst( $string ) {
411 if ( $string[0] == 'I' ) {
412 $variant = $this->getPreferredVariant();
413 if ( $variant == 'kk-latn' ||
$variant == 'kk-tr' ) {
414 return 'ı' . substr( $string, 1 );
417 return parent
::lcfirst( $string );
421 * @param string $word
422 * @param string $case
425 function convertGrammar( $word, $case ) {
427 $variant = $this->getPreferredVariant();
428 switch ( $variant ) {
431 $word = parent
::convertGrammarKk_arab( $word, $case );
435 $word = parent
::convertGrammarKk_latn( $word, $case );
441 $word = parent
::convertGrammarKk_cyrl( $word, $case );