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