需 chinese.js, jquery.js, jquery.cookie.min.js 辅助

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* 繁体语言切换配置
* */

<li><a class="tradToggle" data-lang="2">繁</a> / <a href="/">EN</a></li>

function langTurn() {
var cookieName = 'zh_choose'
, langIdBtn = $(".tradToggle")
, cookieGet = $.cookie()
, zh_choose = $.cookie(cookieName)
, home_zh_choose = cookieGet[cookieName];
// 入内页和首页语言不一致进行转换
if(zh_choose != home_zh_choose) {
// 储存带有当前路径的cookie
zh_tran(home_zh_choose);
}
if (home_zh_choose == 't') {
langIdBtn.data("lang", 1).text("简")
}
langIdBtn.click(function () {
_lang = $(this).data("lang");
if (_lang == 2) {
zh_tran('t');
$.cookie(cookieName, 't', {path: '/'})
$(this).data("lang", 1).text("简");
} else {
zh_tran('s');
$.cookie(cookieName, 's', {path: '/'})
$(this).data("lang", 2).text("繁")
}
location.reload();
})
}