How to translate whole website by google transltion?
This is my code :
<div id="wrap">
⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
</div>
<script type="text/javascript">
google.load("language", "开发者_JAVA百科1");
google.setOnLoadCallback(submitChange);
var wrap_text = '';
function submitChange(){
wrap_text = document.getElementById('wrap').innerHTML;
google.language.translate(wrap_text, 'zh-CN', 'zh-TW', function(result) {
var resultBody = document.getElementById('wrap');
alert(result.translation);
if (result.translation){
resultBody.innerHTML = result.translation;
}
else {
resultBody.innerHTML = wrap_text;
}
});
return false;
}
</script>
it does not work, if I replace wrap_text to some words, it works.
who can help me, thanks!
I think you have to escape it to work, at least that's what they did in the example code:
var sourceText = escape(document.getElementById("sourceText").innerHTML);
See: http://code.google.com/apis/language/translate/v2/getting_started.html
I find a good solution http://translate.google.com/translate_tools?hl=en
精彩评论