2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * phpMyAdmin Language Loading File
8 if (! defined('PHPMYADMIN')) {
13 * Returns language name
15 * @param string $tmplang
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;
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'])) {
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'])) {
51 } elseif (!is_string($_POST['lang'])) {
52 /* Faked request, don't care on localisation */
53 $GLOBALS['lang_failed_request'] = 'Yes';
55 $GLOBALS['lang_failed_request'] = $_POST['lang'];
59 // check user requested language (GET)
60 if (! empty($_GET['lang'])) {
61 if (PMA_langSet($_GET['lang'])) {
63 } elseif (!is_string($_GET['lang'])) {
64 /* Faked request, don't care on localisation */
65 $GLOBALS['lang_failed_request'] = 'Yes';
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'])) {
75 } elseif (!is_string($_COOKIE['pma_lang'])) {
76 /* Faked request, don't care on localisation */
77 $GLOBALS['lang_failed_cookie'] = 'Yes';
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)) {
92 // try to findout user's language by checking its HTTP_USER_AGENT variable
93 if (PMA_langDetect(PMA_getenv('HTTP_USER_AGENT'), 2)) {
97 // Didn't catch any valid lang : we use the default settings
98 if (PMA_langSet($GLOBALS['cfg']['DefaultLang'])) {
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])) {
120 $GLOBALS['lang'] = $lang;
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
136 function PMA_langDetect($str, $envType)
141 if (empty($GLOBALS['available_languages'])) {
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
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)) {
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
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
188 * @param string $lang
191 function PMA_langDetails($lang)
195 return array('af|afrikaans', 'af', '');
197 return array('ar|arabic', 'ar', 'العربية');
199 return array('az|azerbaijani', 'az', 'Azərbaycanca');
201 return array('bn|bangla', 'bn', 'বাংলা');
203 return array('be|belarusian', 'be', 'Беларуская');
205 return array('be[-_]lat|belarusian latin', 'be-lat', 'Biełaruskaja');
207 return array('bg|bulgarian', 'bg', 'Български');
209 return array('bs|bosnian', 'bs', 'Bosanski');
211 return array('br|breton', 'br', 'Brezhoneg');
213 return array('ca|catalan', 'ca', 'Català');
215 return array('cs|czech', 'cs', 'Čeština');
217 return array('cy|welsh', 'cy', 'Cymraeg');
219 return array('da|danish', 'da', 'Dansk');
221 return array('de|german', 'de', 'Deutsch');
223 return array('el|greek', 'el', 'Ελληνικά');
225 return array('en|english', 'en', '');
227 return array('en[_-]gb|english (United Kingdom)', 'en-gb', '');
229 return array('es|spanish', 'es', 'Español');
231 return array('et|estonian', 'et', 'Eesti');
233 return array('eu|basque', 'eu', 'Euskara');
235 return array('fa|persian', 'fa', 'فارسی');
237 return array('fi|finnish', 'fi', 'Suomi');
239 return array('fr|french', 'fr', 'Français');
241 return array('gl|galician', 'gl', 'Galego');
243 return array('he|hebrew', 'he', 'עברית');
245 return array('hi|hindi', 'hi', 'हिन्दी');
247 return array('hr|croatian', 'hr', 'Hrvatski');
249 return array('hu|hungarian', 'hu', 'Magyar');
251 return array('id|indonesian', 'id', 'Bahasa Indonesia');
253 return array('it|italian', 'it', 'Italiano');
255 return array('ja|japanese', 'ja', '日本語');
257 return array('ko|korean', 'ko', '한국어');
259 return array('ka|georgian', 'ka', 'ქართული');
261 return array('lt|lithuanian', 'lt', 'Lietuvių');
263 return array('lv|latvian', 'lv', 'Latviešu');
265 return array('mk|macedonian', 'mk', 'Macedonian');
267 return array('mn|mongolian', 'mn', 'Монгол');
269 return array('ms|malay', 'ms', 'Bahasa Melayu');
271 return array('nl|dutch', 'nl', 'Nederlands');
273 return array('nb|norwegian', 'nb', 'Norsk');
275 return array('pl|polish', 'pl', 'Polski');
277 return array('pt[-_]br|brazilian portuguese', 'pt-BR', 'Português');
279 return array('pt|portuguese', 'pt', 'Português');
281 return array('ro|romanian', 'ro', 'Română');
283 return array('ru|russian', 'ru', 'Русский');
285 return array('si|sinhala', 'si', 'සිංහල');
287 return array('sk|slovak', 'sk', 'Slovenčina');
289 return array('sl|slovenian', 'sl', 'Slovenščina');
291 return array('sq|albanian', 'sq', 'Shqip');
293 return array('sr[-_]lat|serbian latin', 'sr-lat', 'Srpski');
295 return array('sr|serbian', 'sr', 'Српски');
297 return array('sv|swedish', 'sv', 'Svenska');
299 return array('ta|tamil', 'ta', 'தமிழ்');
301 return array('te|telugu', 'te', 'తెలుగు');
303 return array('th|thai', 'th', 'ภาษาไทย');
305 return array('tr|turkish', 'tr', 'Türkçe');
307 return array('tt|tatarish', 'tt', 'Tatarça');
309 return array('ug|uyghur', 'ug', 'ئۇيغۇرچە');
311 return array('uk|ukrainian', 'uk', 'Українська');
313 return array('ur|urdu', 'ur', 'اُردوُ');
315 return array('uz[-_]lat|uzbek-latin', 'uz-lat', 'O‘zbekcha');
317 return array('uz[-_]cyr|uzbek-cyrillic', 'uz-cyr', 'Ўзбекча');
319 return array('zh[-_](tw|hk)|chinese traditional', 'zh-TW', '中文');
321 return array('zh|chinese simplified', 'zh', '中文');
323 return array("$lang|$lang", $lang, $lang);
327 * Returns list of languages supported by phpMyAdmin
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'])) {
341 /* Open the directory */
342 $handle = @opendir
($GLOBALS['lang_path']);
343 /* This can happen if the kit is English-only */
344 if ($handle === false) {
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 */
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 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'])) {
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(
418 'gb2312' => 'gb2312',
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',
429 'shift_jis' => 'sjis',
430 'tis-620' => 'tis620',
432 'windows-1250' => 'cp1250',
433 'windows-1251' => 'cp1251',
434 'windows-1252' => 'latin1',
435 'windows-1256' => 'cp1256',
436 'windows-1257' => 'cp1257',
443 if (! PMA_langCheck()) {
445 $fall_back_lang = 'en';
447 if (! PMA_langSet($fall_back_lang)) {
448 trigger_error('phpMyAdmin-ERROR: invalid lang code: '
449 . __FILE__
. '#' . $line . ', check hard coded fall back language.',
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.');
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');
479 $GLOBALS['l'] = array();
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']) {
493 sprintf(__('Unknown language: %1$s.'),
494 htmlspecialchars($GLOBALS['lang_failed_cfg'])),
497 if ($GLOBALS['lang_failed_cookie']) {
499 sprintf(__('Unknown language: %1$s.'),
500 htmlspecialchars($GLOBALS['lang_failed_cookie'])),
503 if ($GLOBALS['lang_failed_request']) {
505 sprintf(__('Unknown language: %1$s.'),
506 htmlspecialchars($GLOBALS['lang_failed_request'])),
510 unset($line, $fall_back_lang,
511 $GLOBALS['lang_failed_cfg'], $GLOBALS['lang_failed_cookie'], $GLOBALS['lang_failed_request']);