ECSHOP中英文版切换的实现【收藏】

1.在前台文件夹include中找到init.phP文件,然后找到:

require(ROOT_PATH . ‘languages/’ . $_CFG[‘lang’] . ‘/common.php’);

然后再填写上面这些代码:

//获取传入的lang ->写入到cookie->跳转//中英文版
if($_GET[‘lang’]&&in_array($_GET[‘lang’],array(‘zh_cn’,’en_us’,’zh_tw’)))
{

setcookie(‘lang’,$_GET[‘lang’],0);
header(“location:”.PHP_SELF);

}

$_CFG[‘lang’]=$_COOKIE[‘lang’]?$_COOKIE[‘lang’]:’zh_cn’;///$_CFG[‘lang’]=’en_us’;//英文版

//echo $_COOKIE[‘lang’];
/* 载入语言文件 */

//$_CFG[‘lang’]=$_GET[‘lang’];

require(ROOT_PATH . ‘languages/’ . $_CFG[‘lang’] . ‘/common.php’);

2.在找到头部模板文件

在 themes/default/library/page_header.lib 相应的位置(你自己需要的地方) 添加上对应的中文链接和英文链接,代码如下:
<a href=”../index.php?lang=zh_cn”>中文版&nbsp;</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=”../index.php?lang=en_us”>英文版</a>

3.前台预览会出现Notice,和 Warning

Notice: Undefined index: lang in D:\shanmaoweb\shanmao\mylocalhost\afu\includes\init.php on line 120

Warning: Cannot modify header information – headers already sent by (output started at D:\shanmaoweb\shanmao\mylocalhost\afu\includes\init.php:120) in D:\shanmaoweb\shanmao\mylocalhost\afu\includes\init.php on line 176

Warning: Cannot modify header information – headers already sent by (output started at D:\shanmaoweb\shanmao\mylocalhost\afu\includes\init.php:120) in D:\shanmaoweb\shanmao\mylocalhost\afu\includes\init.php on line 177

Warning: Cannot modify header information – headers already sent by (output started at D:\shanmaoweb\shanmao\mylocalhost\afu\includes\init.php:120) in D:\shanmaoweb\shanmao\mylocalhost\afu\includes\cls_template.php on line 58

我们可以在init.php中屏蔽,在init.php的前几行找到(大概在20行。)

error_reporting(E_ALL);//E_ALL表示所有的都打开,错误等级设置
改成

error_reporting(E_ALL ^ E_NOTICE );//除去 E_NOTICE 之外的所有错误信息

—————————————————————————————–

ecshop支持当前页面切换语言。不用到首页去:

首先要让ecshop支持jquery,因为个人技术有限,目前只会jquery

先看:

让 ecshop 支持jquery

然后:

在footer模板里面加入:

[code]
<script type="text/javascript">
function lang_en(){
jQuery.get("/index.php?lang=en_us");
setTimeout("window.location.reload()",1000);
}
function lang_cn(){
jQuery.get("/index.php?lang=zh_cn");
setTimeout("window.location.reload()",1000);
}
</script>
[/code]

在头部模板加入切换按钮:

<a href=”javascript:lang_cn();”>中文版</a> |
<a href=”javascript:lang_en();”>English</a>

就搞定le .

——————————————————

让ecshop 默认英文:

打开index.php文件。

在最上面 加上:

$kk = $_COOKIE[‘diyici’];
if($kk!=1){
setcookie(“diyici”,1,time()+6600,”/”);
header(‘Location: http://xxx.com/index.php?lang=en_us’);
}

即可。