Translation update done using Pootle.
[phpmyadmin/crack.git] / libraries / mysql_charsets.lib.php
blob303c63770965c3512e4e79d187af5e673d4d6388
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 /**
15 if (! PMA_cacheExists('mysql_charsets_count', true)) {
16 $res = PMA_DBI_query('SHOW CHARACTER SET;');
18 $mysql_charsets = array();
19 while ($row = PMA_DBI_fetch_assoc($res)) {
20 $mysql_charsets[] = $row['Charset'];
21 // never used
22 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
23 $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
25 PMA_DBI_free_result($res);
27 $mysql_charsets_count = count($mysql_charsets);
28 sort($mysql_charsets, SORT_STRING);
30 $mysql_collations = array_flip($mysql_charsets);
31 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
33 $res = PMA_DBI_query('SHOW COLLATION;');
34 while ($row = PMA_DBI_fetch_assoc($res)) {
35 if (!is_array($mysql_collations[$row['Charset']])) {
36 $mysql_collations[$row['Charset']] = array($row['Collation']);
37 } else {
38 $mysql_collations[$row['Charset']][] = $row['Collation'];
40 $mysql_collations_flat[] = $row['Collation'];
41 if ((isset($row['D']) && $row['D'] == 'Y') || (isset($row['Default']) && $row['Default'] == 'Yes')) {
42 $mysql_default_collations[$row['Charset']] = $row['Collation'];
44 //$mysql_collations_available[$row['Collation']] = !isset($row['Compiled']) || $row['Compiled'] == 'Yes';
45 $mysql_collations_available[$row['Collation']] = TRUE;
46 $mysql_charsets_available[$row['Charset']] =
47 !empty($mysql_charsets_available[$row['Charset']])
48 || !empty($mysql_collations_available[$row['Collation']]);
50 PMA_DBI_free_result($res);
51 unset($res, $row);
53 $mysql_collations_count = count($mysql_collations_flat);
54 sort($mysql_collations_flat, SORT_STRING);
55 foreach ($mysql_collations AS $key => $value) {
56 sort($mysql_collations[$key], SORT_STRING);
57 reset($mysql_collations[$key]);
59 unset($key, $value);
61 PMA_cacheSet('mysql_charsets', $GLOBALS['mysql_charsets'], true);
62 PMA_cacheSet('mysql_charsets_descriptions', $GLOBALS['mysql_charsets_descriptions'], true);
63 PMA_cacheSet('mysql_charsets_count', $GLOBALS['mysql_charsets_count'], true);
64 PMA_cacheSet('mysql_charsets_available', $GLOBALS['mysql_charsets_available'], true);
65 PMA_cacheSet('mysql_collations', $GLOBALS['mysql_collations'], true);
66 PMA_cacheSet('mysql_default_collations', $GLOBALS['mysql_default_collations'], true);
67 PMA_cacheSet('mysql_collations_flat', $GLOBALS['mysql_collations_flat'], true);
68 PMA_cacheSet('mysql_collations_count', $GLOBALS['mysql_collations_count'], true);
69 PMA_cacheSet('mysql_collations_available', $GLOBALS['mysql_collations_available'], true);
70 } else {
71 $GLOBALS['mysql_charsets'] = PMA_cacheGet('mysql_charsets', true);
72 $GLOBALS['mysql_charsets_descriptions'] = PMA_cacheGet('mysql_charsets_descriptions', true);
73 $GLOBALS['mysql_charsets_count'] = PMA_cacheGet('mysql_charsets_count', true);
74 $GLOBALS['mysql_charsets_available'] = PMA_cacheGet('mysql_charsets_available', true);
75 $GLOBALS['mysql_collations'] = PMA_cacheGet('mysql_collations', true);
76 $GLOBALS['mysql_default_collations'] = PMA_cacheGet('mysql_default_collations', true);
77 $GLOBALS['mysql_collations_flat'] = PMA_cacheGet('mysql_collations_flat', true);
78 $GLOBALS['mysql_collations_count'] = PMA_cacheGet('mysql_collations_count', true);
79 $GLOBALS['mysql_collations_available'] = PMA_cacheGet('mysql_collations_available', true);
82 define('PMA_CSDROPDOWN_COLLATION', 0);
83 define('PMA_CSDROPDOWN_CHARSET', 1);
85 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION,
86 $name = null, $id = null, $default = null, $label = TRUE, $indent = 0,
87 $submitOnChange = FALSE, $displayUnavailable = FALSE)
89 global $mysql_charsets, $mysql_charsets_descriptions,
90 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
92 if (empty($name)) {
93 if ($type == PMA_CSDROPDOWN_COLLATION) {
94 $name = 'collation';
95 } else {
96 $name = 'character_set';
100 $return_str = '<select xml:lang="en" dir="ltr" name="'
101 . htmlspecialchars($name) . '"'
102 . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"')
103 . ($submitOnChange ? ' onchange="this.form.submit();"' : '') . '>' . "\n";
104 if ($label) {
105 $return_str .= '<option value="">'
106 . ($type == PMA_CSDROPDOWN_COLLATION ? __('Collation') : __('Charset'))
107 . '</option>' . "\n";
109 $return_str .= '<option value=""></option>' . "\n";
110 foreach ($mysql_charsets as $current_charset) {
111 if (!$mysql_charsets_available[$current_charset]) {
112 continue;
114 $current_cs_descr =
115 empty($mysql_charsets_descriptions[$current_charset])
116 ? $current_charset
117 : $mysql_charsets_descriptions[$current_charset];
119 if ($type == PMA_CSDROPDOWN_COLLATION) {
120 $return_str .= '<optgroup label="' . $current_charset
121 . '" title="' . $current_cs_descr . '">' . "\n";
122 foreach ($mysql_collations[$current_charset] as $current_collation) {
123 if (!$mysql_collations_available[$current_collation]) {
124 continue;
126 $return_str .= '<option value="' . $current_collation
127 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
128 . ($default == $current_collation ? ' selected="selected"' : '') . '>'
129 . $current_collation . '</option>' . "\n";
131 $return_str .= '</optgroup>' . "\n";
132 } else {
133 $return_str .= '<option value="' . $current_charset
134 . '" title="' . $current_cs_descr . '"'
135 . ($default == $current_charset ? ' selected="selected"' : '') . '>'
136 . $current_charset . '</option>' . "\n";
139 $return_str .= '</select>' . "\n";
141 return $return_str;
144 function PMA_generateCharsetQueryPart($collation) {
145 list($charset) = explode('_', $collation);
146 return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation);
150 * returns collation of given db
152 * @uses PMA_DBI_fetch_value()
153 * @uses PMA_DBI_select_db()
154 * @uses PMA_sqlAddSlashes()
155 * @uses $GLOBALS['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 * @uses PMA_DBI_fetch_value()
183 * @return string $server_collation
185 function PMA_getServerCollation() {
186 return PMA_DBI_fetch_value(
187 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1);
191 * returns description for given collation
193 * @uses is_array()
194 * @uses explode()
195 * @uses count()
197 * @param string $collation MySQL collation string
198 * @return string collation description
200 function PMA_getCollationDescr($collation) {
201 static $collation_cache;
203 if (!is_array($collation_cache)) {
204 $collation_cache = array();
205 } elseif (isset($collation_cache[$collation])) {
206 return $collation_cache[$collation];
209 if ($collation == 'binary') {
210 return __('Binary');
212 $parts = explode('_', $collation);
213 if (count($parts) == 1) {
214 $parts[1] = 'general';
215 } elseif ($parts[1] == 'ci' || $parts[1] == 'cs') {
216 $parts[2] = $parts[1];
217 $parts[1] = 'general';
219 $descr = '';
220 switch ($parts[1]) {
221 case 'bulgarian':
222 $descr = __('Bulgarian');
223 break;
224 case 'chinese':
225 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') {
226 $descr = __('Simplified Chinese');
227 } elseif ($parts[0] == 'big5') {
228 $descr = __('Traditional Chinese');
230 break;
231 case 'ci':
232 $descr = __('case-insensitive');
233 break;
234 case 'cs':
235 $descr = __('case-sensitive');
236 break;
237 case 'croatian':
238 $descr = __('Croatian');
239 break;
240 case 'czech':
241 $descr = __('Czech');
242 break;
243 case 'danish':
244 $descr = __('Danish');
245 break;
246 case 'english':
247 $descr = __('English');
248 break;
249 case 'esperanto':
250 $descr = __('Esperanto');
251 break;
252 case 'estonian':
253 $descr = __('Estonian');
254 break;
255 case 'german1':
256 $descr = __('German') . ' (' . __('dictionary') . ')';
257 break;
258 case 'german2':
259 $descr = __('German') . ' (' . __('phone book') . ')';
260 break;
261 case 'hungarian':
262 $descr = __('Hungarian');
263 break;
264 case 'icelandic':
265 $descr = __('Icelandic');
266 break;
267 case 'japanese':
268 $descr = __('Japanese');
269 break;
270 case 'latvian':
271 $descr = __('Latvian');
272 break;
273 case 'lithuanian':
274 $descr = __('Lithuanian');
275 break;
276 case 'korean':
277 $descr = __('Korean');
278 break;
279 case 'persian':
280 $descr = __('Persian');
281 break;
282 case 'polish':
283 $descr = __('Polish');
284 break;
285 case 'roman':
286 $descr = __('West European');
287 break;
288 case 'romanian':
289 $descr = __('Romanian');
290 break;
291 case 'slovak':
292 $descr = __('Slovak');
293 break;
294 case 'slovenian':
295 $descr = __('Slovenian');
296 break;
297 case 'spanish':
298 $descr = __('Spanish');
299 break;
300 case 'spanish2':
301 $descr = __('Traditional Spanish');
302 break;
303 case 'swedish':
304 $descr = __('Swedish');
305 break;
306 case 'thai':
307 $descr = __('Thai');
308 break;
309 case 'turkish':
310 $descr = __('Turkish');
311 break;
312 case 'ukrainian':
313 $descr = __('Ukrainian');
314 break;
315 case 'unicode':
316 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
317 break;
318 case 'bin':
319 $is_bin = TRUE;
320 case 'general':
321 switch ($parts[0]) {
322 // Unicode charsets
323 case 'ucs2':
324 case 'utf8':
325 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
326 break;
327 // West European charsets
328 case 'ascii':
329 case 'cp850':
330 case 'dec8':
331 case 'hp8':
332 case 'latin1':
333 case 'macroman':
334 $descr = __('West European') . ' (' . __('multilingual') . ')';
335 break;
336 // Central European charsets
337 case 'cp1250':
338 case 'cp852':
339 case 'latin2':
340 case 'macce':
341 $descr = __('Central European') . ' (' . __('multilingual') . ')';
342 break;
343 // Russian charsets
344 case 'cp866':
345 case 'koi8r':
346 $descr = __('Russian');
347 break;
348 // Simplified Chinese charsets
349 case 'gb2312':
350 case 'gbk':
351 $descr = __('Simplified Chinese');
352 break;
353 // Japanese charsets
354 case 'sjis':
355 case 'ujis':
356 case 'cp932':
357 case 'eucjpms':
358 $descr = __('Japanese');
359 break;
360 // Baltic charsets
361 case 'cp1257':
362 case 'latin7':
363 $descr = __('Baltic') . ' (' . __('multilingual') . ')';
364 break;
365 // Other
366 case 'armscii8':
367 case 'armscii':
368 $descr = __('Armenian');
369 break;
370 case 'big5':
371 $descr = __('Traditional Chinese');
372 break;
373 case 'cp1251':
374 $descr = __('Cyrillic') . ' (' . __('multilingual') . ')';
375 break;
376 case 'cp1256':
377 $descr = __('Arabic');
378 break;
379 case 'euckr':
380 $descr = __('Korean');
381 break;
382 case 'hebrew':
383 $descr = __('Hebrew');
384 break;
385 case 'geostd8':
386 $descr = __('Georgian');
387 break;
388 case 'greek':
389 $descr = __('Greek');
390 break;
391 case 'keybcs2':
392 $descr = __('Czech-Slovak');
393 break;
394 case 'koi8u':
395 $descr = __('Ukrainian');
396 break;
397 case 'latin5':
398 $descr = __('Turkish');
399 break;
400 case 'swe7':
401 $descr = __('Swedish');
402 break;
403 case 'tis620':
404 $descr = __('Thai');
405 break;
406 default:
407 $descr = __('unknown');
408 break;
410 if (!empty($is_bin)) {
411 $descr .= ', ' . __('Binary');
413 break;
414 default: $descr = __('unknown');
416 if (!empty($parts[2])) {
417 if ($parts[2] == 'ci') {
418 $descr .= ', ' . __('case-insensitive');
419 } elseif ($parts[2] == 'cs') {
420 $descr .= ', ' . __('case-sensitive');
424 $collation_cache[$collation] = $descr;
425 return $descr;