官网的收费,所以自己下载了个英文包language文件夹,和默认的简体中文的语言包,来实现切换 1.在/source下增加目录locale,将待切换的语言包langguage放到里面并重命名,下面以中文包更名为zh_CN,英文包更名为en_US为例进行操作(原先默认的/source/language还留在那里一份,与页面无关的继续调用默认的就可以) 2.在/source/class/class_core.php底部引入文件: /**begin 多语言包切换**/ require_once './source/discuz_locale.php'; /**end 多语言包切换**/ 2.在/source下增加文件discuz_locale.php,内容是 <?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')); 3./source/function/function_core.php中的checktplrefresh方法中,这两个if里加上 '1 ||', 来关闭缓存,这是为了切换语言后前台页面能立即生效,而不必去后台更新缓存。 if(1 || empty($timecompare) || $tplrefresh == 1 || ($tplrefresh > 1 && !($timestamp % $tplrefresh))) { if(1 || empty($timecompare) || @filemtime(DISCUZ_ROOT.$subtpl) > $timecompare) 4.替换/source/function/function_core.php,source/class/optimizer/optimizer_setting.php中包含有language/的加载路径,替换成DISCUZ_LOCALE。如 include DISCUZ_LOCALE.($path == '' ? '' : '/'.$path).'/lang_'.$file.'.php'; 5.前台增加切换按钮,分别加上链接 http://url?lang=cn 和 http://url?lang=en就可以 <td>&nbsp;<a href="javascript:changetoVersion('cn','en')" class="xi2 xw1">中文版</a></td>
<td>&nbsp;<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>
思路有借鉴,感谢:http://tieba.baidu/p/3600965400

更多推荐

discuz多语言切换