1.在/source下增加目录locale,将待切换的语言包langguage放到里面并重命名,下面以中文包更名为zh_CN,英文包更名为en_US为例进行操作(原先默认的/source/language还留在那里一份,与页面无关的继续调用默认的就可以)
/**begin 多语言包切换**/
require_once './source/discuz_locale.php';
/**end 多语言包切换**/
<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
empty(getcookie('locale')) ? dsetcookie('locale','zh_CN') : '';
if(isset($_GET['lang'])){
$mylang = array(
'cn' => 'zh_CN',
'en' => 'en_US'
);
if(array_key_exists($_GET['lang'], $mylang)){
dsetcookie('locale',$mylang[$_GET['lang']]);
}
}
define('DISCUZ_LOCALE', DISCUZ_ROOT.'source/locale/'.getcookie('locale'));
来关闭缓存,这是为了切换语言后前台页面能立即生效,而不必去后台更新缓存。
if(1 || empty($timecompare) || $tplrefresh == 1 || ($tplrefresh > 1 && !($timestamp % $tplrefresh))) {
if(1 || empty($timecompare) || @filemtime(DISCUZ_ROOT.$subtpl) > $timecompare)
include DISCUZ_LOCALE.($path == '' ? '' : '/'.$path).'/lang_'.$file.'.php';
<td> <a href="javascript:changetoVersion('cn','en')" class="xi2 xw1">中文版</a></td>
<td> <a href="javascript:changetoVersion('en','cn')" class="xi2 xw1">English</a></td>
<script>
function changetoVersion(arg1,arg2){
if(location.href.indexOf('?lang=') != '-1' || location.href.indexOf('?') == '-1'){
arg1 = '?lang=' + arg1;
arg2 = '?lang=' + arg2;
}else{
arg1 = '&lang=' + arg1;
arg2 = '&lang=' + arg2;
}
if(location.href.indexOf(arg1) != '-1'){
location.reload();
}else if(location.href.indexOf(arg2) != '-1'){
location.href = location.href.replace(arg2,'')
+ arg1;
}else{
location.href += arg1;
}
}
</script>
以下是英语包:
---
转载请注明本文标题和链接:《Discuz!X3.2多国语言实现方法及教程》
发表评论