多语言切换,不适合大量文本

原创 ninja123 随笔 笔记 290阅读 2017-06-28 11:22:09 举报

html 代码

text-ja.json

text-zh.json

$(function() {

    var uulanguage = (navigator.language || navigator.browserLanguage).toLowerCase();

if (uulanguage.indexOf("en") > -1) {

  $("[data-localize]").localize("text", {pathPrefix: "lang", language: "en"});//pathPrefix文件路径,小心跨域产生
}

else if (uulanguage.indexOf("ja") > -1) {

 $("[data-localize]").localize("text", {pathPrefix: "lang", language: "ja"});

}
else if (uulanguage.indexOf("zh") > -1) {

 $("[data-localize]").localize("text", {pathPrefix: "lang", language: "zh"});

}else{
$("[data-localize]").localize("text", {pathPrefix: "lang", language: "en"});
};
if (sessionStorage[name] != "") {
if (sessionStorage[name] == "ja") {
$("[data-localize]").localize("text", {pathPrefix: "lang", language: "ja"});
}
if (sessionStorage[name] == "en") {
$("[data-localize]").localize("text", { pathPrefix: "lang",language: "en"});
}
if (sessionStorage[name] == "zh") {
$("[data-localize]").localize("text", { pathPrefix: "lang",language: "zh"});
}
}
});
</script>

</html>[/code]

评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复