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 if ($handle === FALSE) {
347 trigger_error('phpMyAdmin: path not found: '
348 . $GLOBALS['lang_path'] . ', check your language directory.',
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 */
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'])) {
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(
423 'gb2312' => 'gb2312',
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',
434 'shift_jis' => 'sjis',
435 'tis-620' => 'tis620',
437 'windows-1250' => 'cp1250',
438 'windows-1251' => 'cp1251',
439 'windows-1252' => 'latin1',
440 'windows-1256' => 'cp1256',
441 'windows-1257' => 'cp1257',
448 if (! PMA_langCheck()) {
450 $fall_back_lang = 'en';
452 if (! PMA_langSet($fall_back_lang)) {
453 trigger_error('phpMyAdmin-ERROR: invalid lang code: '
454 . __FILE__
. '#' . $line . ', check hard coded fall back language.',
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.');
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 */
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']) {
489 sprintf(__('Unknown language: %1$s.'),
490 htmlspecialchars($GLOBALS['lang_failed_cfg'])),
493 if ($GLOBALS['lang_failed_cookie']) {
495 sprintf(__('Unknown language: %1$s.'),
496 htmlspecialchars($GLOBALS['lang_failed_cookie'])),
499 if ($GLOBALS['lang_failed_request']) {
501 sprintf(__('Unknown language: %1$s.'),
502 htmlspecialchars($GLOBALS['lang_failed_request'])),
506 unset($line, $fall_back_lang,
507 $GLOBALS['lang_failed_cfg'], $GLOBALS['lang_failed_cookie'], $GLOBALS['ang_failed_request']);