Convert Excel column name correctly
[phpmyadmin/arisferyanto.git] / libraries / select_lang.lib.php
blob5e5762a54dcbf71732cfc30fc5f869e8b3742181
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * phpMyAdmin Language Loading File
6 * @version $Id$
7 * @package phpMyAdmin
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
14 * tries to find the language to use
16 * @uses $GLOBALS['cfg']['lang']
17 * @uses $GLOBALS['cfg']['DefaultLang']
18 * @uses $GLOBALS['lang_failed_cfg']
19 * @uses $GLOBALS['lang_failed_cookie']
20 * @uses $GLOBALS['lang_failed_request']
21 * @uses $GLOBALS['convcharset'] to set it if not set
22 * @uses $_REQUEST['lang']
23 * @uses $_COOKIE['pma_lang']
24 * @uses $_SERVER['HTTP_ACCEPT_LANGUAGE']
25 * @uses $_SERVER['HTTP_USER_AGENT']
26 * @uses PMA_langSet()
27 * @uses PMA_langDetect()
28 * @uses explode()
29 * @return bool success if valid lang is found, otherwise false
31 function PMA_langCheck()
33 // check forced language
34 if (! empty($GLOBALS['cfg']['Lang'])) {
35 if (PMA_langSet($GLOBALS['cfg']['Lang'])) {
36 return true;
37 } else {
38 $GLOBALS['lang_failed_cfg'] = $GLOBALS['cfg']['Lang'];
42 // Don't use REQUEST in following code as it might be confused by cookies with same name
43 // check user requested language (POST)
44 if (! empty($_POST['lang'])) {
45 if (PMA_langSet($_POST['lang'])) {
46 return true;
47 } elseif (!is_string($_POST['lang'])) {
48 /* Faked request, don't care on localisation */
49 $GLOBALS['lang_failed_request'] = 'Yes';
50 } else {
51 $GLOBALS['lang_failed_request'] = $_POST['lang'];
55 // check user requested language (GET)
56 if (! empty($_GET['lang'])) {
57 if (PMA_langSet($_GET['lang'])) {
58 return true;
59 } elseif (!is_string($_GET['lang'])) {
60 /* Faked request, don't care on localisation */
61 $GLOBALS['lang_failed_request'] = 'Yes';
62 } else {
63 $GLOBALS['lang_failed_request'] = $_GET['lang'];
67 // check previous set language
68 if (! empty($_COOKIE['pma_lang'])) {
69 if (PMA_langSet($_COOKIE['pma_lang'])) {
70 return true;
71 } elseif (!is_string($_COOKIE['pma_lang'])) {
72 /* Faked request, don't care on localisation */
73 $GLOBALS['lang_failed_cookie'] = 'Yes';
74 } else {
75 $GLOBALS['lang_failed_cookie'] = $_COOKIE['pma_lang'];
79 // try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE variable
80 if (PMA_getenv('HTTP_ACCEPT_LANGUAGE')) {
81 foreach (explode(',', PMA_getenv('HTTP_ACCEPT_LANGUAGE')) as $lang) {
82 if (PMA_langDetect($lang, 1)) {
83 return true;
88 // try to findout user's language by checking its HTTP_USER_AGENT variable
89 if (PMA_langDetect(PMA_getenv('HTTP_USER_AGENT'), 2)) {
90 return true;
93 // Didn't catch any valid lang : we use the default settings
94 if (PMA_langSet($GLOBALS['cfg']['DefaultLang'])) {
95 return true;
98 return false;
102 * checks given lang and sets it if valid
103 * returns true on success, otherwise flase
105 * @uses $GLOBALS['available_languages'] to check $lang
106 * @uses $GLOBALS['lang'] to set it
107 * @param string $lang language to set
108 * @return bool success
110 function PMA_langSet(&$lang)
112 if (!is_string($lang) || empty($lang) || empty($GLOBALS['available_languages'][$lang])) {
113 return false;
115 $GLOBALS['lang'] = $lang;
116 return true;
120 * Analyzes some PHP environment variables to find the most probable language
121 * that should be used
123 * @param string string to analyze
124 * @param integer type of the PHP environment variable which value is $str
126 * @return bool true on success, otherwise false
128 * @global array $available_languages
130 * @access private
132 function PMA_langDetect($str, $envType)
134 if (empty($str)) {
135 return false;
137 if (empty($GLOBALS['available_languages'])) {
138 return false;
141 foreach ($GLOBALS['available_languages'] as $lang => $value) {
142 // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
143 // 2 for the 'HTTP_USER_AGENT' one
144 $expr = $value[0];
145 if (strpos($expr, '[-_]') === FALSE) {
146 $expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr);
148 if (($envType == 1 && preg_match('/^(' . addcslashes($expr,'/') . ')(;q=[0-9]\\.[0-9])?$/i', $str))
149 || ($envType == 2 && preg_match('/(\(|\[|;[[:space:]])(' . addcslashes($expr,'/') . ')(;|\]|\))/i', $str))) {
150 if (PMA_langSet($lang)) {
151 return true;
156 return false;
157 } // end of the 'PMA_langDetect()' function
160 * Returns list of languages supported by phpMyAdmin
162 * @return array
164 function PMA_langList()
167 * All the supported languages have to be listed in the array below.
168 * 1. The key must be the "official" ISO 639 language code and, if required,
169 * the dialect code. It can also contain some information about the
170 * charset (see the Russian case).
171 * 2. The first of the values associated to the key is used in a regular
172 * expression to find some keywords corresponding to the language inside two
173 * environment variables.
174 * These values contain:
175 * - the "official" ISO language code and, if required, the dialect code
176 * too ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
177 * dialects, 'zh[-_]tw' for Chinese traditional...), the dialect has to
178 * be specified first;
179 * - the '|' character (it means 'OR');
180 * - the full language name.
181 * 3. The second value associated to the key is the name of the file to load
182 * without the 'inc.php' extension.
183 * 4. The third value associated to the key is the language code as defined by
184 * the RFC1766.
185 * 5. The fourth value is its native name in html entities.
187 * Beware that the sorting order (first values associated to keys by
188 * alphabetical reverse order in the array) is important: 'zh-tw' (chinese
189 * traditional) must be detected before 'zh' (chinese simplified) for
190 * example.
193 return array(
194 'af-utf-8' => array('af|afrikaans', 'afrikaans-utf-8', 'af', ''),
195 'ar-utf-8' => array('ar|arabic', 'arabic-utf-8', 'ar', '&#1575;&#1604;&#1593;&#1585;&#1576;&#1610;&#1577;'),
196 'az-utf-8' => array('az|azerbaijani', 'azerbaijani-utf-8', 'az', 'Az&#601;rbaycanca'),
197 'bn-utf-8' => array('bn|bangla', 'bangla-utf-8', 'bn', ''),
198 'becyr-utf-8' => array('be|belarusian', 'belarusian_cyrillic-utf-8', 'be', '&#1041;&#1077;&#1083;&#1072;&#1088;&#1091;&#1089;&#1082;&#1072;&#1103;'),
199 'belat-utf-8' => array('be[-_]lat|belarusian latin', 'belarusian_latin-utf-8', 'be-lat', 'Bie&#0322;aruskaja'),
200 'bg-utf-8' => array('bg|bulgarian', 'bulgarian-utf-8', 'bg', '&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;'),
201 'bs-utf-8' => array('bs|bosnian', 'bosnian-utf-8', 'bs', 'Bosanski'),
202 'ca-utf-8' => array('ca|catalan', 'catalan-utf-8', 'ca', 'Catal&agrave;'),
203 'cs-utf-8' => array('cs|czech', 'czech-utf-8', 'cs', '&#268;esky'),
204 'da-utf-8' => array('da|danish', 'danish-utf-8', 'da', 'Dansk'),
205 'de-utf-8' => array('de|german', 'german-utf-8', 'de', 'Deutsch'),
206 'el-utf-8' => array('el|greek', 'greek-utf-8', 'el', '&Epsilon;&lambda;&lambda;&eta;&nu;&iota;&kappa;&#940;'),
207 'en-utf-8' => array('en|english', 'english-utf-8', 'en', ''),
208 'es-utf-8' => array('es|spanish', 'spanish-utf-8', 'es', 'Espa&ntilde;ol'),
209 'et-utf-8' => array('et|estonian', 'estonian-utf-8', 'et', 'Eesti'),
210 'eu-utf-8' => array('eu|basque', 'basque-utf-8', 'eu', 'Euskara'),
211 'fa-utf-8' => array('fa|persian', 'persian-utf-8', 'fa', '&#1601;&#1575;&#1585;&#1587;&#1740;'),
212 'fi-utf-8' => array('fi|finnish', 'finnish-utf-8', 'fi', 'Suomi'),
213 'fr-utf-8' => array('fr|french', 'french-utf-8', 'fr', 'Fran&ccedil;ais'),
214 'gl-utf-8' => array('gl|galician', 'galician-utf-8', 'gl', 'Galego'),
215 'he-utf-8' => array('he|hebrew', 'hebrew-utf-8', 'he', '&#1506;&#1489;&#1512;&#1497;&#1514;'),
216 'hi-utf-8' => array('hi|hindi', 'hindi-utf-8', 'hi', '&#2361;&#2367;&#2344;&#2381;&#2342;&#2368;'),
217 'hr-utf-8' => array('hr|croatian', 'croatian-utf-8', 'hr', 'Hrvatski'),
218 'hu-utf-8' => array('hu|hungarian', 'hungarian-utf-8', 'hu', 'Magyar'),
219 'id-utf-8' => array('id|indonesian', 'indonesian-utf-8', 'id', 'Bahasa Indonesia'),
220 'it-utf-8' => array('it|italian', 'italian-utf-8', 'it', 'Italiano'),
221 'ja-utf-8' => array('ja|japanese', 'japanese-utf-8', 'ja', '&#26085;&#26412;&#35486;'),
222 'ko-utf-8' => array('ko|korean', 'korean-utf-8', 'ko', '&#54620;&#44397;&#50612;'),
223 'ka-utf-8' => array('ka|georgian', 'georgian-utf-8', 'ka', '&#4325;&#4304;&#4320;&#4311;&#4323;&#4314;&#4312;'),
224 'lt-utf-8' => array('lt|lithuanian', 'lithuanian-utf-8', 'lt', 'Lietuvi&#371;'),
225 'lv-utf-8' => array('lv|latvian', 'latvian-utf-8', 'lv', 'Latvie&scaron;u'),
226 'mkcyr-utf-8' => array('mk|macedonian', 'macedonian_cyrillic-utf-8', 'mk', 'Macedonian'),
227 'mn-utf-8' => array('mn|mongolian', 'mongolian-utf-8', 'mn', '&#1052;&#1086;&#1085;&#1075;&#1086;&#1083;'),
228 'ms-utf-8' => array('ms|malay', 'malay-utf-8', 'ms', 'Bahasa Melayu'),
229 'nl-utf-8' => array('nl|dutch', 'dutch-utf-8', 'nl', 'Nederlands'),
230 'no-utf-8' => array('no|norwegian', 'norwegian-utf-8', 'no', 'Norsk'),
231 'pl-utf-8' => array('pl|polish', 'polish-utf-8', 'pl', 'Polski'),
232 'ptbr-utf-8' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR', 'Portugu&ecirc;s'),
233 'pt-utf-8' => array('pt|portuguese', 'portuguese-utf-8', 'pt', 'Portugu&ecirc;s'),
234 'ro-utf-8' => array('ro|romanian', 'romanian-utf-8', 'ro', 'Rom&acirc;n&#259;'),
235 'ru-utf-8' => array('ru|russian', 'russian-utf-8', 'ru', '&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;'),
236 'si-utf-8' => array('si|sinhala', 'sinhala-utf-8', 'si', '&#3523;&#3538;&#3458;&#3524;&#3517;'),
237 'sk-utf-8' => array('sk|slovak', 'slovak-utf-8', 'sk', 'Sloven&#269;ina'),
238 'sl-utf-8' => array('sl|slovenian', 'slovenian-utf-8', 'sl', 'Sloven&scaron;&#269;ina'),
239 'sq-utf-8' => array('sq|albanian', 'albanian-utf-8', 'sq', 'Shqip'),
240 'srlat-utf-8' => array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat', 'Srpski'),
241 'srcyr-utf-8' => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr', '&#1057;&#1088;&#1087;&#1089;&#1082;&#1080;'),
242 'sv-utf-8' => array('sv|swedish', 'swedish-utf-8', 'sv', 'Svenska'),
243 'th-utf-8' => array('th|thai', 'thai-utf-8', 'th', '&#3616;&#3634;&#3625;&#3634;&#3652;&#3607;&#3618;'),
244 'tr-utf-8' => array('tr|turkish', 'turkish-utf-8', 'tr', 'T&uuml;rk&ccedil;e'),
245 'tt-utf-8' => array('tt|tatarish', 'tatarish-utf-8', 'tt', 'Tatar&ccedil;a'),
246 'uk-utf-8' => array('uk|ukrainian', 'ukrainian-utf-8', 'uk', '&#1059;&#1082;&#1088;&#1072;&#1111;&#1085;&#1089;&#1100;&#1082;&#1072;'),
247 'uzlat-utf-8' => array('uz[-_]lat|uzbek-latin', 'uzbek_latin-utf-8', 'uz-lat', 'O&lsquo;zbekcha'),
248 'uzcyr-utf-8' => array('uz[-_]cyr|uzbek-cyrillic', 'uzbek_cyrillic-utf-8', 'uz-cyr', '&#1038;&#1079;&#1073;&#1077;&#1082;&#1095;&#1072;'),
249 'zhtw-utf-8' => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-utf-8', 'zh-TW', '&#20013;&#25991;'),
250 'zh-utf-8' => array('zh|chinese simplified', 'chinese_simplified-utf-8', 'zh', '&#20013;&#25991;'),
255 * @global string path to the translations directory
257 $GLOBALS['lang_path'] = './lang/';
260 * @global string interface language
262 $GLOBALS['lang'] = 'en-utf-8';
264 * @global boolean whether loading lang from cfg failed
266 $GLOBALS['lang_failed_cfg'] = false;
268 * @global boolean whether loading lang from cookie failed
270 $GLOBALS['lang_failed_cookie'] = false;
272 * @global boolean whether loading lang from user request failed
274 $GLOBALS['lang_failed_request'] = false;
276 * @global string text direction ltr or rtl
278 $GLOBALS['text_dir'] = 'ltr';
281 * @global array supported languages
283 $GLOBALS['available_languages'] = PMA_langList();
285 // Language filtering support
286 if (! empty($GLOBALS['cfg']['FilterLanguages'])) {
287 $new_lang = array();
288 foreach ($GLOBALS['available_languages'] as $key => $val) {
289 if (preg_match('@' . $GLOBALS['cfg']['FilterLanguages'] . '@', $key)) {
290 $new_lang[$key] = $val;
293 if (count($new_lang) > 0) {
294 $GLOBALS['available_languages'] = $new_lang;
296 unset($key, $val, $new_lang);
300 * first check for lang dir exists
302 if (! is_dir($GLOBALS['lang_path'])) {
303 // language directory not found
304 trigger_error('phpMyAdmin-ERROR: path not found: '
305 . $GLOBALS['lang_path'] . ', check your language directory.',
306 E_USER_WARNING);
307 // and tell the user
308 PMA_fatalError('path to languages is invalid: ' . $GLOBALS['lang_path']);
312 * check for language files
314 foreach ($GLOBALS['available_languages'] as $each_lang_key => $each_lang) {
315 if (! file_exists($GLOBALS['lang_path'] . $each_lang[1] . '.inc.php')) {
316 unset($GLOBALS['available_languages'][$each_lang_key]);
319 unset($each_lang_key, $each_lang);
322 * @global array MySQL charsets map
324 $GLOBALS['mysql_charset_map'] = array(
325 'big5' => 'big5',
326 'cp-866' => 'cp866',
327 'euc-jp' => 'ujis',
328 'euc-kr' => 'euckr',
329 'gb2312' => 'gb2312',
330 'gbk' => 'gbk',
331 'iso-8859-1' => 'latin1',
332 'iso-8859-2' => 'latin2',
333 'iso-8859-7' => 'greek',
334 'iso-8859-8' => 'hebrew',
335 'iso-8859-8-i' => 'hebrew',
336 'iso-8859-9' => 'latin5',
337 'iso-8859-13' => 'latin7',
338 'iso-8859-15' => 'latin1',
339 'koi8-r' => 'koi8r',
340 'shift_jis' => 'sjis',
341 'tis-620' => 'tis620',
342 'utf-8' => 'utf8',
343 'windows-1250' => 'cp1250',
344 'windows-1251' => 'cp1251',
345 'windows-1252' => 'latin1',
346 'windows-1256' => 'cp1256',
347 'windows-1257' => 'cp1257',
351 * Do the work!
354 if (empty($GLOBALS['convcharset'])) {
355 if (isset($_COOKIE['pma_charset'])) {
356 $GLOBALS['convcharset'] = $_COOKIE['pma_charset'];
357 } else {
358 // session.save_path might point to a bad folder, in which case
359 // $GLOBALS['cfg'] would not exist
360 $GLOBALS['convcharset'] = isset($GLOBALS['cfg']['DefaultCharset']) ? $GLOBALS['cfg']['DefaultCharset'] : 'utf-8';
364 if (! PMA_langCheck()) {
365 // fallback language
366 $fall_back_lang = 'en-utf-8';
367 $line = __LINE__;
368 if (! PMA_langSet($fall_back_lang)) {
369 trigger_error('phpMyAdmin-ERROR: invalid lang code: '
370 . __FILE__ . '#' . $line . ', check hard coded fall back language.',
371 E_USER_WARNING);
372 // stop execution
373 // and tell the user that his choosen language is invalid
374 PMA_fatalError('Could not load any language, please check your language settings and folder.');
378 // Defines the associated filename and load the translation
379 $lang_file = $GLOBALS['lang_path'] . $GLOBALS['available_languages'][$GLOBALS['lang']][1] . '.inc.php';
380 require_once $lang_file;
382 // now, that we have loaded the language strings we can send the errors
383 if ($GLOBALS['lang_failed_cfg']) {
384 trigger_error(
385 sprintf($GLOBALS['strLanguageUnknown'],
386 htmlspecialchars($GLOBALS['lang_failed_cfg'])),
387 E_USER_ERROR);
389 if ($GLOBALS['lang_failed_cookie']) {
390 trigger_error(
391 sprintf($GLOBALS['strLanguageUnknown'],
392 htmlspecialchars($GLOBALS['lang_failed_cookie'])),
393 E_USER_ERROR);
395 if ($GLOBALS['lang_failed_request']) {
396 trigger_error(
397 sprintf($GLOBALS['strLanguageUnknown'],
398 htmlspecialchars($GLOBALS['lang_failed_request'])),
399 E_USER_ERROR);
402 unset($line, $fall_back_lang,
403 $GLOBALS['lang_failed_cfg'], $GLOBALS['lang_failed_cookie'], $GLOBALS['ang_failed_request'], $GLOBALS['strLanguageUnknown']);