【php开源代码栏目提醒】:以下是网学会员为您推荐的php开源代码-select_lang.lib.php,希望本篇文章对您学习有所帮助。
<?php
/* $Id: select_lang.lib.php,v 2.36.2.2 2006/05/02 09:28:57 nijel Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* phpMyAdmin Language Loading File
*/
/**
* trys to find the language to use
*
* @uses $GLOBALS['cfg']['lang']
* @uses $GLOBALS['cfg']['DefaultLang']
* @uses $GLOBALS['lang_failed_cfg']
* @uses $GLOBALS['lang_failed_cookie']
* @uses $GLOBALS['lang_failed_request']
* @uses $_REQUEST['lang']
* @uses $_COOKIE['pma_lang']
* @uses $_SERVER['HTTP_ACCEPT_LANGUAGE']
* @uses $_SERVER['HTTP_USER_AGENT']
* @uses PMA_langSet()
* @uses PMA_langDetect()
* @uses explode()
* @return bool success if valid lang is found, otherwise false
*/
function PMA_langCheck()
{
// check forced language
if (! empty($GLOBALS['cfg']['Lang'])) {
if (PMA_langSet($GLOBALS['cfg']['Lang'])) {
return true;
} else {
$GLOBALS['lang_failed_cfg'] = $GLOBALS['cfg']['Lang'];
}
}
// check user requested language
if (! empty($_REQUEST['lang'])) {
if (PMA_langSet($_REQUEST['lang'])) {
return true;
} else {
$GLOBALS['lang_failed_request'] = $_REQUEST['lang'];
}
}
// check previous set language
if (! empty($_COOKIE['pma_lang'])) {
if (PMA_langSet($_COOKIE['pma_lang'])) {
return true;
} else {
$GLOBALS['lang_failed_cookie'] = $_COOKIE['pma_lang'];
}
}
// try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE variable
if (PMA_getenv('HTTP_ACCEPT_LANGUAGE')) {
foreach (explode(',', PMA_getenv('HTTP_ACCEPT_LANGUAGE')) as $lang) {
if (PMA_langDetect($lang, 1)) {
return true;
}
}
}
// try to findout user's language by checking its HTTP_USER_AGENT variable
if (PMA_langDetect(PMA_getenv('HTTP_USER_AGENT'), 2)) {
return true;
}
// Didn't catch any valid lang : we use the default settings
if (PMA_langSet($GLOBALS['cfg']['DefaultLang'])) {
return true;
}
return false;
}
/**
* checks given lang and sets it if valid
* returns true on success, otherwise flase
*
* @uses $GLOBALS['available_languages'] to check $lang
* @uses $GLOBALS['lang'] to set it
* @param string $lang language to set
* @return bool success
*/
function PMA_langSet(&$lang)
{
if (empty($lang) || empty($GLOBALS['available_languages'][$lang])) {
return false;
}
$GLOBALS['lang'] = $lang;
return true;
}
/**
* Analyzes some PHP environment variables to find the most probable language
* that should be used
*
* @param string string to analyze
* @param integer type of the
PHP environment variable which value is $str
*
* @return bool true on success, otherwise false
*
* @global $available_languages
*
* @access private
*/
function PMA_langDetect(&$str, $envType)
{
if (empty($str)) {
return false;
}
if (empty($GLOBALS['available_languages'])) {
return false;
}
foreach ($GLOBALS['available_languages'] as $lang => $value) {
// $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
// 2 for the 'HTTP_USER_AGENT' one
$expr = $value[0];
if (strpos($expr, '[-_]') === FALSE) {
$expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr);
}
if (($envType == 1 && eregi('^(' . $expr . ')(;q=[0-9]\\.[0-9])?$', $str))
|| ($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $expr . ')(;|\]|\))', $str))) {
if (PMA_langSet($lang)) {
return true;
}
}
}
return false;
} // end of the 'PMA_langDetect()' function
/**
* @var string path to the translations directory
*/
$lang_path = './lang/';
/**
* first check for lang dir exists
*/
if (! is_dir($lang_path)) {
// language directory not found
trigger_error('phpMyAdmin-ERROR: path not found: '
. $lang_path . ', check your language directory.',
E_USER_WARNING);
// and tell the user
PMA_sendHeaderLocation('error.php?error='
. urlencode( 'path to languages is invalid: ' . $lang_path));
// stop execution
exit;
}
/**
* @var string interface language
*/
$GLOBALS['lang'] = '';
/**
* @var boolean wether loading lang from cfg failed
*/
$lang_failed_cfg = false;
/**
* @var boolean wether loading lang from cookie failed
*/
$lang_failed_cookie = false;
/**
* @var boolean wether loading lang from user request failed
*/
$lang_failed_request = false;
/**
* All the supported languages have to be listed in the array below.
* 1. The key must be the "official" ISO 639 language code and, if required,
* the dialect code. It can also contain some informations about the
* charset (see the Russian case).
* 2. The first of the values associated to the key is used in a regular
* expression to find some key
words corresponding to the language inside two
* environment variables.
* These values contains:
* - the "official" ISO language code and, if required, the dialect code
* also ('bu' for Bulgarian, 'fr([