我需要有关我网站上已安装的自动检测语言的帮助

时间:2014-03-15 18:23:59

标签: php mysql

你好这里的新员工和英语不好,但我真的需要一些帮助!

我的网站已经有一些语言mytrip.gallery,但它不会自动检测语言,并且想知道是否有人知道如何做到这一点,有人可以帮助我吗?我将花一些代码页:

INCLUDE / CONFIG中的

`<?
$config = array();

// Begin Configuration
$config['basedir']     =  '---';
$config['baseurl']     =  '---';

$DBTYPE = '----';
$DBHOST = '----';
$DBUSER = '----';
$DBPASSWORD = '---';
$DBNAME = '---';

$default_language = "english"; //Valid options are english, french, spanish, portuguese, japanese, chinese_simplified or chinese_traditional
// End Configuration

session_start();
date_default_timezone_set('America/New_York');
$config['adminurl']      =  $config['baseurl'].'/administrator';
$config['cssurl']      =  $config['baseurl'].'/css';
$config['imagedir']      =  $config['basedir'].'/img';
$config['imageurl']      =  $config['baseurl'].'/img';
$config['pdir']      =  $config['basedir'].'/pics';
$config['purl']      =  $config['baseurl'].'/pics';
$config['mdir']      =  $config['basedir'].'/mpics';
$config['murl']      =  $config['baseurl'].'/mpics';
echo file_get_contents($config['baseurl']."/startup.php");
require_once($config['basedir'].'/smarty/libs/Smarty.class.php');
require_once($config['basedir'].'/libraries/mysmarty.class.php');
require_once($config['basedir'].'/libraries/SConfig.php');
require_once($config['basedir'].'/libraries/SError.php');
require_once($config['basedir'].'/libraries/adodb/adodb.inc.php');
require_once($config['basedir'].'/libraries/phpmailer/class.phpmailer.php');
require_once($config['basedir'].'/libraries/SEmail.php');

function strip_mq_gpc($arg)
{
    $arg = str_replace('"',"'",$arg);
    $arg = stripslashes($arg);
    return $arg;
}

$conn = &ADONewConnection($DBTYPE);
$conn->PConnect($DBHOST, $DBUSER, $DBPASSWORD, $DBNAME);
@mysql_query("SET NAMES 'UTF8'");
$sql = "SELECT * from config";
$rsc = $conn->Execute($sql);

if($rsc){while(!$rsc->EOF)
{
$field = $rsc->fields['setting'];
$config[$field] = $rsc->fields['value'];
STemplate::assign($field, strip_mq_gpc($config[$field]));
@$rsc->MoveNext();
}}

if ($_REQUEST['language'] != "")
{
    if ($_REQUEST['language'] == "english")
    {
        $_SESSION['language'] = "english";
    }
    elseif ($_REQUEST['language'] == "french")
    {
        $_SESSION['language'] = "french";
    }
    elseif ($_REQUEST['language'] == "spanish")
    {
    $_SESSION['language'] = "spanish";
}
elseif ($_REQUEST['language'] == "portuguese")
{
    $_SESSION['language'] = "portuguese";
}
elseif ($_REQUEST['language'] == "japanese")
{
    $_SESSION['language'] = "japanese";
}
elseif ($_REQUEST['language'] == "chinese_simplified")
{
    $_SESSION['language'] = "chinese_simplified";
}
elseif ($_REQUEST['language'] == "chinese_traditional")
{
    $_SESSION['language'] = "chinese_traditional";
}
}

if ($_SESSION['language'] == "")
{
$_SESSION['language'] = $default_language;
}

if ($_SESSION['language'] == "english")
{
include("lang/english.php");
}
elseif ($_SESSION['language'] == "french")
{
include("lang/french.php");
}
elseif ($_SESSION['language'] == "spanish")
{
include("lang/spanish.php");
}
elseif ($_SESSION['language'] == "portuguese")
{
include("lang/portuguese.php");
}
elseif ($_SESSION['language'] == "japanese")
{
include("lang/japanese.php");
}
elseif ($_SESSION['language'] == "chinese_simplified")
{
include("lang/chinese_simplified.php");
}
elseif ($_SESSION['language'] == "chinese_traditional")
{
include("lang/chinese_traditional.php");
}
else
{
include("lang/".$default_language.".php");
}

for ($i=0; $i<count($lang); $i++)
{
STemplate::assign('lang'.$i, $lang[$i]);
}
if($config['re_mobile'] == "1" && $config['m_url'] != "")
{
if($mobile != "1")
{
    include("mobile.php");
    $mcheck = is_md();
    if($mcheck != "")
    {
        header("Location:".$config['m_url']);exit;
    }
}
}
STemplate::assign('baseurl',       $config['baseurl']);
STemplate::assign('basedir',       $config['basedir']);
STemplate::assign('adminurl',       $config['adminurl']);
STemplate::assign('cssurl',       $config['cssurl']);
STemplate::assign('imagedir',        $config['imagedir']);
STemplate::assign('imageurl',        $config['imageurl']);
STemplate::assign('pdir',        $config['pdir']);
STemplate::assign('purl',        $config['purl']);
STemplate::assign('mdir',        $config['mdir']);
STemplate::assign('murl',        $config['murl']);
STemplate::setCompileDir($config['basedir']."/temporary");
STemplate::setTplDir($config['basedir']."/themes");

...

并且包含包含/语言的语言的文件夹,请参阅英语示例:

<?
$lang = array();

$lang['0'] =  "Login";
$lang['1'] =  "Home";
$lang['2'] =  "Not a member yet?";
$lang['3'] =  "Get an invitation and register.";
$lang['4'] =  "Receive an invitation";
$lang['5'] =  "Login using your facebook account.";
$lang['6'] =  "Connect using Facebook";

$ lang [&#39; 7&#39;] =&#34;使用您的电子邮件地址登录。&#34 ;;`

它还有葡萄牙语,西班牙语,日语

我感谢任何帮助,我知道对于一些exeprientes程序员来说这很容易,为此我正在寻求帮助!

我找到了MENU_MENU.TPL

<div class="nav sysOutLink"><a href="javascript:void(0)"      {literal}onclick="App.ajaxDialog('{/literal}{$baseurl}{literal}/language.php', {id:     'sysLangPopup', width: '550px'})"{/literal}>{if $smarty.session.language eq "english"}English{elseif $smarty.session.language eq "spanish"}Español{elseif $smarty.session.language eq "french"}Français{elseif $smarty.session.language eq "portuguese"}Português{elseif $smarty.session.language eq "japanese"}日本の{elseif $smarty.session.language eq "chinese_simplified"}中文(简体){elseif $smarty.session.language eq "chinese_traditional"}中國傳統文化{/if}</a></div>

1 个答案:

答案 0 :(得分:0)

根据浏览器语言,使用:

$_SERVER['HTTP_ACCEPT_LANGUAGE'];