MediaWiki REL1_35
UzConverter.php
Go to the documentation of this file.
1<?php
28 public $toLatin = [
29 'а' => 'a', 'А' => 'A',
30 'б' => 'b', 'Б' => 'B',
31 'д' => 'd', 'Д' => 'D',
32 'е' => 'e', 'Е' => 'E',
33 'э' => 'e', 'Э' => 'E',
34 'в' => 'v', 'В' => 'V',
35 'х' => 'x', 'Х' => 'X',
36 'ғ' => 'gʻ', 'Ғ' => 'Gʻ',
37 'г' => 'g', 'Г' => 'G',
38 'ҳ' => 'h', 'Ҳ' => 'H',
39 'ж' => 'j', 'Ж' => 'J',
40 'з' => 'z', 'З' => 'Z',
41 'и' => 'i', 'И' => 'I',
42 'к' => 'k', 'К' => 'K',
43 'л' => 'l', 'Л' => 'L',
44 'м' => 'm', 'М' => 'M',
45 'н' => 'n', 'Н' => 'N',
46 'о' => 'o', 'О' => 'O',
47 'п' => 'p', 'П' => 'P',
48 'р' => 'r', 'Р' => 'R',
49 'с' => 's', 'С' => 'S',
50 'т' => 't', 'Т' => 'T',
51 'у' => 'u', 'У' => 'U',
52 'ф' => 'f', 'Ф' => 'F',
53 'ў' => 'oʻ', 'Ў' => 'Oʻ',
54 // note: at the beginning of a word and right after a consonant, only "s" is used
55 'ц' => 'ts', 'Ц' => 'Ts',
56 'қ' => 'q', 'Қ' => 'Q',
57 'ё' => 'yo', 'Ё' => 'Yo',
58 'ю' => 'yu', 'Ю' => 'Yu',
59 'ч' => 'ch', 'Ч' => 'Ch',
60 'ш' => 'sh', 'Ш' => 'Sh',
61 'й' => 'y', 'Й' => 'Y',
62 'я' => 'ya', 'Я' => 'Ya',
63 'ъ' => 'ʼ',
64 ];
65
66 public $toCyrillic = [
67 'a' => 'а', 'A' => 'А',
68 'b' => 'б', 'B' => 'Б',
69 'd' => 'д', 'D' => 'Д',
70 // at the beginning of a word and after a vowel, "э" is used instead of "e"
71 // (see regex below)
72 'e' => 'э', 'E' => 'Э',
73 'f' => 'ф', 'F' => 'Ф',
74 'g' => 'г', 'G' => 'Г',
75 'g‘' => 'ғ', 'G‘' => 'Ғ', 'gʻ' => 'ғ', 'Gʻ' => 'Ғ',
76 'h' => 'ҳ', 'H' => 'Ҳ',
77 'i' => 'и', 'I' => 'И',
78 'k' => 'к', 'K' => 'К',
79 'l' => 'л', 'L' => 'Л',
80 'm' => 'м', 'M' => 'М',
81 'n' => 'н', 'N' => 'Н',
82 'o' => 'о', 'O' => 'О',
83 'p' => 'п', 'P' => 'П',
84 'r' => 'р', 'R' => 'Р',
85 's' => 'с', 'S' => 'С',
86 't' => 'т', 'T' => 'Т',
87 'u' => 'у', 'U' => 'У',
88 'v' => 'в', 'V' => 'В',
89 'x' => 'х', 'X' => 'Х',
90 'z' => 'з', 'Z' => 'З',
91 'j' => 'ж', 'J' => 'Ж',
92 'o‘' => 'ў', 'O‘' => 'Ў', 'oʻ' => 'ў', 'Oʻ' => 'Ў',
93 'yo‘' => 'йў', 'Yo‘' => 'Йў', 'yoʻ' => 'йў', 'Yoʻ' => 'Йў',
94 'ts' => 'ц', 'Ts' => 'Ц',
95 'q' => 'қ', 'Q' => 'Қ',
96 'yo' => 'ё', 'Yo' => 'Ё',
97 'yu' => 'ю', 'Yu' => 'Ю',
98 'ch' => 'ч', 'Ch' => 'Ч',
99 'sh' => 'ш', 'Sh' => 'Ш',
100 'y' => 'й', 'Y' => 'Й',
101 'ya' => 'я', 'Ya' => 'Я',
102 'ʼ' => 'ъ',
103 ];
104
108 public function __construct( $langobj ) {
109 $variants = [ 'uz', 'uz-latn', 'uz-cyrl' ];
110 $variantfallbacks = [
111 'uz' => 'uz-latn',
112 'uz-cyrl' => 'uz',
113 'uz-latn' => 'uz',
114 ];
115 parent::__construct( $langobj, 'uz', $variants, $variantfallbacks );
116 }
117
118 protected function loadDefaultTables() {
119 $this->mTables = [
120 'uz-cyrl' => new ReplacementArray( $this->toCyrillic ),
121 'uz-latn' => new ReplacementArray( $this->toLatin ),
122 'uz' => new ReplacementArray()
123 ];
124 }
125
126 public function translate( $text, $toVariant ) {
127 if ( $toVariant == 'uz-cyrl' ) {
128 $text = str_replace( 'ye', 'е', $text );
129 $text = str_replace( 'Ye', 'Е', $text );
130 $text = str_replace( 'YE', 'Е', $text );
131 // "е" after consonants, otherwise "э" (see above)
132 $text = preg_replace( '/([BVGDJZYKLMNPRSTFXCWQʻ‘H])E/u', '$1Е', $text );
133 $text = preg_replace( '/([bvgdjzyklmnprstfxcwqʻ‘h])e/ui', '$1е', $text );
134 }
135 return parent::translate( $text, $toVariant );
136 }
137
138}
Base class for multi-variant language conversion.
Wrapper around strtr() that holds replacements.
__construct( $langobj)
loadDefaultTables()
Load default conversion tables.
translate( $text, $toVariant)
Translate a string to a variant.