2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * phpMyAdmin Language Loading File
8 if (! defined('PHPMYADMIN')) {
13 * tries to find the language to use
15 * @uses $GLOBALS['cfg']['lang']
16 * @uses $GLOBALS['cfg']['DefaultLang']
17 * @uses $GLOBALS['lang_failed_cfg']
18 * @uses $GLOBALS['lang_failed_cookie']
19 * @uses $GLOBALS['lang_failed_request']
20 * @uses $GLOBALS['convcharset'] to set it if not set
21 * @uses $_REQUEST['lang']
22 * @uses $_COOKIE['pma_lang']
23 * @uses $_SERVER['HTTP_ACCEPT_LANGUAGE']
24 * @uses $_SERVER['HTTP_USER_AGENT']
26 * @uses PMA_langDetect()
28 * @return bool success if valid lang is found, otherwise false
30 function PMA_langCheck()
32 // check forced language
33 if (! empty($GLOBALS['cfg']['Lang'])) {
34 if (PMA_langSet($GLOBALS['cfg']['Lang'])) {
37 $GLOBALS['lang_failed_cfg'] = $GLOBALS['cfg']['Lang'];
41 // Don't use REQUEST in following code as it might be confused by cookies with same name
42 // check user requested language (POST)
43 if (! empty($_POST['lang'])) {
44 if (PMA_langSet($_POST['lang'])) {
46 } elseif (!is_string($_POST['lang'])) {
47 /* Faked request, don't care on localisation */
48 $GLOBALS['lang_failed_request'] = 'Yes';
50 $GLOBALS['lang_failed_request'] = $_POST['lang'];
54 // check user requested language (GET)
55 if (! empty($_GET['lang'])) {
56 if (PMA_langSet($_GET['lang'])) {
58 } elseif (!is_string($_GET['lang'])) {
59 /* Faked request, don't care on localisation */
60 $GLOBALS['lang_failed_request'] = 'Yes';
62 $GLOBALS['lang_failed_request'] = $_GET['lang'];
66 // check previous set language
67 if (! empty($_COOKIE['pma_lang'])) {
68 if (PMA_langSet($_COOKIE['pma_lang'])) {
70 } elseif (!is_string($_COOKIE['lang'])) {
71 /* Faked request, don't care on localisation */
72 $GLOBALS['lang_failed_request'] = 'Yes';
74 $GLOBALS['lang_failed_cookie'] = $_COOKIE['pma_lang'];
78 // try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE variable
79 if (PMA_getenv('HTTP_ACCEPT_LANGUAGE')) {
80 foreach (explode(',', PMA_getenv('HTTP_ACCEPT_LANGUAGE')) as $lang) {
81 if (PMA_langDetect($lang, 1)) {
87 // try to findout user's language by checking its HTTP_USER_AGENT variable
88 if (PMA_langDetect(PMA_getenv('HTTP_USER_AGENT'), 2)) {
92 // Didn't catch any valid lang : we use the default settings
93 if (PMA_langSet($GLOBALS['cfg']['DefaultLang'])) {
101 * checks given lang and sets it if valid
102 * returns true on success, otherwise flase
104 * @uses $GLOBALS['available_languages'] to check $lang
105 * @uses $GLOBALS['lang'] to set it
106 * @param string $lang language to set
107 * @return bool success
109 function PMA_langSet(&$lang)
111 if (!is_string($lang) ||
empty($lang) ||
empty($GLOBALS['available_languages'][$lang])) {
114 $GLOBALS['lang'] = $lang;
119 * Analyzes some PHP environment variables to find the most probable language
120 * that should be used
122 * @param string string to analyze
123 * @param integer type of the PHP environment variable which value is $str
125 * @return bool true on success, otherwise false
127 * @global $available_languages
131 function PMA_langDetect(&$str, $envType)
136 if (empty($GLOBALS['available_languages'])) {
140 foreach ($GLOBALS['available_languages'] as $lang => $value) {
141 // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
142 // 2 for the 'HTTP_USER_AGENT' one
144 if (strpos($expr, '[-_]') === FALSE) {
145 $expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr);
147 if (($envType == 1 && eregi('^(' . $expr . ')(;q=[0-9]\\.[0-9])?$', $str))
148 ||
($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $expr . ')(;|\]|\))', $str))) {
149 if (PMA_langSet($lang)) {
156 } // end of the 'PMA_langDetect()' function
159 * Returns list of languages supported by phpMyAdmin
163 function PMA_langList()
166 * All the supported languages have to be listed in the array below.
167 * 1. The key must be the "official" ISO 639 language code and, if required,
168 * the dialect code. It can also contain some information about the
169 * charset (see the Russian case).
170 * 2. The first of the values associated to the key is used in a regular
171 * expression to find some keywords corresponding to the language inside two
172 * environment variables.
173 * These values contain:
174 * - the "official" ISO language code and, if required, the dialect code
175 * too ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
176 * dialects, 'zh[-_]tw' for Chinese traditional...), the dialect has to
177 * be specified first;
178 * - the '|' character (it means 'OR');
179 * - the full language name.
180 * 3. The second value associated to the key is the name of the file to load
181 * without the 'inc.php' extension.
182 * 4. The third value associated to the key is the language code as defined by
184 * 5. The fourth value is its native name in html entities.
186 * Beware that the sorting order (first values associated to keys by
187 * alphabetical reverse order in the array) is important: 'zh-tw' (chinese
188 * traditional) must be detected before 'zh' (chinese simplified) for
193 'af-utf-8' => array('af|afrikaans', 'afrikaans-utf-8', 'af', ''),
194 'ar-utf-8' => array('ar|arabic', 'arabic-utf-8', 'ar', 'العربية'),
195 'az-utf-8' => array('az|azerbaijani', 'azerbaijani-utf-8', 'az', 'Azərbaycanca'),
196 'bn-utf-8' => array('bn|bangla', 'bangla-utf-8', 'bn', ''),
197 'becyr-utf-8' => array('be|belarusian', 'belarusian_cyrillic-utf-8', 'be', 'Беларуская'),
198 'belat-utf-8' => array('be[-_]lat|belarusian latin', 'belarusian_latin-utf-8', 'be-lat', 'Biełaruskaja'),
199 'bg-utf-8' => array('bg|bulgarian', 'bulgarian-utf-8', 'bg', 'Български'),
200 'bs-utf-8' => array('bs|bosnian', 'bosnian-utf-8', 'bs', 'Bosanski'),
201 'ca-utf-8' => array('ca|catalan', 'catalan-utf-8', 'ca', 'Català'),
202 'cs-utf-8' => array('cs|czech', 'czech-utf-8', 'cs', 'Česky'),
203 'da-utf-8' => array('da|danish', 'danish-utf-8', 'da', 'Dansk'),
204 'de-utf-8' => array('de|german', 'german-utf-8', 'de', 'Deutsch'),
205 'el-utf-8' => array('el|greek', 'greek-utf-8', 'el', 'Ελληνικά'),
206 'en-utf-8' => array('en|english', 'english-utf-8', 'en', ''),
207 'es-utf-8' => array('es|spanish', 'spanish-utf-8', 'es', 'Español'),
208 'et-utf-8' => array('et|estonian', 'estonian-utf-8', 'et', 'Eesti'),
209 'eu-utf-8' => array('eu|basque', 'basque-utf-8', 'eu', 'Euskara'),
210 'fa-utf-8' => array('fa|persian', 'persian-utf-8', 'fa', 'فارسی'),
211 'fi-utf-8' => array('fi|finnish', 'finnish-utf-8', 'fi', 'Suomi'),
212 'fr-utf-8' => array('fr|french', 'french-utf-8', 'fr', 'Français'),
213 'gl-utf-8' => array('gl|galician', 'galician-utf-8', 'gl', 'Galego'),
214 'he-utf-8' => array('he|hebrew', 'hebrew-utf-8', 'he', 'עברית'),
215 'hi-utf-8' => array('hi|hindi', 'hindi-utf-8', 'hi', 'हिन्दी'),
216 'hr-utf-8' => array('hr|croatian', 'croatian-utf-8', 'hr', 'Hrvatski'),
217 'hu-utf-8' => array('hu|hungarian', 'hungarian-utf-8', 'hu', 'Magyar'),
218 'id-utf-8' => array('id|indonesian', 'indonesian-utf-8', 'id', 'Bahasa Indonesia'),
219 'it-utf-8' => array('it|italian', 'italian-utf-8', 'it', 'Italiano'),
220 'ja-utf-8' => array('ja|japanese', 'japanese-utf-8', 'ja', '日本語'),
221 'ko-utf-8' => array('ko|korean', 'korean-utf-8', 'ko', '한국어'),
222 'ka-utf-8' => array('ka|georgian', 'georgian-utf-8', 'ka', 'ქართული'),
223 'lt-utf-8' => array('lt|lithuanian', 'lithuanian-utf-8', 'lt', 'Lietuvių'),
224 'lv-utf-8' => array('lv|latvian', 'latvian-utf-8', 'lv', 'Latviešu'),
225 'mkcyr-utf-8' => array('mk|macedonian', 'macedonian_cyrillic-utf-8', 'mk', 'Macedonian'),
226 'mn-utf-8' => array('mn|mongolian', 'mongolian-utf-8', 'mn', 'Монгол'),
227 'ms-utf-8' => array('ms|malay', 'malay-utf-8', 'ms', 'Bahasa Melayu'),
228 'nl-utf-8' => array('nl|dutch', 'dutch-utf-8', 'nl', 'Nederlands'),
229 'no-utf-8' => array('no|norwegian', 'norwegian-utf-8', 'no', 'Norsk'),
230 'pl-utf-8' => array('pl|polish', 'polish-utf-8', 'pl', 'Polski'),
231 'ptbr-utf-8' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR', 'Português'),
232 'pt-utf-8' => array('pt|portuguese', 'portuguese-utf-8', 'pt', 'Português'),
233 'ro-utf-8' => array('ro|romanian', 'romanian-utf-8', 'ro', 'Română'),
234 'ru-utf-8' => array('ru|russian', 'russian-utf-8', 'ru', 'Русский'),
235 'si-utf-8' => array('si|sinhala', 'sinhala-utf-8', 'si', 'සිංහල'),
236 'sk-utf-8' => array('sk|slovak', 'slovak-utf-8', 'sk', 'Slovenčina'),
237 'sl-utf-8' => array('sl|slovenian', 'slovenian-utf-8', 'sl', 'Slovenščina'),
238 'sq-utf-8' => array('sq|albanian', 'albanian-utf-8', 'sq', 'Shqip'),
239 'srlat-utf-8' => array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat', 'Srpski'),
240 'srcyr-utf-8' => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr', 'Српски'),
241 'sv-utf-8' => array('sv|swedish', 'swedish-utf-8', 'sv', 'Svenska'),
242 'th-utf-8' => array('th|thai', 'thai-utf-8', 'th', 'ภาษาไทย'),
243 'tr-utf-8' => array('tr|turkish', 'turkish-utf-8', 'tr', 'Türkçe'),
244 'tt-utf-8' => array('tt|tatarish', 'tatarish-utf-8', 'tt', 'Tatarça'),
245 'uk-utf-8' => array('uk|ukrainian', 'ukrainian-utf-8', 'uk', 'Українська'),
246 'zhtw-utf-8' => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-utf-8', 'zh-TW', '中文'),
247 'zh-utf-8' => array('zh|chinese simplified', 'chinese_simplified-utf-8', 'zh', '中文'),
252 * @global string path to the translations directory
254 $GLOBALS['lang_path'] = './lang/';
257 * @global string interface language
259 $GLOBALS['lang'] = 'en-utf-8';
261 * @global boolean whether loading lang from cfg failed
263 $GLOBALS['lang_failed_cfg'] = false;
265 * @global boolean whether loading lang from cookie failed
267 $GLOBALS['lang_failed_cookie'] = false;
269 * @global boolean whether loading lang from user request failed
271 $GLOBALS['lang_failed_request'] = false;
273 * @global string text direction ltr or rtl
275 $GLOBALS['text_dir'] = 'ltr';
278 * @global array supported languages
280 $GLOBALS['available_languages'] = PMA_langList();
282 // Language filtering support
283 if (! empty($GLOBALS['cfg']['FilterLanguages'])) {
285 foreach ($GLOBALS['available_languages'] as $key => $val) {
286 if (preg_match('@' . $GLOBALS['cfg']['FilterLanguages'] . '@', $key)) {
287 $new_lang[$key] = $val;
290 if (count($new_lang) > 0) {
291 $GLOBALS['available_languages'] = $new_lang;
293 unset($key, $val, $new_lang);
297 * first check for lang dir exists
299 if (! is_dir($GLOBALS['lang_path'])) {
300 // language directory not found
301 trigger_error('phpMyAdmin-ERROR: path not found: '
302 . $GLOBALS['lang_path'] . ', check your language directory.',
305 PMA_fatalError('path to languages is invalid: ' . $GLOBALS['lang_path']);
309 * check for language files
311 foreach ($GLOBALS['available_languages'] as $each_lang_key => $each_lang) {
312 if (! file_exists($GLOBALS['lang_path'] . $each_lang[1] . '.inc.php')) {
313 unset($GLOBALS['available_languages'][$each_lang_key]);
316 unset($each_lang_key, $each_lang);
319 * @global array MySQL charsets map
321 $GLOBALS['mysql_charset_map'] = array(
326 'gb2312' => 'gb2312',
328 'iso-8859-1' => 'latin1',
329 'iso-8859-2' => 'latin2',
330 'iso-8859-7' => 'greek',
331 'iso-8859-8' => 'hebrew',
332 'iso-8859-8-i' => 'hebrew',
333 'iso-8859-9' => 'latin5',
334 'iso-8859-13' => 'latin7',
335 'iso-8859-15' => 'latin1',
337 'shift_jis' => 'sjis',
338 'tis-620' => 'tis620',
340 'windows-1250' => 'cp1250',
341 'windows-1251' => 'cp1251',
342 'windows-1252' => 'latin1',
343 'windows-1256' => 'cp1256',
344 'windows-1257' => 'cp1257',
351 if (empty($GLOBALS['convcharset'])) {
352 if (isset($_COOKIE['pma_charset'])) {
353 $GLOBALS['convcharset'] = $_COOKIE['pma_charset'];
355 // session.save_path might point to a bad folder, in which case
356 // $GLOBALS['cfg'] would not exist
357 $GLOBALS['convcharset'] = isset($GLOBALS['cfg']['DefaultCharset']) ?
$GLOBALS['cfg']['DefaultCharset'] : 'utf-8';
361 if (! PMA_langCheck()) {
363 $fall_back_lang = 'en-utf-8';
365 if (! PMA_langSet($fall_back_lang)) {
366 trigger_error('phpMyAdmin-ERROR: invalid lang code: '
367 . __FILE__
. '#' . $line . ', check hard coded fall back language.',
370 // and tell the user that his choosen language is invalid
371 PMA_fatalError('Could not load any language, please check your language settings and folder.');
375 // Defines the associated filename and load the translation
376 $lang_file = $GLOBALS['lang_path'] . $GLOBALS['available_languages'][$GLOBALS['lang']][1] . '.inc.php';
377 require_once $lang_file;
379 // now, that we have loaded the language strings we can send the errors
380 if ($GLOBALS['lang_failed_cfg']) {
382 sprintf($GLOBALS['strLanguageUnknown'],
383 htmlspecialchars($GLOBALS['lang_failed_cfg'])),
386 if ($GLOBALS['lang_failed_cookie']) {
388 sprintf($GLOBALS['strLanguageUnknown'],
389 htmlspecialchars($GLOBALS['lang_failed_cookie'])),
392 if ($GLOBALS['lang_failed_request']) {
394 sprintf($GLOBALS['strLanguageUnknown'],
395 htmlspecialchars($GLOBALS['lang_failed_request'])),
399 unset($line, $fall_back_lang,
400 $GLOBALS['lang_failed_cfg'], $GLOBALS['lang_failed_cookie'], $GLOBALS['ang_failed_request'], $GLOBALS['strLanguageUnknown']);