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('tk|turkmen', 'tk', 'türkmençe');
307 return array('tr|turkish', 'tr', 'Türkçe');
309 return array('tt|tatarish', 'tt', 'Tatarça');
311 return array('ug|uyghur', 'ug', 'ئۇيغۇرچە');
313 return array('uk|ukrainian', 'uk', 'Українська');
315 return array('ur|urdu', 'ur', 'اُردوُ');
317 return array('uz[-_]lat|uzbek-latin', 'uz-lat', 'O‘zbekcha');
319 return array('uz[-_]cyr|uzbek-cyrillic', 'uz-cyr', 'Ўзбекча');
321 return array('zh[-_](tw|hk)|chinese traditional', 'zh-TW', '中文');
323 return array('zh|chinese simplified', 'zh', '中文');
325 return array("$lang|$lang", $lang, $lang);
329 * Returns list of languages supported by phpMyAdmin
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'])) {
343 /* Open the directory */
344 $handle = @opendir
($GLOBALS['lang_path']);
345 /* This can happen if the kit is English-only */
346 if ($handle === false) {
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 */
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'])) {
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(
420 'gb2312' => 'gb2312',
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',
431 'shift_jis' => 'sjis',
432 'tis-620' => 'tis620',
434 'windows-1250' => 'cp1250',
435 'windows-1251' => 'cp1251',
436 'windows-1252' => 'latin1',
437 'windows-1256' => 'cp1256',
438 'windows-1257' => 'cp1257',
445 if (! PMA_langCheck()) {
447 $fall_back_lang = 'en';
449 if (! PMA_langSet($fall_back_lang)) {
450 trigger_error('phpMyAdmin-ERROR: invalid lang code: '
451 . __FILE__
. '#' . $line . ', check hard coded fall back language.',
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.');
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');
481 $GLOBALS['l'] = array();
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']) {
495 sprintf(__('Unknown language: %1$s.'),
496 htmlspecialchars($GLOBALS['lang_failed_cfg'])),
499 if ($GLOBALS['lang_failed_cookie']) {
501 sprintf(__('Unknown language: %1$s.'),
502 htmlspecialchars($GLOBALS['lang_failed_cookie'])),
505 if ($GLOBALS['lang_failed_request']) {
507 sprintf(__('Unknown language: %1$s.'),
508 htmlspecialchars($GLOBALS['lang_failed_request'])),
512 unset($line, $fall_back_lang,
513 $GLOBALS['lang_failed_cfg'], $GLOBALS['lang_failed_cookie'], $GLOBALS['lang_failed_request']);