Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / mysql_charsets.lib.php
bloba79699c100a00a2b2acbd65778783fa0c0ba5fab
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 /**
13 * Generate charset dropdown box
15 * @param int $type Type
16 * @param string $name Element name
17 * @param string $id Element id
18 * @param null|string $default Default value
19 * @param bool $label Label
20 * @param bool $submitOnChange Submit on change
22 * @return string
24 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION,
25 $name = null, $id = null, $default = null, $label = true,
26 $submitOnChange = false
27 ) {
28 global $mysql_charsets, $mysql_charsets_descriptions,
29 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
31 if (empty($name)) {
32 if ($type == PMA_CSDROPDOWN_COLLATION) {
33 $name = 'collation';
34 } else {
35 $name = 'character_set';
39 $return_str = '<select lang="en" dir="ltr" name="'
40 . htmlspecialchars($name) . '"'
41 . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"')
42 . ($submitOnChange ? ' class="autosubmit"' : '') . '>' . "\n";
43 if ($label) {
44 $return_str .= '<option value="">'
45 . ($type == PMA_CSDROPDOWN_COLLATION ? __('Collation') : __('Charset'))
46 . '</option>' . "\n";
48 $return_str .= '<option value=""></option>' . "\n";
49 foreach ($mysql_charsets as $current_charset) {
50 if (!$mysql_charsets_available[$current_charset]) {
51 continue;
53 $current_cs_descr
54 = empty($mysql_charsets_descriptions[$current_charset])
55 ? $current_charset
56 : $mysql_charsets_descriptions[$current_charset];
58 if ($type == PMA_CSDROPDOWN_COLLATION) {
59 $return_str .= '<optgroup label="' . $current_charset
60 . '" title="' . $current_cs_descr . '">' . "\n";
61 foreach ($mysql_collations[$current_charset] as $current_collation) {
62 if (!$mysql_collations_available[$current_collation]) {
63 continue;
65 $return_str .= '<option value="' . $current_collation
66 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
67 . ($default == $current_collation ? ' selected="selected"' : '')
68 . '>'
69 . $current_collation . '</option>' . "\n";
71 $return_str .= '</optgroup>' . "\n";
72 } else {
73 $return_str .= '<option value="' . $current_charset
74 . '" title="' . $current_cs_descr . '"'
75 . ($default == $current_charset ? ' selected="selected"' : '') . '>'
76 . $current_charset . '</option>' . "\n";
79 $return_str .= '</select>' . "\n";
81 return $return_str;
84 /**
85 * Generate the charset query part
87 * @param string $collation Collation
89 * @return string
91 function PMA_generateCharsetQueryPart($collation)
93 if (!PMA_DRIZZLE) {
94 list($charset) = explode('_', $collation);
95 return ' CHARACTER SET ' . $charset
96 . ($charset == $collation ? '' : ' COLLATE ' . $collation);
97 } else {
98 return ' COLLATE ' . $collation;
103 * returns collation of given db
105 * @param string $db name of db
107 * @return string collation of $db
109 function PMA_getDbCollation($db)
111 if ($GLOBALS['dbi']->isSystemSchema($db)) {
112 // We don't have to check the collation of the virtual
113 // information_schema database: We know it!
114 return 'utf8_general_ci';
117 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
118 // this is slow with thousands of databases
119 $sql = PMA_DRIZZLE
120 ? 'SELECT DEFAULT_COLLATION_NAME FROM data_dictionary.SCHEMAS'
121 . ' WHERE SCHEMA_NAME = \'' . PMA_Util::sqlAddSlashes($db)
122 . '\' LIMIT 1'
123 : 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA'
124 . ' WHERE SCHEMA_NAME = \'' . PMA_Util::sqlAddSlashes($db)
125 . '\' LIMIT 1';
126 return $GLOBALS['dbi']->fetchValue($sql);
127 } else {
128 $GLOBALS['dbi']->selectDb($db);
129 $return = $GLOBALS['dbi']->fetchValue(
130 'SHOW VARIABLES LIKE \'collation_database\'', 0, 1
132 if ($db !== $GLOBALS['db']) {
133 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
135 return $return;
140 * returns default server collation from show variables
142 * @return string $server_collation
144 function PMA_getServerCollation()
146 return $GLOBALS['dbi']->fetchValue(
147 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1
152 * returns description for given collation
154 * @param string $collation MySQL collation string
156 * @return string collation description
158 function PMA_getCollationDescr($collation)
160 if ($collation == 'binary') {
161 return __('Binary');
163 $parts = explode('_', $collation);
164 if (count($parts) == 1) {
165 $parts[1] = 'general';
166 } elseif ($parts[1] == 'ci' || $parts[1] == 'cs') {
167 $parts[2] = $parts[1];
168 $parts[1] = 'general';
170 $descr = '';
171 switch ($parts[1]) {
172 case 'bulgarian':
173 $descr = __('Bulgarian');
174 break;
175 case 'chinese':
176 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') {
177 $descr = __('Simplified Chinese');
178 } elseif ($parts[0] == 'big5') {
179 $descr = __('Traditional Chinese');
181 break;
182 case 'ci':
183 $descr = __('case-insensitive');
184 break;
185 case 'cs':
186 $descr = __('case-sensitive');
187 break;
188 case 'croatian':
189 $descr = __('Croatian');
190 break;
191 case 'czech':
192 $descr = __('Czech');
193 break;
194 case 'danish':
195 $descr = __('Danish');
196 break;
197 case 'english':
198 $descr = __('English');
199 break;
200 case 'esperanto':
201 $descr = __('Esperanto');
202 break;
203 case 'estonian':
204 $descr = __('Estonian');
205 break;
206 case 'german1':
207 $descr = __('German') . ' (' . __('dictionary') . ')';
208 break;
209 case 'german2':
210 $descr = __('German') . ' (' . __('phone book') . ')';
211 break;
212 case 'hungarian':
213 $descr = __('Hungarian');
214 break;
215 case 'icelandic':
216 $descr = __('Icelandic');
217 break;
218 case 'japanese':
219 $descr = __('Japanese');
220 break;
221 case 'latvian':
222 $descr = __('Latvian');
223 break;
224 case 'lithuanian':
225 $descr = __('Lithuanian');
226 break;
227 case 'korean':
228 $descr = __('Korean');
229 break;
230 case 'persian':
231 $descr = __('Persian');
232 break;
233 case 'polish':
234 $descr = __('Polish');
235 break;
236 case 'roman':
237 $descr = __('West European');
238 break;
239 case 'romanian':
240 $descr = __('Romanian');
241 break;
242 case 'sinhala':
243 $descr = __('Sinhalese');
244 break;
245 case 'slovak':
246 $descr = __('Slovak');
247 break;
248 case 'slovenian':
249 $descr = __('Slovenian');
250 break;
251 case 'spanish':
252 $descr = __('Spanish');
253 break;
254 case 'spanish2':
255 $descr = __('Traditional Spanish');
256 break;
257 case 'swedish':
258 $descr = __('Swedish');
259 break;
260 case 'thai':
261 $descr = __('Thai');
262 break;
263 case 'turkish':
264 $descr = __('Turkish');
265 break;
266 case 'ukrainian':
267 $descr = __('Ukrainian');
268 break;
269 case 'unicode':
270 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
271 break;
272 case 'vietnamese':
273 $descr = __('Vietnamese');
274 break;
275 case 'bin':
276 $is_bin = true;
277 // no break; statement here, continuing with 'general' section:
278 case 'general':
279 switch ($parts[0]) {
280 // Unicode charsets
281 case 'ucs2':
282 case 'utf8':
283 case 'utf8mb4':
284 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
285 break;
286 // West European charsets
287 case 'ascii':
288 case 'cp850':
289 case 'dec8':
290 case 'hp8':
291 case 'latin1':
292 case 'macroman':
293 $descr = __('West European') . ' (' . __('multilingual') . ')';
294 break;
295 // Central European charsets
296 case 'cp1250':
297 case 'cp852':
298 case 'latin2':
299 case 'macce':
300 $descr = __('Central European') . ' (' . __('multilingual') . ')';
301 break;
302 // Russian charsets
303 case 'cp866':
304 case 'koi8r':
305 $descr = __('Russian');
306 break;
307 // Simplified Chinese charsets
308 case 'gb2312':
309 case 'gbk':
310 $descr = __('Simplified Chinese');
311 break;
312 // Japanese charsets
313 case 'sjis':
314 case 'ujis':
315 case 'cp932':
316 case 'eucjpms':
317 $descr = __('Japanese');
318 break;
319 // Baltic charsets
320 case 'cp1257':
321 case 'latin7':
322 $descr = __('Baltic') . ' (' . __('multilingual') . ')';
323 break;
324 // Other
325 case 'armscii8':
326 case 'armscii':
327 $descr = __('Armenian');
328 break;
329 case 'big5':
330 $descr = __('Traditional Chinese');
331 break;
332 case 'cp1251':
333 $descr = __('Cyrillic') . ' (' . __('multilingual') . ')';
334 break;
335 case 'cp1256':
336 $descr = __('Arabic');
337 break;
338 case 'euckr':
339 $descr = __('Korean');
340 break;
341 case 'hebrew':
342 $descr = __('Hebrew');
343 break;
344 case 'geostd8':
345 $descr = __('Georgian');
346 break;
347 case 'greek':
348 $descr = __('Greek');
349 break;
350 case 'keybcs2':
351 $descr = __('Czech-Slovak');
352 break;
353 case 'koi8u':
354 $descr = __('Ukrainian');
355 break;
356 case 'latin5':
357 $descr = __('Turkish');
358 break;
359 case 'swe7':
360 $descr = __('Swedish');
361 break;
362 case 'tis620':
363 $descr = __('Thai');
364 break;
365 default:
366 $descr = __('unknown');
367 break;
369 if (!empty($is_bin)) {
370 $descr .= ', ' . __('Binary');
372 break;
373 default: $descr = __('unknown');
375 if (!empty($parts[2])) {
376 if ($parts[2] == 'ci') {
377 $descr .= ', ' . __('case-insensitive');
378 } elseif ($parts[2] == 'cs') {
379 $descr .= ', ' . __('case-sensitive');
383 return $descr;