home *** CD-ROM | disk | FTP | other *** search
/ Freelog 70 / Freelog070.iso / Internet / EasyPHP / easyphp1-8_setup.exe / {app} / phpmyadmin / libraries / select_lang.lib.php < prev    next >
Encoding:
PHP Script  |  2004-10-12  |  14.1 KB  |  313 lines

  1. <?php
  2. /* $Id: select_lang.lib.php,v 2.14 2004/10/12 21:29:07 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * phpMyAdmin Language Loading File
  8.  */
  9.  
  10.  
  11. /**
  12.  * We need some elements of the superglobal $_SERVER array.
  13.  */
  14. require_once('./libraries/grab_globals.lib.php');
  15.  
  16.  
  17. /**
  18.  * Define the path to the translations directory and get some variables
  19.  * from system arrays if 'register_globals' is set to 'off'
  20.  */
  21. $lang_path = 'lang/';
  22.  
  23.  
  24. /**
  25.  * All the supported languages have to be listed in the array below.
  26.  * 1. The key must be the "official" ISO 639 language code and, if required,
  27.  *    the dialect code. It can also contain some informations about the
  28.  *    charset (see the Russian case).
  29.  * 2. The first of the values associated to the key is used in a regular
  30.  *    expression to find some keywords corresponding to the language inside two
  31.  *    environment variables.
  32.  *    These values contains:
  33.  *    - the "official" ISO language code and, if required, the dialect code
  34.  *      also ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
  35.  *      dialects, 'zh[-_]tw' for Chinese traditional...), the dialect has to 
  36.  *      be specified as first;
  37.  *    - the '|' character (it means 'OR');
  38.  *    - the full language name.
  39.  * 3. The second values associated to the key is the name of the file to load
  40.  *    without the 'inc.php' extension.
  41.  * 4. The last values associated to the key is the language code as defined by
  42.  *    the RFC1766.
  43.  *
  44.  * Beware that the sorting order (first values associated to keys by
  45.  * alphabetical reverse order in the array) is important: 'zh-tw' (chinese
  46.  * traditional) must be detected before 'zh' (chinese simplified) for
  47.  * example.
  48.  *
  49.  * When there are more than one charset for a language, we put the -utf-8
  50.  * last because we need the default charset to be non-utf-8 to avoid
  51.  * problems on MySQL < 4.1.x if AllowAnywhereRecoding is FALSE.
  52.  *
  53.  * For Russian, we put 1251 first, because MSIE does not accept 866
  54.  * and users would not see anything.
  55.  */
  56. $available_languages = array(
  57.     'af-iso-8859-1'     => array('af|afrikaans', 'afrikaans-iso-8859-1', 'af'),
  58.     'af-utf-8'          => array('af|afrikaans', 'afrikaans-utf-8', 'af'),
  59.     'ar-win1256'        => array('ar|arabic', 'arabic-windows-1256', 'ar'),
  60.     'ar-utf-8'          => array('ar|arabic', 'arabic-utf-8', 'ar'),
  61.     'az-iso-8859-9'     => array('az|azerbaijani', 'azerbaijani-iso-8859-9', 'az'),
  62.     'az-utf-8'          => array('az|azerbaijani', 'azerbaijani-utf-8', 'az'),
  63.     'bg-win1251'        => array('bg|bulgarian', 'bulgarian-windows-1251', 'bg'),
  64.     'bg-koi8-r'         => array('bg|bulgarian', 'bulgarian-koi8-r', 'bg'),
  65.     'bg-utf-8'          => array('bg|bulgarian', 'bulgarian-utf-8', 'bg'),
  66.     'bs-win1250'        => array('bs|bosnian', 'bosnian-windows-1250', 'bs'),
  67.     'bs-utf-8'          => array('bs|bosnian', 'bosnian-utf-8', 'bs'),
  68.     'ca-iso-8859-1'     => array('ca|catalan', 'catalan-iso-8859-1', 'ca'),
  69.     'ca-utf-8'          => array('ca|catalan', 'catalan-utf-8', 'ca'),
  70.     'cs-iso-8859-2'     => array('cs|czech', 'czech-iso-8859-2', 'cs'),
  71.     'cs-win1250'        => array('cs|czech', 'czech-windows-1250', 'cs'),
  72.     'cs-utf-8'          => array('cs|czech', 'czech-utf-8', 'cs'),
  73.     'da-iso-8859-1'     => array('da|danish', 'danish-iso-8859-1', 'da'),
  74.     'da-utf-8'          => array('da|danish', 'danish-utf-8', 'da'),
  75.     'de-iso-8859-1'     => array('de|german', 'german-iso-8859-1', 'de'),
  76.     'de-utf-8'          => array('de|german', 'german-utf-8', 'de'),
  77.     'el-iso-8859-7'     => array('el|greek',  'greek-iso-8859-7', 'el'),
  78.     'el-utf-8'          => array('el|greek',  'greek-utf-8', 'el'),
  79.     'en-iso-8859-1'     => array('en|english',  'english-iso-8859-1', 'en'),
  80.     'en-utf-8'          => array('en|english',  'english-utf-8', 'en'),
  81.     'es-iso-8859-1'     => array('es|spanish', 'spanish-iso-8859-1', 'es'),
  82.     'es-utf-8'          => array('es|spanish', 'spanish-utf-8', 'es'),
  83.     'et-iso-8859-1'     => array('et|estonian', 'estonian-iso-8859-1', 'et'),
  84.     'et-utf-8'          => array('et|estonian', 'estonian-utf-8', 'et'),
  85.     'eu-iso-8859-1'     => array('eu|basque', 'basque-iso-8859-1', 'eu'),
  86.     'eu-utf-8'          => array('eu|basque', 'basque-utf-8', 'eu'),
  87.     'fa-win1256'        => array('fa|persian', 'persian-windows-1256', 'fa'),
  88.     'fa-utf-8'          => array('fa|persian', 'persian-utf-8', 'fa'),
  89.     'fi-iso-8859-1'     => array('fi|finnish', 'finnish-iso-8859-1', 'fi'),
  90.     'fi-utf-8'          => array('fi|finnish', 'finnish-utf-8', 'fi'),
  91.     'fr-iso-8859-1'     => array('fr|french', 'french-iso-8859-1', 'fr'),
  92.     'fr-utf-8'          => array('fr|french', 'french-utf-8', 'fr'),
  93.     'gl-iso-8859-1'     => array('gl|galician', 'galician-iso-8859-1', 'gl'),
  94.     'gl-utf-8'          => array('gl|galician', 'galician-utf-8', 'gl'),
  95.     'he-iso-8859-8-i'   => array('he|hebrew', 'hebrew-iso-8859-8-i', 'he'),
  96.     'he-utf-8'          => array('he|hebrew', 'hebrew-utf-8', 'he'),
  97.     'hi-utf-8'          => array('hi|hindi', 'hindi-utf-8', 'hi'),
  98.     'hr-win1250'        => array('hr|croatian', 'croatian-windows-1250', 'hr'),
  99.     'hr-iso-8859-2'     => array('hr|croatian', 'croatian-iso-8859-2', 'hr'),
  100.     'hr-utf-8'          => array('hr|croatian', 'croatian-utf-8', 'hr'),
  101.     'hu-iso-8859-2'     => array('hu|hungarian', 'hungarian-iso-8859-2', 'hu'),
  102.     'hu-utf-8'          => array('hu|hungarian', 'hungarian-utf-8', 'hu'),
  103.     'id-iso-8859-1'     => array('id|indonesian', 'indonesian-iso-8859-1', 'id'),
  104.     'id-utf-8'          => array('id|indonesian', 'indonesian-utf-8', 'id'),
  105.     'it-iso-8859-1'     => array('it|italian', 'italian-iso-8859-1', 'it'),
  106.     'it-utf-8'          => array('it|italian', 'italian-utf-8', 'it'),
  107.     'ja-euc'            => array('ja|japanese', 'japanese-euc', 'ja'),
  108.     'ja-sjis'           => array('ja|japanese', 'japanese-sjis', 'ja'),
  109.     'ja-utf-8'          => array('ja|japanese', 'japanese-utf-8', 'ja'),
  110.     'ko-euc-kr'         => array('ko|korean', 'korean-euc-kr', 'ko'),
  111.     'ko-utf-8'          => array('ko|korean', 'korean-utf-8', 'ko'),
  112.     'ka-utf-8'          => array('ka|georgian', 'georgian-utf-8', 'ka'),
  113.     'lt-win1257'        => array('lt|lithuanian', 'lithuanian-windows-1257', 'lt'),
  114.     'lt-utf-8'          => array('lt|lithuanian', 'lithuanian-utf-8', 'lt'),
  115.     'lv-win1257'        => array('lv|latvian', 'latvian-windows-1257', 'lv'),
  116.     'lv-utf-8'          => array('lv|latvian', 'latvian-utf-8', 'lv'),
  117.     'ms-iso-8859-1'     => array('ms|malay', 'malay-iso-8859-1', 'ms'),
  118.     'ms-utf-8'          => array('ms|malay', 'malay-utf-8', 'ms'),
  119.     'nl-iso-8859-1'     => array('nl|dutch', 'dutch-iso-8859-1', 'nl'),
  120.     'nl-utf-8'          => array('nl|dutch', 'dutch-utf-8', 'nl'),
  121.     'no-iso-8859-1'     => array('no|norwegian', 'norwegian-iso-8859-1', 'no'),
  122.     'no-utf-8'          => array('no|norwegian', 'norwegian-utf-8', 'no'),
  123.     'pl-iso-8859-2'     => array('pl|polish', 'polish-iso-8859-2', 'pl'),
  124.     'pl-utf-8'          => array('pl|polish', 'polish-utf-8', 'pl'),
  125.     'ptbr-iso-8859-1'   => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-iso-8859-1', 'pt-BR'),
  126.     'ptbr-utf-8'        => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR'),
  127.     'pt-iso-8859-1'     => array('pt|portuguese', 'portuguese-iso-8859-1', 'pt'),
  128.     'pt-utf-8'          => array('pt|portuguese', 'portuguese-utf-8', 'pt'),
  129.     'ro-iso-8859-1'     => array('ro|romanian', 'romanian-iso-8859-1', 'ro'),
  130.     'ro-utf-8'          => array('ro|romanian', 'romanian-utf-8', 'ro'),
  131.     'ru-win1251'        => array('ru|russian', 'russian-windows-1251', 'ru'),
  132.     'ru-cp-866'         => array('ru|russian', 'russian-cp-866', 'ru'),
  133.     'ru-koi8-r'         => array('ru|russian', 'russian-koi8-r', 'ru'),
  134.     'ru-utf-8'          => array('ru|russian', 'russian-utf-8', 'ru'),
  135.     'sk-iso-8859-2'     => array('sk|slovak', 'slovak-iso-8859-2', 'sk'),
  136.     'sk-win1250'        => array('sk|slovak', 'slovak-windows-1250', 'sk'),
  137.     'sk-utf-8'          => array('sk|slovak', 'slovak-utf-8', 'sk'),
  138.     'sl-iso-8859-2'     => array('sl|slovenian', 'slovenian-iso-8859-2', 'sl'),
  139.     'sl-win1250'        => array('sl|slovenian', 'slovenian-windows-1250', 'sl'),
  140.     'sl-utf-8'          => array('sl|slovenian', 'slovenian-utf-8', 'sl'),
  141.     'sq-iso-8859-1'     => array('sq|albanian', 'albanian-iso-8859-1', 'sq'),
  142.     'sq-utf-8'          => array('sq|albanian', 'albanian-utf-8', 'sq'),
  143.     'srlat-win1250'     => array('sr[-_]lat|serbian latin', 'serbian_latin-windows-1250', 'sr-lat'),
  144.     'srlat-utf-8'       => array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat'),
  145.     'srcyr-win1251'     => array('sr|serbian', 'serbian_cyrillic-windows-1251', 'sr'),
  146.     'srcyr-utf-8'       => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr'),
  147.     'sv-iso-8859-1'     => array('sv|swedish', 'swedish-iso-8859-1', 'sv'),
  148.     'sv-utf-8'          => array('sv|swedish', 'swedish-utf-8', 'sv'),
  149.     'th-tis-620'        => array('th|thai', 'thai-tis-620', 'th'),
  150.     'th-utf-8'          => array('th|thai', 'thai-utf-8', 'th'),
  151.     'tr-iso-8859-9'     => array('tr|turkish', 'turkish-iso-8859-9', 'tr'),
  152.     'tr-utf-8'          => array('tr|turkish', 'turkish-utf-8', 'tr'),
  153.     'uk-win1251'        => array('uk|ukrainian', 'ukrainian-windows-1251', 'uk'),
  154.     'uk-utf-8'          => array('uk|ukrainian', 'ukrainian-utf-8', 'uk'),
  155.     'zhtw-big5'         => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-big5', 'zh-TW'),
  156.     'zhtw-utf-8'        => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-utf-8', 'zh-TW'),
  157.     'zh-gb2312'         => array('zh|chinese simplified', 'chinese_simplified-gb2312', 'zh'),
  158.     'zh-utf-8'          => array('zh|chinese simplified', 'chinese_simplified-utf-8', 'zh')
  159. );
  160.  
  161.  
  162. /**
  163.  * Analyzes some PHP environment variables to find the most probable language
  164.  * that should be used
  165.  *
  166.  * @param   string   string to analyze
  167.  * @param   integer  type of the PHP environment variable which value is $str
  168.  *
  169.  * @global  array    the list of available translations
  170.  * @global  string   the retained translation keyword
  171.  *
  172.  * @access  private
  173.  */
  174. function PMA_langDetect($str = '', $envType = '')
  175. {
  176.     global $available_languages;
  177.     global $lang;
  178.  
  179.     foreach ($available_languages AS $key => $value) {
  180.         // $envType =  1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
  181.         //             2 for the 'HTTP_USER_AGENT' one
  182.         $expr = $value[0];
  183.         if (strpos($expr, '[-_]') === FALSE) {
  184.             $expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr);
  185.         }
  186.         if (($envType == 1 && eregi('^(' . $expr . ')(;q=[0-9]\\.[0-9])?$', $str))
  187.             || ($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $expr . ')(;|\]|\))', $str))) {
  188.             $lang     = $key;
  189.             break;
  190.         }
  191.     }
  192. } // end of the 'PMA_langDetect()' function
  193.  
  194.  
  195. if (!isset($lang)) {
  196.     if (isset($_GET) && !empty($_GET['lang'])) {
  197.         $lang = $_GET['lang'];
  198.     }
  199.     else if (isset($_POST) && !empty($_POST['lang'])) {
  200.         $lang = $_POST['lang'];
  201.     }
  202.     else if (isset($_COOKIE) && !empty($_COOKIE['pma_lang'])) {
  203.         $lang = $_COOKIE['pma_lang'];
  204.     }
  205. }
  206.  
  207.  
  208. /**
  209.  * Do the work!
  210.  */
  211.  
  212. // compatibility with config.inc.php <= v1.80
  213. if (!isset($cfg['Lang']) && isset($cfgLang)) {
  214.     $cfg['Lang']        = $cfgLang;
  215.     unset($cfgLang);
  216. }
  217. if (!isset($cfg['DefaultLang']) && isset($cfgDefaultLang)) {
  218.     $cfg['DefaultLang'] = $cfgDefaultLang;
  219.     unset($cfgLang);
  220. }
  221.  
  222. /**
  223.  *
  224.  * 2004-02-15 rabus: Deactivated the code temporarily:
  225.  *            We need to allow UTF-8 in order to be MySQL 4.1 compatible!
  226.  
  227. // Disable UTF-8 if $cfg['AllowAnywhereRecoding'] has been set to FALSE.
  228. if (!isset($cfg['AllowAnywhereRecoding']) || !$cfg['AllowAnywhereRecoding']) {
  229.     $available_language_files               = $available_languages;
  230.     $available_languages                    = array();
  231.     foreach ($available_language_files AS $tmp_lang => $tmp_lang_data) {
  232.         if (substr($tmp_lang, -5) != 'utf-8') {
  233.             $available_languages[$tmp_lang] = $tmp_lang_data;
  234.         }
  235.     } // end while
  236.     unset($tmp_lang, $tmp_lang_data, $available_language_files);
  237. } // end if
  238.  
  239.  *
  240.  */
  241.  
  242. // MySQL charsets map
  243. $mysql_charset_map = array(
  244.     'big5'         => 'big5',
  245.     'cp-866'       => 'cp866',
  246.     'euc-jp'       => 'ujis',
  247.     'euc-kr'       => 'euckr',
  248.     'gb2312'       => 'gb2312',
  249.     'gbk'          => 'gbk',
  250.     'iso-8859-1'   => 'latin1',
  251.     'iso-8859-2'   => 'latin2',
  252.     'iso-8859-7'   => 'greek',
  253.     'iso-8859-8'   => 'hebrew',
  254.     'iso-8859-8-i' => 'hebrew',
  255.     'iso-8859-9'   => 'latin5',
  256.     'iso-8859-13'  => 'latin7',
  257.     'iso-8859-15'  => 'latin1',
  258.     'koi8-r'       => 'koi8r',
  259.     'shift_jis'    => 'sjis',
  260.     'tis-620'      => 'tis620',
  261.     'utf-8'        => 'utf8',
  262.     'windows-1250' => 'cp1250',
  263.     'windows-1251' => 'cp1251',
  264.     'windows-1252' => 'latin1',
  265.     'windows-1256' => 'cp1256',
  266.     'windows-1257' => 'cp1257',
  267. );
  268.  
  269. // Lang forced
  270. if (!empty($cfg['Lang'])) {
  271.     $lang = $cfg['Lang'];
  272. }
  273.  
  274. // If '$lang' is defined, ensure this is a valid translation
  275. if (!empty($lang) && empty($available_languages[$lang])) {
  276.     $lang = '';
  277. }
  278.  
  279. // Language is not defined yet :
  280. // 1. try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE
  281. //    variable
  282. if (empty($lang) && !empty($HTTP_ACCEPT_LANGUAGE)) {
  283.     $accepted    = explode(',', $HTTP_ACCEPT_LANGUAGE);
  284.     $acceptedCnt = count($accepted);
  285.     for ($i = 0; $i < $acceptedCnt && empty($lang); $i++) {
  286.         PMA_langDetect($accepted[$i], 1);
  287.     }
  288. }
  289. // 2. try to findout user's language by checking its HTTP_USER_AGENT variable
  290. if (empty($lang) && !empty($HTTP_USER_AGENT)) {
  291.     PMA_langDetect($HTTP_USER_AGENT, 2);
  292. }
  293.  
  294. // 3. Didn't catch any valid lang : we use the default settings
  295. if (empty($lang)) {
  296.     $lang = $cfg['DefaultLang'];
  297. }
  298.  
  299. // 4. Checks whether charset recoding should be allowed or not
  300. $allow_recoding = FALSE; // Default fallback value
  301. if (!isset($convcharset) || empty($convcharset)) {
  302.     if (isset($_COOKIE['pma_charset'])) {
  303.         $convcharset = $_COOKIE['pma_charset'];
  304.     } else {
  305.         $convcharset = $cfg['DefaultCharset'];
  306.     }
  307. }
  308.  
  309. // 5. Defines the associated filename and load the translation
  310. $lang_file = $lang_path . $available_languages[$lang][1] . '.inc.php';
  311. require_once('./' . $lang_file);
  312. ?>
  313.