小编Bli*_*eer的帖子

使用Javascript更改网站语言

我正在开发一个可以使用多种语言的GUI网站.我使用的原始HTML文件是完全静态的.因此,如果需要翻译,我必须解析alle文件,注意某些词语或术语的位置,将它们全部交给翻译部门并在新语言文件中输入这些翻译.

由于这些文件完全是静态的,因此意味着必须多次翻译整个部分.不是很有效率.

所以现在我正在使用Javascript中的某种字典,只是在那些网站上交换条款.它主要以这种方式工作:

var dicEnglish = {
term 1: "This is the English text"
Ref: "Another English text"
}
var dicFrench = {
term 1: "This is the French text"
Ref: "Another French text"   
}
Run Code Online (Sandbox Code Playgroud)

其中包含需要更改的所有可能内容.HTML代码中的每个候选者都获得一个class="dicRef" id="l_dicTag_#"标识符,我将其切换到字典标记并使用以下代码进行交换:

var imgSrc = "en";
var ActiveDic;
var langSel;
if(window.name){
    langSel=window.name;
    }
else{langSel="English";
}

function LangChange(){
langClass = document.getElementsByClassName("dicRef");
var i = langClass.length;
var Start, Stop, idSrc, idDic;
var navText;

switch(langSel){
    case "French":
        langSel="French";
        imgSrc = "en";
        navText="Anglais";
        break;
    case "English":
    case …
Run Code Online (Sandbox Code Playgroud)

html javascript translation

14
推荐指数
2
解决办法
6万
查看次数

标签 统计

html ×1

javascript ×1

translation ×1