Translation update done using Pootle.
[phpmyadmin/madhuracj.git] / libraries / select_lang.lib.php
blob62b1ea7d83fd63aa0aff20a68193641210fbc184
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 'tr':
305 return array('tr|turkish', 'tr', 'T&uuml;rk&ccedil;e');
306 case 'tt':
307 return array('tt|tatarish', 'tt', 'Tatar&ccedil;a');
308 case 'ug':
309 return array('ug|uyghur', 'ug', 'ئۇيغۇرچە');
310 case 'uk':
311 return array('uk|ukrainian', 'uk', '&#1059;&#1082;&#1088;&#1072;&#1111;&#1085;&#1089;&#1100;&#1082;&#1072;');
312 case 'ur':
313 return array('ur|urdu', 'ur', 'اُردوُ');
314 case 'uz@latin':
315 return array('uz[-_]lat|uzbek-latin', 'uz-lat', 'O&lsquo;zbekcha');
316 case 'uz':
317 return array('uz[-_]cyr|uzbek-cyrillic', 'uz-cyr', '&#1038;&#1079;&#1073;&#1077;&#1082;&#1095;&#1072;');
318 case 'zh_TW':
319 return array('zh[-_](tw|hk)|chinese traditional', 'zh-TW', '&#20013;&#25991;');
320 case 'zh_CN':
321 return array('zh|chinese simplified', 'zh', '&#20013;&#25991;');
323 return array("$lang|$lang", $lang, $lang);
327 * Returns list of languages supported by phpMyAdmin
329 * @return array
331 function PMA_langList()
333 /* We can always speak English */
334 $result = array('en' => PMA_langDetails('en'));
336 /* Check for existing directory */
337 if (!is_dir($GLOBALS['lang_path'])) {
338 return $result;
341 /* Open the directory */
342 $handle = @opendir($GLOBALS['lang_path']);
343 /* This can happen if the kit is English-only */
344 if ($handle === false) {
345 return $result;
348 /* Process all files */
349 while (false !== ($file = readdir($handle))) {
350 if ($file != "." && $file != ".." && file_exists($GLOBALS['lang_path'] . '/' . $file . '/LC_MESSAGES/phpmyadmin.mo')) {
351 $result[$file] = PMA_langDetails($file);
354 /* Close the handle */
355 closedir($handle);
357 return $result;
361 * @global string path to the translations directory; may be absent if the kit is English-only
363 $GLOBALS['lang_path'] = './locale/';
366 * Load gettext functions.
368 require_once './libraries/php-gettext/gettext.inc';
371 * @global string interface language
373 $GLOBALS['lang'] = 'en';
375 * @global boolean whether loading lang from cfg failed
377 $GLOBALS['lang_failed_cfg'] = false;
379 * @global boolean whether loading lang from cookie failed
381 $GLOBALS['lang_failed_cookie'] = false;
383 * @global boolean whether loading lang from user request failed
385 $GLOBALS['lang_failed_request'] = false;
387 * @global string text direction ltr or rtl
389 $GLOBALS['text_dir'] = 'ltr';
392 * @global array supported languages
394 $GLOBALS['available_languages'] = PMA_langList();
396 // Language filtering support
397 if (! empty($GLOBALS['cfg']['FilterLanguages'])) {
398 $new_lang = array();
399 foreach ($GLOBALS['available_languages'] as $key => $val) {
400 if (preg_match('@' . $GLOBALS['cfg']['FilterLanguages'] . '@', $key)) {
401 $new_lang[$key] = $val;
404 if (count($new_lang) > 0) {
405 $GLOBALS['available_languages'] = $new_lang;
407 unset($key, $val, $new_lang);
411 * @global array MySQL charsets map
413 $GLOBALS['mysql_charset_map'] = array(
414 'big5' => 'big5',
415 'cp-866' => 'cp866',
416 'euc-jp' => 'ujis',
417 'euc-kr' => 'euckr',
418 'gb2312' => 'gb2312',
419 'gbk' => 'gbk',
420 'iso-8859-1' => 'latin1',
421 'iso-8859-2' => 'latin2',
422 'iso-8859-7' => 'greek',
423 'iso-8859-8' => 'hebrew',
424 'iso-8859-8-i' => 'hebrew',
425 'iso-8859-9' => 'latin5',
426 'iso-8859-13' => 'latin7',
427 'iso-8859-15' => 'latin1',
428 'koi8-r' => 'koi8r',
429 'shift_jis' => 'sjis',
430 'tis-620' => 'tis620',
431 'utf-8' => 'utf8',
432 'windows-1250' => 'cp1250',
433 'windows-1251' => 'cp1251',
434 'windows-1252' => 'latin1',
435 'windows-1256' => 'cp1256',
436 'windows-1257' => 'cp1257',
440 * Do the work!
443 if (! PMA_langCheck()) {
444 // fallback language
445 $fall_back_lang = 'en';
446 $line = __LINE__;
447 if (! PMA_langSet($fall_back_lang)) {
448 trigger_error('phpMyAdmin-ERROR: invalid lang code: '
449 . __FILE__ . '#' . $line . ', check hard coded fall back language.',
450 E_USER_WARNING);
451 // stop execution
452 // and tell the user that his chosen language is invalid
453 PMA_fatalError('Could not load any language, please check your language settings and folder.');
457 // Set locale
458 _setlocale(LC_MESSAGES, $GLOBALS['lang']);
459 _bindtextdomain('phpmyadmin', $GLOBALS['lang_path']);
460 _bind_textdomain_codeset('phpmyadmin', 'UTF-8');
461 _textdomain('phpmyadmin');
464 * Messages for phpMyAdmin.
466 * These messages are here for easy transition to Gettext.
467 * You should not add any messages here, use instead gettext directly
468 * in your template/PHP file.
471 if (! function_exists('__')) {
472 die('Bad invocation!');
475 /* l10n: Text direction, use either ltr or rtl */
476 $GLOBALS['text_dir'] = __('ltr');
478 /* TCPDF */
479 $GLOBALS['l'] = array();
481 /* TCPDF settings */
482 $GLOBALS['l']['a_meta_charset'] = 'UTF-8';
483 $GLOBALS['l']['a_meta_dir'] = $GLOBALS['text_dir'];
484 $GLOBALS['l']['a_meta_language'] = $GLOBALS['lang'];
486 /* TCPDF translations */
487 $GLOBALS['l']['w_page'] = __('Page number:');
490 // now, that we have loaded the language strings we can send the errors
491 if ($GLOBALS['lang_failed_cfg']) {
492 trigger_error(
493 sprintf(__('Unknown language: %1$s.'),
494 htmlspecialchars($GLOBALS['lang_failed_cfg'])),
495 E_USER_ERROR);
497 if ($GLOBALS['lang_failed_cookie']) {
498 trigger_error(
499 sprintf(__('Unknown language: %1$s.'),
500 htmlspecialchars($GLOBALS['lang_failed_cookie'])),
501 E_USER_ERROR);
503 if ($GLOBALS['lang_failed_request']) {
504 trigger_error(
505 sprintf(__('Unknown language: %1$s.'),
506 htmlspecialchars($GLOBALS['lang_failed_request'])),
507 E_USER_ERROR);
510 unset($line, $fall_back_lang,
511 $GLOBALS['lang_failed_cfg'], $GLOBALS['lang_failed_cookie'], $GLOBALS['lang_failed_request']);