我正在使用手动语言翻译的混合方法,以及使用 jquery-translate libray 的谷歌翻译。我已经让谷歌方法正常工作,但谷歌缺少我雇主的客户需要的一些语言......
因此,我使用 jquery 读取具有英语 + 法语加拿大语言的 xml 文件,对于示例页面,我能够读取 xml,并使用 nodeContainsText 替换页面上的文本,但是当我这样做时。通过谷歌翻译(即法语)完美显示的文本重音。
所以我的问题是如何将 xml 数据作为正确的字符集/内容类型,以便正确显示。
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "xmldata.xml",
dataType: "xml",
success: parseXml
});
});
function parseXml(xml)
{
//find every Tutorial and print the author
$(xml).find("english").each(function()
{
$(this).find('phrase').each(function(){
english[count] = $(this).text();
console.log('Adding to english array..['+english[count]+']');
count = count + 1;
});
});
count = 1;
$(xml).find("french_canadian").each(function()
{
$(this).find('phrase').each(function(){
frca[count] = $(this).text();
console.log('Adding to frca array..['+frca[count]+']');
count = count + 1;
});
});
$('body').nodesContainingText().each(function(){
// step 1 search through all text nodes
var $el = $(this), text = $el.text() || $el.val();
var nn = this.nodeName;
// step 2 find position in english array for word
for(var i=0;i<english.length;i++) {
// step 3 replace with french canadian version from array
if (english[i] == text) {
// which node dot text = value
console.log('Replacing...'+english[i]+' with '+frca[i]);
$el.text(frca[i]);
}
}
});
}
如您所见,我正在通过 firebug 使用 console.log 来帮助调试内容/字符集问题的来源......
我似乎无法掌握将从 xml 文件传入的数据转换为正确的 htmlentities 编码的语法。
我知道它应该是 .html() 但是当我添加它时,它只会导致错误。那么有人可以给我一个线索吗?
谢谢你。