Google语言翻译API干净地翻译成中文:
原文链接:https://www.f2er.com/ajax/159882.html<script type="text/javascript" src="http://www.google.com/jsapi"></script> <script> google.load('language','1'); function googletrans(text) { google.language.translate(text,'en','zh',function(result) { alert(result.translation); }); } </script> <input onchange="googletrans(this.value);"> Example input: "Hello" Result: "你好"
我的问题是我不能得到Romanization(使用英文字母的发音).这是一个known issue.
现在的数据就在translate.google.com上(例如:“Hello”结果:“Nǐhǎo”)),甚至可以通过指向浏览器查看:
http://translate.google.com/translate_a/t?client=t&text=hello&hl=en&sl=en&tl=zh-CN&otf=2&pc=0 Result: {"sentences":[{"trans":"你好","orig":"hello","translit":"Nǐ hǎo"}],"dict":[{"pos":"interjection","terms":["喂"]}],"src":"en"}
但是不知何故当我尝试使用ajax获取这个URL失败(XMLHttpRequest Exception 101).有没有办法用ajax检索这个罗马化数据?