该 HTML 脚本会音译输入其中的每个单词、短语或字母。
本质上,它是一个非官方的翻译器。
使用 jsFiddle 测试代码时,出现以下错误:
{"error": "请使用 POST 请求"}
我将文件正确保存为 .html,并使用 Google Chrome 打开它。
一切都是这样工作的;我能够音译文本,但是当我输入太多要音译的文本时,框内的文本将被省略,代码(页面)本质上会“刷新”自身。
但是,此代码确实可以翻译小的短语和单词。
要音译的字符数量是否有限制?
我不确定错误表示什么,但我确定上述 jsFiddle 错误与这个错误相对应。
这让我很困惑。
音译代码如下:
<html>
<head>
<title>English - Imzreth Translator</title>
<script>
validator = "aábcdeéfghjiíklmnoöpqrstuüvwxyzAÁBCDEÉFGHIJKLMNOÖPQRSTUÜVWXYZ’";
vowels = "aáeéiíoöuüyAÁEÉIÍOÖUÜY’";
aemap = new Array();
aemap["au"] = "a";
aemap["a"] = "a";
aemap["l"] = "b";
aemap["b"] = "b";
aemap["c"] = "c";
aemap["ku"] = "d";
aemap["d"] = "d";
aemap["u"] = "e";
aemap["u"] = "e";
aemap["f"] = "f";
aemap["gé"] = "g";
aemap["g"] = "g";
aemap["h"] = "h";
aemap["o"] = "i";
aemap["i"] = "i";
aemap["t"] = "j";
aemap["j"] = "j";
aemap["ré"] = "k";
aemap["k"] = "k";
aemap["l"] = "l";
aemap["m"] = "m";
aemap["q"] = "n";
aemap["n"] = "n";
aemap["i"] = "o";
aemap["o"] = "o";
aemap["ph"] = "p";
aemap["p"] = "p";
aemap["q"] = "q";
aemap["r"] = "r";
aemap["s"] = "s";
aemap["s"] = "t";
aemap["t"] = "t";
aemap["e"] = "u";
aemap["u"] = "u";
aemap["z"] = "v";
aemap["v"] = "v";
aemap["w"] = "w";
aemap["l"] = "x";
aemap["x"] = "x";
aemap["y"] = "y";
aemap["á"] = "y";
aemap["z"] = "z";
eamap = new Array();
eamap["a"] = "au";
eamap["b"] = "l";
eamap["c"] = "c";
eamap["d"] = "ku";
eamap["e"] = "u";
eamap["f"] = "f";
eamap["g"] = "gé";
eamap["h"] = "h";
eamap["i"] = "o";
eamap["j"] = "t";
eamap["k"] = "ré";
eamap["l"] = "l";
eamap["m"] = "m";
eamap["n"] = "n";
eamap["o"] = "i";
eamap["p"] = "ph";
eamap["q"] = "q";
eamap["r"] = "r";
eamap["s"] = "s";
eamap["t"] = "s";
eamap["u"] = "e";
eamap["v"] = "z";
eamap["w"] = "w";
eamap["x"] = "l";
eamap["y"] = "á";
eamap["z"] = "z";
eamap["A"] = "A";
eamap["B"] = "B";
eamap["C"] = "C";
eamap["D"] = "D";
eamap["E"] = "E";
eamap["F"] = "F";
eamap["G"] = "G";
eamap["H"] = "H";
eamap["I"] = "I";
eamap["J"] = "J";
eamap["K"] = "K";
eamap["L"] = "L";
eamap["M"] = "M";
eamap["N"] = "N";
eamap["O"] = "O";
eamap["P"] = "P";
eamap["Q"] = "Q";
eamap["R"] = "R";
eamap["S"] = "S";
eamap["T"] = "T";
eamap["U"] = "U";
eamap["V"] = "V";
eamap["W"] = "W";
eamap["X"] = "X";
eamap["Y"] = "Y";
eamap["Z"] = "Z";
promap = new Array();
promap["a"] = "aah";
promap["b"] = "buh";
promap["c"] = "se";
promap["d"] = "duh";
promap["e"] = "eh";
promap["f"] = "f";
promap["g"] = "guh";
promap["h"] = "h’";
promap["i"] = "íh";
promap["j"] = "juh";
promap["k"] = "kuh";
promap["l"] = "l’";
promap["m"] = "m";
promap["n"] = "n";
promap["o"] = "öh";
promap["p"] = "puh";
promap["q"] = "quah";
promap["r"] = "ra";
promap["s"] = "s";
promap["t"] = "t’uh";
promap["u"] = "ooh";
promap["v"] = "vuh";
promap["w"] = "wuh";
promap["x"] = "k’ss";
promap["y"] = "ya";
promap["z"] = "z";
promap["ph"] = "f’";
promap["au"] = "aw";
promap["gé"] = "zhé";
promap["á"] = "ahh";
promap["ku"] = "kü";
promap["A"] = "Á";
promap["B"] = "B’";
promap["C"] = "CÉ";
promap["D"] = "D’";
promap["E"] = "EH";
promap["F"] = "F’";
promap["G"] = "G’";
promap["H"] = "H’";
promap["I"] = "Í’";
promap["J"] = "J’";
promap["K"] = "K’";
promap["L"] = "L’";
promap["M"] = "M";
promap["N"] = "N";
promap["O"] = "Ö’";
promap["P"] = "P’";
promap["Q"] = "Q’";
promap["R"] = "RA";
promap["S"] = "SEE";
promap["T"] = "T’UH";
promap["U"] = "OOH";
promap["V"] = "VUH";
promap["W"] = "WUH";
promap["X"] = "K’SS";
promap["Y"] = "YA";
promap["Z"] = "Z";
promap["PH"] = "F";
promap["AU"] = "AW";
promap["KU"] = "KÜ";
function transme() {
if (document.theform.picker[0].checked) { // english to al bhed
builder = "";
toggler = 0;
for (var i = 0; i < document.theform.stimulus.value.length; i++) {
if (document.theform.stimulus.value.charAt(i) == "[") {
toggler = 1;
};
if (document.theform.stimulus.value.charAt(i) == "]") {
toggler = 0;
};
if (toggler == 1) {
builder = builder + document.theform.stimulus.value.charAt(i);
} else {
if (validator.indexOf(document.theform.stimulus.value.charAt(i)) == -1) {
builder = builder + document.theform.stimulus.value.charAt(i);
} else {
builder = builder + eamap[document.theform.stimulus.value.charAt(i)];
};
};
};
builder2 = "";
toggler = 0;
prev = 0;
for (var i = 0; i < document.theform.stimulus.value.length; i++) {
if (document.theform.stimulus.value.charAt(i) == "[") {
toggler = 1;
};
if (document.theform.stimulus.value.charAt(i) == "]") {
toggler = 0;
};
if (toggler == 1) {
builder2 = builder2 + document.theform.stimulus.value.charAt(i);
} else {
if (validator.indexOf(document.theform.stimulus.value.charAt(i)) == -1) {
builder2 = builder2 + document.theform.stimulus.value.charAt(i);
prev = 0;
} else {
temp = promap[eamap[document.theform.stimulus.value.charAt(i)]];
if (prev == 1) {
if ((vowels.indexOf(temp.charAt(0)) == -1) && (temp.length != 1)) {
builder2 = builder2 + "-";
};
};
builder2 = builder2 + temp;
prev = 1;
};
};
};
document.theform.response.value = builder + "\n\nPronounced: \"" + builder2 + "\"";
} else { //al bhed to english
builder = "";
toggler = 0;
for (var i = 0; i < document.theform.stimulus.value.length; i++) {
if (document.theform.stimulus.value.charAt(i) == "[") {
toggler = 1;
};
if (document.theform.stimulus.value.charAt(i) == "]") {
toggler = 0;
};
if (toggler == 1) {
builder = builder + document.theform.stimulus.value.charAt(i);
} else {
if (validator.indexOf(document.theform.stimulus.value.charAt(i)) == -1) {
builder = builder + document.theform.stimulus.value.charAt(i);
} else {
builder = builder + aemap[document.theform.stimulus.value.charAt(i)];
};
};
};
document.theform.response.value = builder;
};
return false;
};
</script>
</head>
<body>
<form method="get" name="theform" action="" onSubmit="return transme()">
<p><b><h2>English to Custom Language Translator (With Phonetics)</h2></b>
<p><b>Translate Text:</b>
<br> <u>(Excluded text should be within brackets).</u>
<br>
<textarea name="stimulus" cols="60" rows="6" wrap="VIRTUAL"></textarea>
</p>
<p><b>Translated Text:</b>
<br>
<textarea name="response" cols="60" rows="6" wrap="VIRTUAL"></textarea>
</p>
<p><b>Translation Options:</b>
<br>
<input name="picker" type="radio" value="0" checked>English to Custom Language (With Phonetics)
<br>
<input name="picker" type="radio" value="1">Custom Language to English (With Rough Phonetics)</p>
<p>
<input type="submit" value="Transl ate / Traunslausu!">
</p>
</form>
</body>
</html>
我很乐意在修复代码以确保完整功能方面获得帮助。