2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * phpMyAdmin Language Loading File
10 * tries to find the language to use
12 * @uses $GLOBALS['cfg']['lang']
13 * @uses $GLOBALS['cfg']['DefaultLang']
14 * @uses $GLOBALS['lang_failed_cfg']
15 * @uses $GLOBALS['lang_failed_cookie']
16 * @uses $GLOBALS['lang_failed_request']
17 * @uses $GLOBALS['convcharset'] to set it if not set
18 * @uses $_REQUEST['lang']
19 * @uses $_COOKIE['pma_lang']
20 * @uses $_SERVER['HTTP_ACCEPT_LANGUAGE']
21 * @uses $_SERVER['HTTP_USER_AGENT']
23 * @uses PMA_langDetect()
25 * @return bool success if valid lang is found, otherwise false
27 function PMA_langCheck()
29 // check forced language
30 if (! empty($GLOBALS['cfg']['Lang'])) {
31 if (PMA_langSet($GLOBALS['cfg']['Lang'])) {
34 $GLOBALS['lang_failed_cfg'] = $GLOBALS['cfg']['Lang'];
38 // Don't use REQUEST in following code as it might be confused by cookies with same name
39 // check user requested language (POST)
40 if (! empty($_POST['lang'])) {
41 if (PMA_langSet($_POST['lang'])) {
43 } elseif (!is_string($_POST['lang'])) {
44 /* Faked request, don't care on localisation */
45 $GLOBALS['lang_failed_request'] = 'Yes';
47 $GLOBALS['lang_failed_request'] = $_POST['lang'];
51 // check user requested language (GET)
52 if (! empty($_GET['lang'])) {
53 if (PMA_langSet($_GET['lang'])) {
55 } elseif (!is_string($_GET['lang'])) {
56 /* Faked request, don't care on localisation */
57 $GLOBALS['lang_failed_request'] = 'Yes';
59 $GLOBALS['lang_failed_request'] = $_GET['lang'];
63 // check previous set language
64 if (! empty($_COOKIE['pma_lang'])) {
65 if (PMA_langSet($_COOKIE['pma_lang'])) {
67 } elseif (!is_string($_COOKIE['lang'])) {
68 /* Faked request, don't care on localisation */
69 $GLOBALS['lang_failed_request'] = 'Yes';
71 $GLOBALS['lang_failed_cookie'] = $_COOKIE['pma_lang'];
75 // try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE variable
76 if (PMA_getenv('HTTP_ACCEPT_LANGUAGE')) {
77 foreach (explode(',', PMA_getenv('HTTP_ACCEPT_LANGUAGE')) as $lang) {
78 if (PMA_langDetect($lang, 1)) {
84 // try to findout user's language by checking its HTTP_USER_AGENT variable
85 if (PMA_langDetect(PMA_getenv('HTTP_USER_AGENT'), 2)) {
89 // Didn't catch any valid lang : we use the default settings
90 if (PMA_langSet($GLOBALS['cfg']['DefaultLang'])) {
98 * checks given lang and sets it if valid
99 * returns true on success, otherwise flase
101 * @uses $GLOBALS['available_languages'] to check $lang
102 * @uses $GLOBALS['lang'] to set it
103 * @param string $lang language to set
104 * @return bool success
106 function PMA_langSet(&$lang)
108 if (!is_string($lang) ||
empty($lang) ||
empty($GLOBALS['available_languages'][$lang])) {
111 $GLOBALS['lang'] = $lang;
116 * Analyzes some PHP environment variables to find the most probable language
117 * that should be used
119 * @param string string to analyze
120 * @param integer type of the PHP environment variable which value is $str
122 * @return bool true on success, otherwise false
124 * @global $available_languages
128 function PMA_langDetect(&$str, $envType)
133 if (empty($GLOBALS['available_languages'])) {
137 foreach ($GLOBALS['available_languages'] as $lang => $value) {
138 // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
139 // 2 for the 'HTTP_USER_AGENT' one
141 if (strpos($expr, '[-_]') === FALSE) {
142 $expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr);
144 if (($envType == 1 && eregi('^(' . $expr . ')(;q=[0-9]\\.[0-9])?$', $str))
145 ||
($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $expr . ')(;|\]|\))', $str))) {
146 if (PMA_langSet($lang)) {
153 } // end of the 'PMA_langDetect()' function
156 * @global string path to the translations directory
158 $GLOBALS['lang_path'] = './lang/';
161 * @global string interface language
163 $GLOBALS['lang'] = 'en-utf-8';
165 * @global boolean wether loading lang from cfg failed
167 $GLOBALS['lang_failed_cfg'] = false;
169 * @global boolean wether loading lang from cookie failed
171 $GLOBALS['lang_failed_cookie'] = false;
173 * @global boolean wether loading lang from user request failed
175 $GLOBALS['lang_failed_request'] = false;
177 * @global string text direction ltr or rtl
179 $GLOBALS['text_dir'] = 'ltr';
182 * All the supported languages have to be listed in the array below.
183 * 1. The key must be the "official" ISO 639 language code and, if required,
184 * the dialect code. It can also contain some informations about the
185 * charset (see the Russian case).
186 * 2. The first of the values associated to the key is used in a regular
187 * expression to find some keywords corresponding to the language inside two
188 * environment variables.
189 * These values contains:
190 * - the "official" ISO language code and, if required, the dialect code
191 * also ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
192 * dialects, 'zh[-_]tw' for Chinese traditional...), the dialect has to
193 * be specified as first;
194 * - the '|' character (it means 'OR');
195 * - the full language name.
196 * 3. The second values associated to the key is the name of the file to load
197 * without the 'inc.php' extension.
198 * 4. The third values associated to the key is the language code as defined by
200 * 5. The fourth value is native name in html entities.
202 * Beware that the sorting order (first values associated to keys by
203 * alphabetical reverse order in the array) is important: 'zh-tw' (chinese
204 * traditional) must be detected before 'zh' (chinese simplified) for
209 * @global array supported languages
211 $GLOBALS['available_languages'] = array(
212 'af-utf-8' => array('af|afrikaans', 'afrikaans-utf-8', 'af', ''),
213 'ar-utf-8' => array('ar|arabic', 'arabic-utf-8', 'ar', 'العربية'),
214 'az-utf-8' => array('az|azerbaijani', 'azerbaijani-utf-8', 'az', 'Azərbaycanca'),
216 'becyr-utf-8' => array('be|belarusian', 'belarusian_cyrillic-utf-8', 'be', 'Беларуская'),
217 'belat-utf-8' => array('be[-_]lat|belarusian latin', 'belarusian_latin-utf-8', 'be-lat', 'Byelorussian'),
218 'bg-utf-8' => array('bg|bulgarian', 'bulgarian-utf-8', 'bg', 'Български'),
219 'bs-utf-8' => array('bs|bosnian', 'bosnian-utf-8', 'bs', 'Bosanski'),
220 'ca-utf-8' => array('ca|catalan', 'catalan-utf-8', 'ca', 'Català'),
221 'cs-utf-8' => array('cs|czech', 'czech-utf-8', 'cs', 'Česky'),
222 'da-utf-8' => array('da|danish', 'danish-utf-8', 'da', 'Dansk'),
223 'de-utf-8' => array('de|german', 'german-utf-8', 'de', 'Deutsch'),
224 'el-utf-8' => array('el|greek', 'greek-utf-8', 'el', 'Ελληνικά'),
225 'en-utf-8' => array('en|english', 'english-utf-8', 'en', ''),
226 'es-utf-8' => array('es|spanish', 'spanish-utf-8', 'es', 'Español'),
227 'et-utf-8' => array('et|estonian', 'estonian-utf-8', 'et', 'Eesti'),
228 'eu-utf-8' => array('eu|basque', 'basque-utf-8', 'eu', 'Euskara'),
229 'fa-utf-8' => array('fa|persian', 'persian-utf-8', 'fa', 'فارسی'),
230 'fi-utf-8' => array('fi|finnish', 'finnish-utf-8', 'fi', 'Suomi'),
231 'fr-utf-8' => array('fr|french', 'french-utf-8', 'fr', 'Français'),
232 'gl-utf-8' => array('gl|galician', 'galician-utf-8', 'gl', 'Galego'),
233 'he-utf-8' => array('he|hebrew', 'hebrew-utf-8', 'he', 'עברית'),
234 'hi-utf-8' => array('hi|hindi', 'hindi-utf-8', 'hi', 'हिन्दी'),
235 'hr-utf-8' => array('hr|croatian', 'croatian-utf-8', 'hr', 'Hrvatski'),
236 'hu-utf-8' => array('hu|hungarian', 'hungarian-utf-8', 'hu', 'Magyar'),
237 'id-utf-8' => array('id|indonesian', 'indonesian-utf-8', 'id', 'Bahasa Indonesia'),
238 'it-utf-8' => array('it|italian', 'italian-utf-8', 'it', 'Italiano'),
239 'ja-utf-8' => array('ja|japanese', 'japanese-utf-8', 'ja', '日本語'),
240 'ko-utf-8' => array('ko|korean', 'korean-utf-8', 'ko', '한국어'),
241 'ka-utf-8' => array('ka|georgian', 'georgian-utf-8', 'ka', 'ქართული'),
242 'lt-utf-8' => array('lt|lithuanian', 'lithuanian-utf-8', 'lt', 'Lietuvių'),
243 'lv-utf-8' => array('lv|latvian', 'latvian-utf-8', 'lv', 'Latviešu'),
244 'mkcyr-utf-8' => array('mk|macedonian', 'macedonian_cyrillic-utf-8', 'mk', 'Macedonian'),
245 'mn-utf-8' => array('mn|mongolian', 'mongolian-utf-8', 'mn', 'Монгол'),
246 'ms-utf-8' => array('ms|malay', 'malay-utf-8', 'ms', 'Bahasa Melayu'),
247 'nl-utf-8' => array('nl|dutch', 'dutch-utf-8', 'nl', 'Nederlands'),
248 'no-utf-8' => array('no|norwegian', 'norwegian-utf-8', 'no', 'Norsk'),
249 'pl-utf-8' => array('pl|polish', 'polish-utf-8', 'pl', 'Polski'),
250 'ptbr-utf-8' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR', 'Português'),
251 'pt-utf-8' => array('pt|portuguese', 'portuguese-utf-8', 'pt', 'Português'),
252 'ro-utf-8' => array('ro|romanian', 'romanian-utf-8', 'ro', 'Română'),
253 'ru-utf-8' => array('ru|russian', 'russian-utf-8', 'ru', 'Русский'),
254 'si-utf-8' => array('si|sinhala', 'sinhala-utf-8', 'si', 'සිංහල'),
255 'sk-utf-8' => array('sk|slovak', 'slovak-utf-8', 'sk', 'Slovenčina'),
256 'sl-utf-8' => array('sl|slovenian', 'slovenian-utf-8', 'sl', 'Slovenščina'),
257 'sq-utf-8' => array('sq|albanian', 'albanian-utf-8', 'sq', 'Shqip'),
258 'srlat-utf-8' => array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat', 'Srpski'),
259 'srcyr-utf-8' => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr', 'Српски'),
260 'sv-utf-8' => array('sv|swedish', 'swedish-utf-8', 'sv', 'Svenska'),
261 'th-utf-8' => array('th|thai', 'thai-utf-8', 'th', 'ภาษาไทย'),
262 'tr-utf-8' => array('tr|turkish', 'turkish-utf-8', 'tr', 'Türkçe'),
263 'tt-utf-8' => array('tt|tatarish', 'tatarish-utf-8', 'tt', 'Tatarça'),
264 'uk-utf-8' => array('uk|ukrainian', 'ukrainian-utf-8', 'uk', 'Українська'),
265 'zhtw-utf-8' => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-utf-8', 'zh-TW', '中文'),
266 'zh-utf-8' => array('zh|chinese simplified', 'chinese_simplified-utf-8', 'zh', '中文'),
269 // Language filtering support
270 if (! empty($GLOBALS['cfg']['FilterLanguages'])) {
272 foreach ($GLOBALS['available_languages'] as $key => $val) {
273 if (preg_match('@' . $GLOBALS['cfg']['FilterLanguages'] . '@', $key)) {
274 $new_lang[$key] = $val;
277 if (count($new_lang) > 0) {
278 $GLOBALS['available_languages'] = $new_lang;
280 unset($key, $val, $new_lang);
284 * first check for lang dir exists
286 if (! is_dir($GLOBALS['lang_path'])) {
287 // language directory not found
288 trigger_error('phpMyAdmin-ERROR: path not found: '
289 . $GLOBALS['lang_path'] . ', check your language directory.',
292 PMA_fatalError('path to languages is invalid: ' . $GLOBALS['lang_path']);
296 * check for language files
298 foreach ($GLOBALS['available_languages'] as $each_lang_key => $each_lang) {
299 if (! file_exists($GLOBALS['lang_path'] . $each_lang[1] . '.inc.php')) {
300 unset($GLOBALS['available_languages'][$each_lang_key]);
303 unset($each_lang_key, $each_lang);
306 * @global array MySQL charsets map
308 $GLOBALS['mysql_charset_map'] = array(
313 'gb2312' => 'gb2312',
315 'iso-8859-1' => 'latin1',
316 'iso-8859-2' => 'latin2',
317 'iso-8859-7' => 'greek',
318 'iso-8859-8' => 'hebrew',
319 'iso-8859-8-i' => 'hebrew',
320 'iso-8859-9' => 'latin5',
321 'iso-8859-13' => 'latin7',
322 'iso-8859-15' => 'latin1',
324 'shift_jis' => 'sjis',
325 'tis-620' => 'tis620',
327 'windows-1250' => 'cp1250',
328 'windows-1251' => 'cp1251',
329 'windows-1252' => 'latin1',
330 'windows-1256' => 'cp1256',
331 'windows-1257' => 'cp1257',
339 * @global boolean whether charset recoding should be allowed or not
341 $GLOBALS['allow_recoding'] = false;
342 if (empty($GLOBALS['convcharset'])) {
343 if (isset($_COOKIE['pma_charset'])) {
344 $GLOBALS['convcharset'] = $_COOKIE['pma_charset'];
346 // session.save_path might point to a bad folder, in which case
347 // $GLOBALS['cfg'] would not exist
348 $GLOBALS['convcharset'] = isset($GLOBALS['cfg']['DefaultCharset']) ?
$GLOBALS['cfg']['DefaultCharset'] : 'utf-8';
352 if (! PMA_langCheck()) {
354 $fall_back_lang = 'en-utf-8';
356 if (! PMA_langSet($fall_back_lang)) {
357 trigger_error('phpMyAdmin-ERROR: invalid lang code: '
358 . __FILE__
. '#' . $line . ', check hard coded fall back language.',
361 // and tell the user that his choosen language is invalid
362 PMA_fatalError('Could not load any language, please check your language settings and folder.');
366 // Defines the associated filename and load the translation
367 $lang_file = $GLOBALS['lang_path'] . $GLOBALS['available_languages'][$GLOBALS['lang']][1] . '.inc.php';
368 require_once $lang_file;
370 // now, that we have loaded the language strings we can send the errors
371 if ($GLOBALS['lang_failed_cfg']) {
373 sprintf($GLOBALS['strLanguageUnknown'],
374 htmlspecialchars($GLOBALS['lang_failed_cfg'])),
377 if ($GLOBALS['lang_failed_cookie']) {
379 sprintf($GLOBALS['strLanguageUnknown'],
380 htmlspecialchars($GLOBALS['lang_failed_cookie'])),
383 if ($GLOBALS['lang_failed_request']) {
385 sprintf($GLOBALS['strLanguageUnknown'],
386 htmlspecialchars($GLOBALS['lang_failed_request'])),
390 unset($line, $fall_back_lang,
391 $GLOBALS['lang_failed_cfg'], $GLOBALS['lang_failed_cookie'], $GLOBALS['ang_failed_request'], $GLOBALS['strLanguageUnknown']);