Translated using Weblate (Kurdish Sorani)
[phpmyadmin.git] / libraries / mysql_charsets.lib.php
blob4abeb5dafe75eac15d07e787d59b5a669f8aab5a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Shared code for mysql charsets
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION,
13 $name = null, $id = null, $default = null, $label = true, $indent = 0,
14 $submitOnChange = false, $displayUnavailable = false
15 ) {
16 global $mysql_charsets, $mysql_charsets_descriptions,
17 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
19 if (empty($name)) {
20 if ($type == PMA_CSDROPDOWN_COLLATION) {
21 $name = 'collation';
22 } else {
23 $name = 'character_set';
27 $return_str = '<select lang="en" dir="ltr" name="'
28 . htmlspecialchars($name) . '"'
29 . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"')
30 . ($submitOnChange ? ' class="autosubmit"' : '') . '>' . "\n";
31 if ($label) {
32 $return_str .= '<option value="">'
33 . ($type == PMA_CSDROPDOWN_COLLATION ? __('Collation') : __('Charset'))
34 . '</option>' . "\n";
36 $return_str .= '<option value=""></option>' . "\n";
37 foreach ($mysql_charsets as $current_charset) {
38 if (!$mysql_charsets_available[$current_charset]) {
39 continue;
41 $current_cs_descr
42 = empty($mysql_charsets_descriptions[$current_charset])
43 ? $current_charset
44 : $mysql_charsets_descriptions[$current_charset];
46 if ($type == PMA_CSDROPDOWN_COLLATION) {
47 $return_str .= '<optgroup label="' . $current_charset
48 . '" title="' . $current_cs_descr . '">' . "\n";
49 foreach ($mysql_collations[$current_charset] as $current_collation) {
50 if (!$mysql_collations_available[$current_collation]) {
51 continue;
53 $return_str .= '<option value="' . $current_collation
54 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
55 . ($default == $current_collation ? ' selected="selected"' : '')
56 . '>'
57 . $current_collation . '</option>' . "\n";
59 $return_str .= '</optgroup>' . "\n";
60 } else {
61 $return_str .= '<option value="' . $current_charset
62 . '" title="' . $current_cs_descr . '"'
63 . ($default == $current_charset ? ' selected="selected"' : '') . '>'
64 . $current_charset . '</option>' . "\n";
67 $return_str .= '</select>' . "\n";
69 return $return_str;
72 function PMA_generateCharsetQueryPart($collation)
74 if (!PMA_DRIZZLE) {
75 list($charset) = explode('_', $collation);
76 return ' CHARACTER SET ' . $charset
77 . ($charset == $collation ? '' : ' COLLATE ' . $collation);
78 } else {
79 return ' COLLATE ' . $collation;
83 /**
84 * returns collation of given db
86 * @param string $db name of db
88 * @return string collation of $db
90 function PMA_getDbCollation($db)
92 if ($GLOBALS['dbi']->isSystemSchema($db)) {
93 // We don't have to check the collation of the virtual
94 // information_schema database: We know it!
95 return 'utf8_general_ci';
98 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
99 // this is slow with thousands of databases
100 $sql = PMA_DRIZZLE
101 ? 'SELECT DEFAULT_COLLATION_NAME FROM data_dictionary.SCHEMAS'
102 . ' WHERE SCHEMA_NAME = \'' . PMA_Util::sqlAddSlashes($db)
103 . '\' LIMIT 1'
104 : 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA'
105 . ' WHERE SCHEMA_NAME = \'' . PMA_Util::sqlAddSlashes($db)
106 . '\' LIMIT 1';
107 return $GLOBALS['dbi']->fetchValue($sql);
108 } else {
109 $GLOBALS['dbi']->selectDb($db);
110 $return = $GLOBALS['dbi']->fetchValue(
111 'SHOW VARIABLES LIKE \'collation_database\'', 0, 1
113 if ($db !== $GLOBALS['db']) {
114 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
116 return $return;
121 * returns default server collation from show variables
123 * @return string $server_collation
125 function PMA_getServerCollation()
127 return $GLOBALS['dbi']->fetchValue(
128 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1
133 * returns description for given collation
135 * @param string $collation MySQL collation string
137 * @return string collation description
139 function PMA_getCollationDescr($collation)
141 if ($collation == 'binary') {
142 return __('Binary');
144 $parts = explode('_', $collation);
145 if (count($parts) == 1) {
146 $parts[1] = 'general';
147 } elseif ($parts[1] == 'ci' || $parts[1] == 'cs') {
148 $parts[2] = $parts[1];
149 $parts[1] = 'general';
151 $descr = '';
152 switch ($parts[1]) {
153 case 'bulgarian':
154 $descr = __('Bulgarian');
155 break;
156 case 'chinese':
157 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') {
158 $descr = __('Simplified Chinese');
159 } elseif ($parts[0] == 'big5') {
160 $descr = __('Traditional Chinese');
162 break;
163 case 'ci':
164 $descr = __('case-insensitive');
165 break;
166 case 'cs':
167 $descr = __('case-sensitive');
168 break;
169 case 'croatian':
170 $descr = __('Croatian');
171 break;
172 case 'czech':
173 $descr = __('Czech');
174 break;
175 case 'danish':
176 $descr = __('Danish');
177 break;
178 case 'english':
179 $descr = __('English');
180 break;
181 case 'esperanto':
182 $descr = __('Esperanto');
183 break;
184 case 'estonian':
185 $descr = __('Estonian');
186 break;
187 case 'german1':
188 $descr = __('German') . ' (' . __('dictionary') . ')';
189 break;
190 case 'german2':
191 $descr = __('German') . ' (' . __('phone book') . ')';
192 break;
193 case 'hungarian':
194 $descr = __('Hungarian');
195 break;
196 case 'icelandic':
197 $descr = __('Icelandic');
198 break;
199 case 'japanese':
200 $descr = __('Japanese');
201 break;
202 case 'latvian':
203 $descr = __('Latvian');
204 break;
205 case 'lithuanian':
206 $descr = __('Lithuanian');
207 break;
208 case 'korean':
209 $descr = __('Korean');
210 break;
211 case 'persian':
212 $descr = __('Persian');
213 break;
214 case 'polish':
215 $descr = __('Polish');
216 break;
217 case 'roman':
218 $descr = __('West European');
219 break;
220 case 'romanian':
221 $descr = __('Romanian');
222 break;
223 case 'slovak':
224 $descr = __('Slovak');
225 break;
226 case 'slovenian':
227 $descr = __('Slovenian');
228 break;
229 case 'spanish':
230 $descr = __('Spanish');
231 break;
232 case 'spanish2':
233 $descr = __('Traditional Spanish');
234 break;
235 case 'swedish':
236 $descr = __('Swedish');
237 break;
238 case 'thai':
239 $descr = __('Thai');
240 break;
241 case 'turkish':
242 $descr = __('Turkish');
243 break;
244 case 'ukrainian':
245 $descr = __('Ukrainian');
246 break;
247 case 'unicode':
248 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
249 break;
250 case 'bin':
251 $is_bin = true;
252 case 'general':
253 switch ($parts[0]) {
254 // Unicode charsets
255 case 'ucs2':
256 case 'utf8':
257 case 'utf8mb4':
258 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
259 break;
260 // West European charsets
261 case 'ascii':
262 case 'cp850':
263 case 'dec8':
264 case 'hp8':
265 case 'latin1':
266 case 'macroman':
267 $descr = __('West European') . ' (' . __('multilingual') . ')';
268 break;
269 // Central European charsets
270 case 'cp1250':
271 case 'cp852':
272 case 'latin2':
273 case 'macce':
274 $descr = __('Central European') . ' (' . __('multilingual') . ')';
275 break;
276 // Russian charsets
277 case 'cp866':
278 case 'koi8r':
279 $descr = __('Russian');
280 break;
281 // Simplified Chinese charsets
282 case 'gb2312':
283 case 'gbk':
284 $descr = __('Simplified Chinese');
285 break;
286 // Japanese charsets
287 case 'sjis':
288 case 'ujis':
289 case 'cp932':
290 case 'eucjpms':
291 $descr = __('Japanese');
292 break;
293 // Baltic charsets
294 case 'cp1257':
295 case 'latin7':
296 $descr = __('Baltic') . ' (' . __('multilingual') . ')';
297 break;
298 // Other
299 case 'armscii8':
300 case 'armscii':
301 $descr = __('Armenian');
302 break;
303 case 'big5':
304 $descr = __('Traditional Chinese');
305 break;
306 case 'cp1251':
307 $descr = __('Cyrillic') . ' (' . __('multilingual') . ')';
308 break;
309 case 'cp1256':
310 $descr = __('Arabic');
311 break;
312 case 'euckr':
313 $descr = __('Korean');
314 break;
315 case 'hebrew':
316 $descr = __('Hebrew');
317 break;
318 case 'geostd8':
319 $descr = __('Georgian');
320 break;
321 case 'greek':
322 $descr = __('Greek');
323 break;
324 case 'keybcs2':
325 $descr = __('Czech-Slovak');
326 break;
327 case 'koi8u':
328 $descr = __('Ukrainian');
329 break;
330 case 'latin5':
331 $descr = __('Turkish');
332 break;
333 case 'swe7':
334 $descr = __('Swedish');
335 break;
336 case 'tis620':
337 $descr = __('Thai');
338 break;
339 default:
340 $descr = __('unknown');
341 break;
343 if (!empty($is_bin)) {
344 $descr .= ', ' . __('Binary');
346 break;
347 default: $descr = __('unknown');
349 if (!empty($parts[2])) {
350 if ($parts[2] == 'ci') {
351 $descr .= ', ' . __('case-insensitive');
352 } elseif ($parts[2] == 'cs') {
353 $descr .= ', ' . __('case-sensitive');
357 return $descr;