Translation update done using Pootle.
[phpmyadmin/last10db.git] / libraries / select_lang.lib.php
blobf1a3725aa08671601ef1633f87f0932763e513bc
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * phpMyAdmin Language Loading File
6 * @package phpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Returns language name
15 function PMA_langName($tmplang) {
16 $lang_name = ucfirst(substr(strrchr($tmplang[0], '|'), 1));
18 // Include native name if non empty
19 if (!empty($tmplang[2])) {
20 $lang_name = $tmplang[2] . ' - ' . $lang_name;
23 return $lang_name;
26 /**
27 * tries to find the language to use
29 * @uses $GLOBALS['cfg']['lang']
30 * @uses $GLOBALS['cfg']['DefaultLang']
31 * @uses $GLOBALS['lang_failed_cfg']
32 * @uses $GLOBALS['lang_failed_cookie']
33 * @uses $GLOBALS['lang_failed_request']
34 * @uses $_REQUEST['lang']
35 * @uses $_COOKIE['pma_lang']
36 * @uses $_SERVER['HTTP_ACCEPT_LANGUAGE']
37 * @uses $_SERVER['HTTP_USER_AGENT']
38 * @uses PMA_langSet()
39 * @uses PMA_langDetect()
40 * @uses explode()
41 * @return bool success if valid lang is found, otherwise false
43 function PMA_langCheck()
45 // check forced language
46 if (! empty($GLOBALS['cfg']['Lang'])) {
47 if (PMA_langSet($GLOBALS['cfg']['Lang'])) {
48 return true;
49 } else {
50 $GLOBALS['lang_failed_cfg'] = $GLOBALS['cfg']['Lang'];
54 // Don't use REQUEST in following code as it might be confused by cookies with same name
55 // check user requested language (POST)
56 if (! empty($_POST['lang'])) {
57 if (PMA_langSet($_POST['lang'])) {
58 return true;
59 } elseif (!is_string($_POST['lang'])) {
60 /* Faked request, don't care on localisation */
61 $GLOBALS['lang_failed_request'] = 'Yes';
62 } else {
63 $GLOBALS['lang_failed_request'] = $_POST['lang'];
67 // check user requested language (GET)
68 if (! empty($_GET['lang'])) {
69 if (PMA_langSet($_GET['lang'])) {
70 return true;
71 } elseif (!is_string($_GET['lang'])) {
72 /* Faked request, don't care on localisation */
73 $GLOBALS['lang_failed_request'] = 'Yes';
74 } else {
75 $GLOBALS['lang_failed_request'] = $_GET['lang'];
79 // check previous set language
80 if (! empty($_COOKIE['pma_lang'])) {
81 if (PMA_langSet($_COOKIE['pma_lang'])) {
82 return true;
83 } elseif (!is_string($_COOKIE['pma_lang'])) {
84 /* Faked request, don't care on localisation */
85 $GLOBALS['lang_failed_cookie'] = 'Yes';
86 } else {
87 $GLOBALS['lang_failed_cookie'] = $_COOKIE['pma_lang'];
91 // try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE variable
92 if (PMA_getenv('HTTP_ACCEPT_LANGUAGE')) {
93 foreach (explode(',', PMA_getenv('HTTP_ACCEPT_LANGUAGE')) as $lang) {
94 if (PMA_langDetect($lang, 1)) {
95 return true;
100 // try to findout user's language by checking its HTTP_USER_AGENT variable
101 if (PMA_langDetect(PMA_getenv('HTTP_USER_AGENT'), 2)) {
102 return true;
105 // Didn't catch any valid lang : we use the default settings
106 if (PMA_langSet($GLOBALS['cfg']['DefaultLang'])) {
107 return true;
110 return false;
114 * checks given lang and sets it if valid
115 * returns true on success, otherwise flase
117 * @uses $GLOBALS['available_languages'] to check $lang
118 * @uses $GLOBALS['lang'] to set it
119 * @param string $lang language to set
120 * @return bool success
122 function PMA_langSet(&$lang)
124 /* Partial backward compatibility with 3.3 and older branches */
125 $lang = str_replace('-utf-8', '', $lang);
127 if (!is_string($lang) || empty($lang) || empty($GLOBALS['available_languages'][$lang])) {
128 return false;
130 $GLOBALS['lang'] = $lang;
131 return true;
135 * Analyzes some PHP environment variables to find the most probable language
136 * that should be used
138 * @param string string to analyze
139 * @param integer type of the PHP environment variable which value is $str
141 * @return bool true on success, otherwise false
143 * @uses $GLOBALS['available_languages'] to check $lang
145 * @access private
147 function PMA_langDetect($str, $envType)
149 if (empty($str)) {
150 return false;
152 if (empty($GLOBALS['available_languages'])) {
153 return false;
156 foreach ($GLOBALS['available_languages'] as $lang => $value) {
157 // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
158 // 2 for the 'HTTP_USER_AGENT' one
159 $expr = $value[0];
160 if (strpos($expr, '[-_]') === FALSE) {
161 $expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr);
163 if (($envType == 1 && preg_match('/^(' . addcslashes($expr,'/') . ')(;q=[0-9]\\.[0-9])?$/i', $str))
164 || ($envType == 2 && preg_match('/(\(|\[|;[[:space:]])(' . addcslashes($expr,'/') . ')(;|\]|\))/i', $str))) {
165 if (PMA_langSet($lang)) {
166 return true;
171 return false;
172 } // end of the 'PMA_langDetect()' function
176 * All the supported languages have to be listed in the array below.
177 * 1. The key must be the "official" ISO 639 language code and, if required,
178 * the dialect code. It can also contain some information about the
179 * charset (see the Russian case).
180 * 2. The first of the values associated to the key is used in a regular
181 * expression to find some keywords corresponding to the language inside two
182 * environment variables.
183 * These values contain:
184 * - the "official" ISO language code and, if required, the dialect code
185 * too ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
186 * dialects, 'zh[-_]tw' for Chinese traditional...), the dialect has to
187 * be specified first;
188 * - the '|' character (it means 'OR');
189 * - the full language name.
190 * 3. The second value associated to the key is the language code as defined by
191 * the RFC1766.
192 * 4. The third value is its native name in html entities or UTF-8.
194 * Beware that the sorting order (first values associated to keys by
195 * alphabetical reverse order in the array) is important: 'zh-tw' (chinese
196 * traditional) must be detected before 'zh' (chinese simplified) for
197 * example.
200 function PMA_langDetails($lang) {
201 switch ($lang) {
202 case 'en':
203 return array('en|english', 'en', '');
204 case 'af':
205 return array('af|afrikaans', 'af', '');
206 case 'ar':
207 return array('ar|arabic', 'ar', '&#1575;&#1604;&#1593;&#1585;&#1576;&#1610;&#1577;');
208 case 'az':
209 return array('az|azerbaijani', 'az', 'Az&#601;rbaycanca');
210 case 'bn':
211 return array('bn|bangla', 'bn', '');
212 case 'be':
213 return array('be|belarusian', 'be', '&#1041;&#1077;&#1083;&#1072;&#1088;&#1091;&#1089;&#1082;&#1072;&#1103;');
214 case 'be@latin':
215 return array('be[-_]lat|belarusian latin', 'be-lat', 'Bie&#0322;aruskaja');
216 case 'bg':
217 return array('bg|bulgarian', 'bg', '&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;');
218 case 'bs':
219 return array('bs|bosnian', 'bs', 'Bosanski');
220 case 'ca':
221 return array('ca|catalan', 'ca', 'Catal&agrave;');
222 case 'cs':
223 return array('cs|czech', 'cs', '&#268;esky');
224 case 'cy':
225 return array('cy|welsh', 'cy', 'Cymraeg');
226 case 'da':
227 return array('da|danish', 'da', 'Dansk');
228 case 'de':
229 return array('de|german', 'de', 'Deutsch');
230 case 'el':
231 return array('el|greek', 'el', '&Epsilon;&lambda;&lambda;&eta;&nu;&iota;&kappa;&#940;');
232 case 'en':
233 return array('en|english', 'en', '');
234 case 'en_GB':
235 return array('en[_-]gb|english (United Kingdom)', 'en-gb', '');
236 case 'es':
237 return array('es|spanish', 'es', 'Espa&ntilde;ol');
238 case 'et':
239 return array('et|estonian', 'et', 'Eesti');
240 case 'eu':
241 return array('eu|basque', 'eu', 'Euskara');
242 case 'fa':
243 return array('fa|persian', 'fa', '&#1601;&#1575;&#1585;&#1587;&#1740;');
244 case 'fi':
245 return array('fi|finnish', 'fi', 'Suomi');
246 case 'fr':
247 return array('fr|french', 'fr', 'Fran&ccedil;ais');
248 case 'gl':
249 return array('gl|galician', 'gl', 'Galego');
250 case 'he':
251 return array('he|hebrew', 'he', '&#1506;&#1489;&#1512;&#1497;&#1514;');
252 case 'hi':
253 return array('hi|hindi', 'hi', '&#2361;&#2367;&#2344;&#2381;&#2342;&#2368;');
254 case 'hr':
255 return array('hr|croatian', 'hr', 'Hrvatski');
256 case 'hu':
257 return array('hu|hungarian', 'hu', 'Magyar');
258 case 'id':
259 return array('id|indonesian', 'id', 'Bahasa Indonesia');
260 case 'it':
261 return array('it|italian', 'it', 'Italiano');
262 case 'ja':
263 return array('ja|japanese', 'ja', '&#26085;&#26412;&#35486;');
264 case 'ko':
265 return array('ko|korean', 'ko', '&#54620;&#44397;&#50612;');
266 case 'ka':
267 return array('ka|georgian', 'ka', '&#4325;&#4304;&#4320;&#4311;&#4323;&#4314;&#4312;');
268 case 'lt':
269 return array('lt|lithuanian', 'lt', 'Lietuvi&#371;');
270 case 'lv':
271 return array('lv|latvian', 'lv', 'Latvie&scaron;u');
272 case 'mk':
273 return array('mk|macedonian', 'mk', 'Macedonian');
274 case 'mn':
275 return array('mn|mongolian', 'mn', '&#1052;&#1086;&#1085;&#1075;&#1086;&#1083;');
276 case 'ms':
277 return array('ms|malay', 'ms', 'Bahasa Melayu');
278 case 'nl':
279 return array('nl|dutch', 'nl', 'Nederlands');
280 case 'nb':
281 return array('nb|norwegian', 'nb', 'Norsk');
282 case 'pl':
283 return array('pl|polish', 'pl', 'Polski');
284 case 'pt_BR':
285 return array('pt[-_]br|brazilian portuguese', 'pt-BR', 'Portugu&ecirc;s');
286 case 'pt':
287 return array('pt|portuguese', 'pt', 'Portugu&ecirc;s');
288 case 'ro':
289 return array('ro|romanian', 'ro', 'Rom&acirc;n&#259;');
290 case 'ru':
291 return array('ru|russian', 'ru', '&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;');
292 case 'si':
293 return array('si|sinhala', 'si', '&#3523;&#3538;&#3458;&#3524;&#3517;');
294 case 'sk':
295 return array('sk|slovak', 'sk', 'Sloven&#269;ina');
296 case 'sl':
297 return array('sl|slovenian', 'sl', 'Sloven&scaron;&#269;ina');
298 case 'sq':
299 return array('sq|albanian', 'sq', 'Shqip');
300 case 'sr@latin':
301 return array('sr[-_]lat|serbian latin', 'sr-lat', 'Srpski');
302 case 'sr':
303 return array('sr|serbian', 'sr', '&#1057;&#1088;&#1087;&#1089;&#1082;&#1080;');
304 case 'sv':
305 return array('sv|swedish', 'sv', 'Svenska');
306 case 'ta':
307 return array('ta|tamil', 'ta', 'தமிழ்');
308 case 'te':
309 return array('te|telugu', 'te', 'తెలుగు');
310 case 'th':
311 return array('th|thai', 'th', '&#3616;&#3634;&#3625;&#3634;&#3652;&#3607;&#3618;');
312 case 'tr':
313 return array('tr|turkish', 'tr', 'T&uuml;rk&ccedil;e');
314 case 'tt':
315 return array('tt|tatarish', 'tt', 'Tatar&ccedil;a');
316 case 'ug':
317 return array('ug|uyghur', 'ug', 'ئۇيغۇرچە');
318 case 'uk':
319 return array('uk|ukrainian', 'uk', '&#1059;&#1082;&#1088;&#1072;&#1111;&#1085;&#1089;&#1100;&#1082;&#1072;');
320 case 'ur':
321 return array('ur|urdu', 'ur', 'اُردوُ');
322 case 'uz@latin':
323 return array('uz[-_]lat|uzbek-latin', 'uz-lat', 'O&lsquo;zbekcha');
324 case 'uz':
325 return array('uz[-_]cyr|uzbek-cyrillic', 'uz-cyr', '&#1038;&#1079;&#1073;&#1077;&#1082;&#1095;&#1072;');
326 case 'zh_TW':
327 return array('zh[-_](tw|hk)|chinese traditional', 'zh-TW', '&#20013;&#25991;');
328 case 'zh_CN':
329 return array('zh|chinese simplified', 'zh', '&#20013;&#25991;');
331 return array("$lang|$lang", $lang, $lang);
335 * Returns list of languages supported by phpMyAdmin
337 * @return array
339 function PMA_langList()
341 /* We can always speak English */
342 $result = array('en' => PMA_langDetails('en'));
344 /* Open the directory */
345 $handle = @opendir($GLOBALS['lang_path']);
346 if ($handle === FALSE) {
347 trigger_error('phpMyAdmin: path not found: '
348 . $GLOBALS['lang_path'] . ', check your language directory.',
349 E_USER_WARNING);
350 return $result;
353 /* Process all files */
354 while (FALSE !== ($file = readdir($handle))) {
355 if ($file != "." && $file != ".." && file_exists($GLOBALS['lang_path'] . '/' . $file . '/LC_MESSAGES/phpmyadmin.mo')) {
356 $result[$file] = PMA_langDetails($file);
359 /* Close the handle */
360 closedir($handle);
362 return $result;
366 * @global string path to the translations directory
368 $GLOBALS['lang_path'] = './locale/';
371 * Load gettext functions.
373 require './libraries/php-gettext/gettext.inc';
376 * @global string interface language
378 $GLOBALS['lang'] = 'en';
380 * @global boolean whether loading lang from cfg failed
382 $GLOBALS['lang_failed_cfg'] = false;
384 * @global boolean whether loading lang from cookie failed
386 $GLOBALS['lang_failed_cookie'] = false;
388 * @global boolean whether loading lang from user request failed
390 $GLOBALS['lang_failed_request'] = false;
392 * @global string text direction ltr or rtl
394 $GLOBALS['text_dir'] = 'ltr';
397 * @global array supported languages
399 $GLOBALS['available_languages'] = PMA_langList();
401 // Language filtering support
402 if (! empty($GLOBALS['cfg']['FilterLanguages'])) {
403 $new_lang = array();
404 foreach ($GLOBALS['available_languages'] as $key => $val) {
405 if (preg_match('@' . $GLOBALS['cfg']['FilterLanguages'] . '@', $key)) {
406 $new_lang[$key] = $val;
409 if (count($new_lang) > 0) {
410 $GLOBALS['available_languages'] = $new_lang;
412 unset($key, $val, $new_lang);
416 * @global array MySQL charsets map
418 $GLOBALS['mysql_charset_map'] = array(
419 'big5' => 'big5',
420 'cp-866' => 'cp866',
421 'euc-jp' => 'ujis',
422 'euc-kr' => 'euckr',
423 'gb2312' => 'gb2312',
424 'gbk' => 'gbk',
425 'iso-8859-1' => 'latin1',
426 'iso-8859-2' => 'latin2',
427 'iso-8859-7' => 'greek',
428 'iso-8859-8' => 'hebrew',
429 'iso-8859-8-i' => 'hebrew',
430 'iso-8859-9' => 'latin5',
431 'iso-8859-13' => 'latin7',
432 'iso-8859-15' => 'latin1',
433 'koi8-r' => 'koi8r',
434 'shift_jis' => 'sjis',
435 'tis-620' => 'tis620',
436 'utf-8' => 'utf8',
437 'windows-1250' => 'cp1250',
438 'windows-1251' => 'cp1251',
439 'windows-1252' => 'latin1',
440 'windows-1256' => 'cp1256',
441 'windows-1257' => 'cp1257',
445 * Do the work!
448 if (! PMA_langCheck()) {
449 // fallback language
450 $fall_back_lang = 'en';
451 $line = __LINE__;
452 if (! PMA_langSet($fall_back_lang)) {
453 trigger_error('phpMyAdmin-ERROR: invalid lang code: '
454 . __FILE__ . '#' . $line . ', check hard coded fall back language.',
455 E_USER_WARNING);
456 // stop execution
457 // and tell the user that his choosen language is invalid
458 PMA_fatalError('Could not load any language, please check your language settings and folder.');
462 // Set locale
463 _setlocale(LC_MESSAGES, $GLOBALS['lang']);
464 _bindtextdomain('phpmyadmin', $GLOBALS['lang_path']);
465 _bind_textdomain_codeset('phpmyadmin', 'UTF-8');
466 _textdomain('phpmyadmin');
469 * Messages for phpMyAdmin.
471 * These messages are here for easy transition to Gettext.
472 * You should not add any messages here, use instead gettext directly
473 * in your template/PHP file.
476 if (! function_exists('__')) {
477 die('Bad invocation!');
480 /* We use only utf-8 */
481 $charset = 'utf-8';
483 /* l10n: Text direction, use either ltr or rtl */
484 $text_dir = __('ltr');
486 // now, that we have loaded the language strings we can send the errors
487 if ($GLOBALS['lang_failed_cfg']) {
488 trigger_error(
489 sprintf(__('Unknown language: %1$s.'),
490 htmlspecialchars($GLOBALS['lang_failed_cfg'])),
491 E_USER_ERROR);
493 if ($GLOBALS['lang_failed_cookie']) {
494 trigger_error(
495 sprintf(__('Unknown language: %1$s.'),
496 htmlspecialchars($GLOBALS['lang_failed_cookie'])),
497 E_USER_ERROR);
499 if ($GLOBALS['lang_failed_request']) {
500 trigger_error(
501 sprintf(__('Unknown language: %1$s.'),
502 htmlspecialchars($GLOBALS['lang_failed_request'])),
503 E_USER_ERROR);
506 unset($line, $fall_back_lang,
507 $GLOBALS['lang_failed_cfg'], $GLOBALS['lang_failed_cookie'], $GLOBALS['ang_failed_request']);