Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
73.68% |
14 / 19 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
UzConverter | |
73.68% |
14 / 19 |
|
80.00% |
4 / 5 |
6.66 | |
0.00% |
0 / 1 |
getMainCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLanguageVariants | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getVariantsFallbacks | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
loadDefaultTables | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
translate | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | /** |
22 | * Uzbek specific code. |
23 | * |
24 | * @ingroup Languages |
25 | */ |
26 | class UzConverter extends LanguageConverter { |
27 | private const TO_LATIN = [ |
28 | 'а' => 'a', 'А' => 'A', |
29 | 'б' => 'b', 'Б' => 'B', |
30 | 'д' => 'd', 'Д' => 'D', |
31 | 'е' => 'e', 'Е' => 'E', |
32 | 'э' => 'e', 'Э' => 'E', |
33 | 'в' => 'v', 'В' => 'V', |
34 | 'х' => 'x', 'Х' => 'X', |
35 | 'ғ' => 'gʻ', 'Ғ' => 'Gʻ', |
36 | 'г' => 'g', 'Г' => 'G', |
37 | 'ҳ' => 'h', 'Ҳ' => 'H', |
38 | 'ж' => 'j', 'Ж' => 'J', |
39 | 'з' => 'z', 'З' => 'Z', |
40 | 'и' => 'i', 'И' => 'I', |
41 | 'к' => 'k', 'К' => 'K', |
42 | 'л' => 'l', 'Л' => 'L', |
43 | 'м' => 'm', 'М' => 'M', |
44 | 'н' => 'n', 'Н' => 'N', |
45 | 'о' => 'o', 'О' => 'O', |
46 | 'п' => 'p', 'П' => 'P', |
47 | 'р' => 'r', 'Р' => 'R', |
48 | 'с' => 's', 'С' => 'S', |
49 | 'т' => 't', 'Т' => 'T', |
50 | 'у' => 'u', 'У' => 'U', |
51 | 'ф' => 'f', 'Ф' => 'F', |
52 | 'ў' => 'oʻ', 'Ў' => 'Oʻ', |
53 | // note: at the beginning of a word and right after a consonant, only "s" is used |
54 | 'ц' => 'ts', 'Ц' => 'Ts', |
55 | 'қ' => 'q', 'Қ' => 'Q', |
56 | 'ё' => 'yo', 'Ё' => 'Yo', |
57 | 'ю' => 'yu', 'Ю' => 'Yu', |
58 | 'ч' => 'ch', 'Ч' => 'Ch', |
59 | 'ш' => 'sh', 'Ш' => 'Sh', |
60 | 'й' => 'y', 'Й' => 'Y', |
61 | 'я' => 'ya', 'Я' => 'Ya', |
62 | 'ъ' => 'ʼ', |
63 | ]; |
64 | |
65 | private const TO_CYRILLIC = [ |
66 | 'a' => 'а', 'A' => 'А', |
67 | 'b' => 'б', 'B' => 'Б', |
68 | 'd' => 'д', 'D' => 'Д', |
69 | // at the beginning of a word and after a vowel, "э" is used instead of "e" |
70 | // (see regex below) |
71 | 'e' => 'э', 'E' => 'Э', |
72 | 'f' => 'ф', 'F' => 'Ф', |
73 | 'g' => 'г', 'G' => 'Г', |
74 | 'g‘' => 'ғ', 'G‘' => 'Ғ', 'gʻ' => 'ғ', 'Gʻ' => 'Ғ', |
75 | 'h' => 'ҳ', 'H' => 'Ҳ', |
76 | 'i' => 'и', 'I' => 'И', |
77 | 'k' => 'к', 'K' => 'К', |
78 | 'l' => 'л', 'L' => 'Л', |
79 | 'm' => 'м', 'M' => 'М', |
80 | 'n' => 'н', 'N' => 'Н', |
81 | 'o' => 'о', 'O' => 'О', |
82 | 'p' => 'п', 'P' => 'П', |
83 | 'r' => 'р', 'R' => 'Р', |
84 | 's' => 'с', 'S' => 'С', |
85 | 't' => 'т', 'T' => 'Т', |
86 | 'u' => 'у', 'U' => 'У', |
87 | 'v' => 'в', 'V' => 'В', |
88 | 'x' => 'х', 'X' => 'Х', |
89 | 'z' => 'з', 'Z' => 'З', |
90 | 'j' => 'ж', 'J' => 'Ж', |
91 | 'o‘' => 'ў', 'O‘' => 'Ў', 'oʻ' => 'ў', 'Oʻ' => 'Ў', |
92 | 'yo‘' => 'йў', 'Yo‘' => 'Йў', 'yoʻ' => 'йў', 'Yoʻ' => 'Йў', |
93 | 'ts' => 'ц', 'Ts' => 'Ц', |
94 | 'q' => 'қ', 'Q' => 'Қ', |
95 | 'yo' => 'ё', 'Yo' => 'Ё', |
96 | 'yu' => 'ю', 'Yu' => 'Ю', |
97 | 'ch' => 'ч', 'Ch' => 'Ч', |
98 | 'sh' => 'ш', 'Sh' => 'Ш', |
99 | 'y' => 'й', 'Y' => 'Й', |
100 | 'ya' => 'я', 'Ya' => 'Я', |
101 | 'ʼ' => 'ъ', |
102 | ]; |
103 | |
104 | public function getMainCode(): string { |
105 | return 'uz'; |
106 | } |
107 | |
108 | public function getLanguageVariants(): array { |
109 | return [ 'uz', 'uz-latn', 'uz-cyrl' ]; |
110 | } |
111 | |
112 | public function getVariantsFallbacks(): array { |
113 | return [ |
114 | 'uz' => 'uz-latn', |
115 | 'uz-cyrl' => 'uz', |
116 | 'uz-latn' => 'uz', |
117 | ]; |
118 | } |
119 | |
120 | protected function loadDefaultTables(): array { |
121 | return [ |
122 | 'uz-cyrl' => new ReplacementArray( self::TO_CYRILLIC ), |
123 | 'uz-latn' => new ReplacementArray( self::TO_LATIN ), |
124 | 'uz' => new ReplacementArray() |
125 | ]; |
126 | } |
127 | |
128 | public function translate( $text, $toVariant ) { |
129 | if ( $toVariant == 'uz-cyrl' ) { |
130 | $text = str_replace( 'ye', 'е', $text ); |
131 | $text = str_replace( 'Ye', 'Е', $text ); |
132 | $text = str_replace( 'YE', 'Е', $text ); |
133 | // "е" after consonants, otherwise "э" (see above) |
134 | $text = preg_replace( '/([BVGDJZYKLMNPRSTFXCWQʻ‘H])E/u', '$1Е', $text ); |
135 | $text = preg_replace( '/([bvgdjzyklmnprstfxcwqʻ‘h])e/ui', '$1е', $text ); |
136 | } |
137 | return parent::translate( $text, $toVariant ); |
138 | } |
139 | } |