Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / libraries / mysql_charsets.lib.php
blobfc6b18fe879ee0b7f7c23991bfd1b1ebf4d197df
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 /**
14 if (! PMA_cacheExists('mysql_charsets', true)) {
15 $sql = PMA_DRIZZLE
16 ? 'SELECT * FROM data_dictionary.CHARACTER_SETS'
17 : 'SELECT * FROM information_schema.CHARACTER_SETS';
18 $res = PMA_DBI_query($sql);
20 $mysql_charsets = array();
21 while ($row = PMA_DBI_fetch_assoc($res)) {
22 $mysql_charsets[] = $row['CHARACTER_SET_NAME'];
23 // never used
24 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
25 $mysql_charsets_descriptions[$row['CHARACTER_SET_NAME']] = $row['DESCRIPTION'];
27 PMA_DBI_free_result($res);
29 sort($mysql_charsets, SORT_STRING);
31 $mysql_collations = array_flip($mysql_charsets);
32 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
34 $sql = PMA_DRIZZLE
35 ? 'SELECT * FROM data_dictionary.COLLATIONS'
36 : 'SELECT * FROM information_schema.COLLATIONS';
37 $res = PMA_DBI_query($sql);
38 while ($row = PMA_DBI_fetch_assoc($res)) {
39 if (! is_array($mysql_collations[$row['CHARACTER_SET_NAME']])) {
40 $mysql_collations[$row['CHARACTER_SET_NAME']] = array($row['COLLATION_NAME']);
41 } else {
42 $mysql_collations[$row['CHARACTER_SET_NAME']][] = $row['COLLATION_NAME'];
44 $mysql_collations_flat[] = $row['COLLATION_NAME'];
45 if ($row['IS_DEFAULT'] == 'Yes') {
46 $mysql_default_collations[$row['CHARACTER_SET_NAME']] = $row['COLLATION_NAME'];
48 //$mysql_collations_available[$row['Collation']] = ! isset($row['Compiled']) || $row['Compiled'] == 'Yes';
49 $mysql_collations_available[$row['COLLATION_NAME']] = true;
50 $mysql_charsets_available[$row['CHARACTER_SET_NAME']] =
51 !empty($mysql_charsets_available[$row['CHARACTER_SET_NAME']])
52 || !empty($mysql_collations_available[$row['COLLATION_NAME']]);
54 PMA_DBI_free_result($res);
55 unset($res, $row);
57 if (PMA_DRIZZLE && isset($mysql_collations['utf8_general_ci']) && isset($mysql_collations['utf8'])) {
58 $mysql_collations['utf8'] = $mysql_collations['utf8_general_ci'];
59 unset($mysql_collations['utf8_general_ci']);
62 sort($mysql_collations_flat, SORT_STRING);
63 foreach ($mysql_collations AS $key => $value) {
64 sort($mysql_collations[$key], SORT_STRING);
65 reset($mysql_collations[$key]);
67 unset($key, $value);
69 PMA_cacheSet('mysql_charsets', $GLOBALS['mysql_charsets'], true);
70 PMA_cacheSet('mysql_charsets_descriptions', $GLOBALS['mysql_charsets_descriptions'], true);
71 PMA_cacheSet('mysql_charsets_available', $GLOBALS['mysql_charsets_available'], true);
72 PMA_cacheSet('mysql_collations', $GLOBALS['mysql_collations'], true);
73 PMA_cacheSet('mysql_default_collations', $GLOBALS['mysql_default_collations'], true);
74 PMA_cacheSet('mysql_collations_flat', $GLOBALS['mysql_collations_flat'], true);
75 PMA_cacheSet('mysql_collations_available', $GLOBALS['mysql_collations_available'], true);
76 } else {
77 $GLOBALS['mysql_charsets'] = PMA_cacheGet('mysql_charsets', true);
78 $GLOBALS['mysql_charsets_descriptions'] = PMA_cacheGet('mysql_charsets_descriptions', true);
79 $GLOBALS['mysql_charsets_available'] = PMA_cacheGet('mysql_charsets_available', true);
80 $GLOBALS['mysql_collations'] = PMA_cacheGet('mysql_collations', true);
81 $GLOBALS['mysql_default_collations'] = PMA_cacheGet('mysql_default_collations', true);
82 $GLOBALS['mysql_collations_flat'] = PMA_cacheGet('mysql_collations_flat', true);
83 $GLOBALS['mysql_collations_available'] = PMA_cacheGet('mysql_collations_available', true);
86 define('PMA_CSDROPDOWN_COLLATION', 0);
87 define('PMA_CSDROPDOWN_CHARSET', 1);
89 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION,
90 $name = null, $id = null, $default = null, $label = true, $indent = 0,
91 $submitOnChange = false, $displayUnavailable = false)
93 global $mysql_charsets, $mysql_charsets_descriptions,
94 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
96 if (empty($name)) {
97 if ($type == PMA_CSDROPDOWN_COLLATION) {
98 $name = 'collation';
99 } else {
100 $name = 'character_set';
104 $return_str = '<select xml:lang="en" dir="ltr" name="'
105 . htmlspecialchars($name) . '"'
106 . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"')
107 . ($submitOnChange ? ' onchange="this.form.submit();"' : '') . '>' . "\n";
108 if ($label) {
109 $return_str .= '<option value="">'
110 . ($type == PMA_CSDROPDOWN_COLLATION ? __('Collation') : __('Charset'))
111 . '</option>' . "\n";
113 $return_str .= '<option value=""></option>' . "\n";
114 foreach ($mysql_charsets as $current_charset) {
115 if (!$mysql_charsets_available[$current_charset]) {
116 continue;
118 $current_cs_descr =
119 empty($mysql_charsets_descriptions[$current_charset])
120 ? $current_charset
121 : $mysql_charsets_descriptions[$current_charset];
123 if ($type == PMA_CSDROPDOWN_COLLATION) {
124 $return_str .= '<optgroup label="' . $current_charset
125 . '" title="' . $current_cs_descr . '">' . "\n";
126 foreach ($mysql_collations[$current_charset] as $current_collation) {
127 if (!$mysql_collations_available[$current_collation]) {
128 continue;
130 $return_str .= '<option value="' . $current_collation
131 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
132 . ($default == $current_collation ? ' selected="selected"' : '') . '>'
133 . $current_collation . '</option>' . "\n";
135 $return_str .= '</optgroup>' . "\n";
136 } else {
137 $return_str .= '<option value="' . $current_charset
138 . '" title="' . $current_cs_descr . '"'
139 . ($default == $current_charset ? ' selected="selected"' : '') . '>'
140 . $current_charset . '</option>' . "\n";
143 $return_str .= '</select>' . "\n";
145 return $return_str;
148 function PMA_generateCharsetQueryPart($collation) {
149 list($charset) = explode('_', $collation);
150 return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation);
154 * returns collation of given db
156 * @param string $db name of db
157 * @return string collation of $db
159 function PMA_getDbCollation($db) {
160 if ($db == 'information_schema') {
161 // We don't have to check the collation of the virtual
162 // information_schema database: We know it!
163 return 'utf8_general_ci';
166 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
167 // this is slow with thousands of databases
168 return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
169 } else {
170 PMA_DBI_select_db($db);
171 $return = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'collation_database\'', 0, 1);
172 if ($db !== $GLOBALS['db']) {
173 PMA_DBI_select_db($GLOBALS['db']);
175 return $return;
180 * returns default server collation from show variables
182 * @return string $server_collation
184 function PMA_getServerCollation() {
185 return PMA_DBI_fetch_value(
186 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1);
190 * returns description for given collation
193 * @param string $collation MySQL collation string
194 * @return string collation description
196 function PMA_getCollationDescr($collation) {
197 if ($collation == 'binary') {
198 return __('Binary');
200 $parts = explode('_', $collation);
201 if (count($parts) == 1) {
202 $parts[1] = 'general';
203 } elseif ($parts[1] == 'ci' || $parts[1] == 'cs') {
204 $parts[2] = $parts[1];
205 $parts[1] = 'general';
207 $descr = '';
208 switch ($parts[1]) {
209 case 'bulgarian':
210 $descr = __('Bulgarian');
211 break;
212 case 'chinese':
213 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') {
214 $descr = __('Simplified Chinese');
215 } elseif ($parts[0] == 'big5') {
216 $descr = __('Traditional Chinese');
218 break;
219 case 'ci':
220 $descr = __('case-insensitive');
221 break;
222 case 'cs':
223 $descr = __('case-sensitive');
224 break;
225 case 'croatian':
226 $descr = __('Croatian');
227 break;
228 case 'czech':
229 $descr = __('Czech');
230 break;
231 case 'danish':
232 $descr = __('Danish');
233 break;
234 case 'english':
235 $descr = __('English');
236 break;
237 case 'esperanto':
238 $descr = __('Esperanto');
239 break;
240 case 'estonian':
241 $descr = __('Estonian');
242 break;
243 case 'german1':
244 $descr = __('German') . ' (' . __('dictionary') . ')';
245 break;
246 case 'german2':
247 $descr = __('German') . ' (' . __('phone book') . ')';
248 break;
249 case 'hungarian':
250 $descr = __('Hungarian');
251 break;
252 case 'icelandic':
253 $descr = __('Icelandic');
254 break;
255 case 'japanese':
256 $descr = __('Japanese');
257 break;
258 case 'latvian':
259 $descr = __('Latvian');
260 break;
261 case 'lithuanian':
262 $descr = __('Lithuanian');
263 break;
264 case 'korean':
265 $descr = __('Korean');
266 break;
267 case 'persian':
268 $descr = __('Persian');
269 break;
270 case 'polish':
271 $descr = __('Polish');
272 break;
273 case 'roman':
274 $descr = __('West European');
275 break;
276 case 'romanian':
277 $descr = __('Romanian');
278 break;
279 case 'slovak':
280 $descr = __('Slovak');
281 break;
282 case 'slovenian':
283 $descr = __('Slovenian');
284 break;
285 case 'spanish':
286 $descr = __('Spanish');
287 break;
288 case 'spanish2':
289 $descr = __('Traditional Spanish');
290 break;
291 case 'swedish':
292 $descr = __('Swedish');
293 break;
294 case 'thai':
295 $descr = __('Thai');
296 break;
297 case 'turkish':
298 $descr = __('Turkish');
299 break;
300 case 'ukrainian':
301 $descr = __('Ukrainian');
302 break;
303 case 'unicode':
304 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
305 break;
306 case 'bin':
307 $is_bin = true;
308 case 'general':
309 switch ($parts[0]) {
310 // Unicode charsets
311 case 'ucs2':
312 case 'utf8':
313 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
314 break;
315 // West European charsets
316 case 'ascii':
317 case 'cp850':
318 case 'dec8':
319 case 'hp8':
320 case 'latin1':
321 case 'macroman':
322 $descr = __('West European') . ' (' . __('multilingual') . ')';
323 break;
324 // Central European charsets
325 case 'cp1250':
326 case 'cp852':
327 case 'latin2':
328 case 'macce':
329 $descr = __('Central European') . ' (' . __('multilingual') . ')';
330 break;
331 // Russian charsets
332 case 'cp866':
333 case 'koi8r':
334 $descr = __('Russian');
335 break;
336 // Simplified Chinese charsets
337 case 'gb2312':
338 case 'gbk':
339 $descr = __('Simplified Chinese');
340 break;
341 // Japanese charsets
342 case 'sjis':
343 case 'ujis':
344 case 'cp932':
345 case 'eucjpms':
346 $descr = __('Japanese');
347 break;
348 // Baltic charsets
349 case 'cp1257':
350 case 'latin7':
351 $descr = __('Baltic') . ' (' . __('multilingual') . ')';
352 break;
353 // Other
354 case 'armscii8':
355 case 'armscii':
356 $descr = __('Armenian');
357 break;
358 case 'big5':
359 $descr = __('Traditional Chinese');
360 break;
361 case 'cp1251':
362 $descr = __('Cyrillic') . ' (' . __('multilingual') . ')';
363 break;
364 case 'cp1256':
365 $descr = __('Arabic');
366 break;
367 case 'euckr':
368 $descr = __('Korean');
369 break;
370 case 'hebrew':
371 $descr = __('Hebrew');
372 break;
373 case 'geostd8':
374 $descr = __('Georgian');
375 break;
376 case 'greek':
377 $descr = __('Greek');
378 break;
379 case 'keybcs2':
380 $descr = __('Czech-Slovak');
381 break;
382 case 'koi8u':
383 $descr = __('Ukrainian');
384 break;
385 case 'latin5':
386 $descr = __('Turkish');
387 break;
388 case 'swe7':
389 $descr = __('Swedish');
390 break;
391 case 'tis620':
392 $descr = __('Thai');
393 break;
394 default:
395 $descr = __('unknown');
396 break;
398 if (!empty($is_bin)) {
399 $descr .= ', ' . __('Binary');
401 break;
402 default: $descr = __('unknown');
404 if (!empty($parts[2])) {
405 if ($parts[2] == 'ci') {
406 $descr .= ', ' . __('case-insensitive');
407 } elseif ($parts[2] == 'cs') {
408 $descr .= ', ' . __('case-sensitive');
412 return $descr;