2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * phpMyAdmin Language Loading File
8 if (! defined('PHPMYADMIN')) {
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;
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']
39 * @uses PMA_langDetect()
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'])) {
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'])) {
59 } elseif (!is_string($_POST['lang'])) {
60 /* Faked request, don't care on localisation */
61 $GLOBALS['lang_failed_request'] = 'Yes';
63 $GLOBALS['lang_failed_request'] = $_POST['lang'];
67 // check user requested language (GET)
68 if (! empty($_GET['lang'])) {
69 if (PMA_langSet($_GET['lang'])) {
71 } elseif (!is_string($_GET['lang'])) {
72 /* Faked request, don't care on localisation */
73 $GLOBALS['lang_failed_request'] = 'Yes';
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'])) {
83 } elseif (!is_string($_COOKIE['pma_lang'])) {
84 /* Faked request, don't care on localisation */
85 $GLOBALS['lang_failed_cookie'] = 'Yes';
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)) {
100 // try to findout user's language by checking its HTTP_USER_AGENT variable
101 if (PMA_langDetect(PMA_getenv('HTTP_USER_AGENT'), 2)) {
105 // Didn't catch any valid lang : we use the default settings
106 if (PMA_langSet($GLOBALS['cfg']['DefaultLang'])) {
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])) {
130 $GLOBALS['lang'] = $lang;
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
147 function PMA_langDetect($str, $envType)
152 if (empty($GLOBALS['available_languages'])) {
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
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)) {
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
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
200 function PMA_langDetails($lang) {
203 return array('en|english', 'en', '');
205 return array('af|afrikaans', 'af', '');
207 return array('ar|arabic', 'ar', 'العربية');
209 return array('az|azerbaijani', 'az', 'Azərbaycanca');
211 return array('bn|bangla', 'bn', '');
213 return array('be|belarusian', 'be', 'Беларуская');
215 return array('be[-_]lat|belarusian latin', 'be-lat', 'Biełaruskaja');
217 return array('bg|bulgarian', 'bg', 'Български');
219 return array('bs|bosnian', 'bs', 'Bosanski');
221 return array('ca|catalan', 'ca', 'Català');
223 return array('cs|czech', 'cs', 'Česky');
225 return array('cy|welsh', 'cy', 'Cymraeg');
227 return array('da|danish', 'da', 'Dansk');
229 return array('de|german', 'de', 'Deutsch');
231 return array('el|greek', 'el', 'Ελληνικά');
233 return array('en|english', 'en', '');
235 return array('en[_-]gb|english (United Kingdom)', 'en-gb', '');
237 return array('es|spanish', 'es', 'Español');
239 return array('et|estonian', 'et', 'Eesti');
241 return array('eu|basque', 'eu', 'Euskara');
243 return array('fa|persian', 'fa', 'فارسی');
245 return array('fi|finnish', 'fi', 'Suomi');
247 return array('fr|french', 'fr', 'Français');
249 return array('gl|galician', 'gl', 'Galego');
251 return array('he|hebrew', 'he', 'עברית');
253 return array('hi|hindi', 'hi', 'हिन्दी');
255 return array('hr|croatian', 'hr', 'Hrvatski');
257 return array('hu|hungarian', 'hu', 'Magyar');
259 return array('id|indonesian', 'id', 'Bahasa Indonesia');
261 return array('it|italian', 'it', 'Italiano');
263 return array('ja|japanese', 'ja', '日本語');
265 return array('ko|korean', 'ko', '한국어');
267 return array('ka|georgian', 'ka', 'ქართული');
269 return array('lt|lithuanian', 'lt', 'Lietuvių');
271 return array('lv|latvian', 'lv', 'Latviešu');
273 return array('mk|macedonian', 'mk', 'Macedonian');
275 return array('mn|mongolian', 'mn', 'Монгол');
277 return array('ms|malay', 'ms', 'Bahasa Melayu');
279 return array('nl|dutch', 'nl', 'Nederlands');
281 return array('nb|norwegian', 'nb', 'Norsk');
283 return array('pl|polish', 'pl', 'Polski');
285 return array('pt[-_]br|brazilian portuguese', 'pt-BR', 'Português');
287 return array('pt|portuguese', 'pt', 'Português');
289 return array('ro|romanian', 'ro', 'Română');
291 return array('ru|russian', 'ru', 'Русский');
293 return array('si|sinhala', 'si', 'සිංහල');
295 return array('sk|slovak', 'sk', 'Slovenčina');
297 return array('sl|slovenian', 'sl', 'Slovenščina');
299 return array('sq|albanian', 'sq', 'Shqip');
301 return array('sr[-_]lat|serbian latin', 'sr-lat', 'Srpski');
303 return array('sr|serbian', 'sr', 'Српски');
305 return array('sv|swedish', 'sv', 'Svenska');
307 return array('ta|tamil', 'ta', 'தமிழ்');
309 return array('te|telugu', 'te', 'తెలుగు');
311 return array('th|thai', 'th', 'ภาษาไทย');
313 return array('tr|turkish', 'tr', 'Türkçe');
315 return array('tt|tatarish', 'tt', 'Tatarça');
317 return array('ug|uyghur', 'ug', 'ئۇيغۇرچە');
319 return array('uk|ukrainian', 'uk', 'Українська');
321 return array('ur|urdu', 'ur', 'اُردوُ');
323 return array('uz[-_]lat|uzbek-latin', 'uz-lat', 'O‘zbekcha');
325 return array('uz[-_]cyr|uzbek-cyrillic', 'uz-cyr', 'Ўзбекча');
327 return array('zh[-_](tw|hk)|chinese traditional', 'zh-TW', '中文');
329 return array('zh|chinese simplified', 'zh', '中文');
331 return array("$lang|$lang", $lang, $lang);
335 * Returns list of languages supported by phpMyAdmin
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 /* This can happen if the kit is English-only */
347 if ($handle === FALSE) {
351 /* Process all files */
352 while (FALSE !== ($file = readdir($handle))) {
353 if ($file != "." && $file != ".." && file_exists($GLOBALS['lang_path'] . '/' . $file . '/LC_MESSAGES/phpmyadmin.mo')) {
354 $result[$file] = PMA_langDetails($file);
357 /* Close the handle */
364 * @global string path to the translations directory; may be absent if the kit is English-only
366 $GLOBALS['lang_path'] = './locale/';
369 * Load gettext functions.
371 require './libraries/php-gettext/gettext.inc';
374 * @global string interface language
376 $GLOBALS['lang'] = 'en';
378 * @global boolean whether loading lang from cfg failed
380 $GLOBALS['lang_failed_cfg'] = false;
382 * @global boolean whether loading lang from cookie failed
384 $GLOBALS['lang_failed_cookie'] = false;
386 * @global boolean whether loading lang from user request failed
388 $GLOBALS['lang_failed_request'] = false;
390 * @global string text direction ltr or rtl
392 $GLOBALS['text_dir'] = 'ltr';
395 * @global array supported languages
397 $GLOBALS['available_languages'] = PMA_langList();
399 // Language filtering support
400 if (! empty($GLOBALS['cfg']['FilterLanguages'])) {
402 foreach ($GLOBALS['available_languages'] as $key => $val) {
403 if (preg_match('@' . $GLOBALS['cfg']['FilterLanguages'] . '@', $key)) {
404 $new_lang[$key] = $val;
407 if (count($new_lang) > 0) {
408 $GLOBALS['available_languages'] = $new_lang;
410 unset($key, $val, $new_lang);
414 * @global array MySQL charsets map
416 $GLOBALS['mysql_charset_map'] = array(
421 'gb2312' => 'gb2312',
423 'iso-8859-1' => 'latin1',
424 'iso-8859-2' => 'latin2',
425 'iso-8859-7' => 'greek',
426 'iso-8859-8' => 'hebrew',
427 'iso-8859-8-i' => 'hebrew',
428 'iso-8859-9' => 'latin5',
429 'iso-8859-13' => 'latin7',
430 'iso-8859-15' => 'latin1',
432 'shift_jis' => 'sjis',
433 'tis-620' => 'tis620',
435 'windows-1250' => 'cp1250',
436 'windows-1251' => 'cp1251',
437 'windows-1252' => 'latin1',
438 'windows-1256' => 'cp1256',
439 'windows-1257' => 'cp1257',
446 if (! PMA_langCheck()) {
448 $fall_back_lang = 'en';
450 if (! PMA_langSet($fall_back_lang)) {
451 trigger_error('phpMyAdmin-ERROR: invalid lang code: '
452 . __FILE__
. '#' . $line . ', check hard coded fall back language.',
455 // and tell the user that his chosen language is invalid
456 PMA_fatalError('Could not load any language, please check your language settings and folder.');
461 _setlocale(LC_MESSAGES
, $GLOBALS['lang']);
462 _bindtextdomain('phpmyadmin', $GLOBALS['lang_path']);
463 _bind_textdomain_codeset('phpmyadmin', 'UTF-8');
464 _textdomain('phpmyadmin');
467 * Messages for phpMyAdmin.
469 * These messages are here for easy transition to Gettext.
470 * You should not add any messages here, use instead gettext directly
471 * in your template/PHP file.
474 if (! function_exists('__')) {
475 die('Bad invocation!');
478 /* We use only utf-8 */
481 /* l10n: Text direction, use either ltr or rtl */
482 $text_dir = __('ltr');
484 // now, that we have loaded the language strings we can send the errors
485 if ($GLOBALS['lang_failed_cfg']) {
487 sprintf(__('Unknown language: %1$s.'),
488 htmlspecialchars($GLOBALS['lang_failed_cfg'])),
491 if ($GLOBALS['lang_failed_cookie']) {
493 sprintf(__('Unknown language: %1$s.'),
494 htmlspecialchars($GLOBALS['lang_failed_cookie'])),
497 if ($GLOBALS['lang_failed_request']) {
499 sprintf(__('Unknown language: %1$s.'),
500 htmlspecialchars($GLOBALS['lang_failed_request'])),
504 unset($line, $fall_back_lang,
505 $GLOBALS['lang_failed_cfg'], $GLOBALS['lang_failed_cookie'], $GLOBALS['ang_failed_request']);