微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ajax – 从Google Translate API获取中文罗马字

Google语言翻译API干净地翻译成中文
<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检索这个罗马化数据?

原文地址:https://www.jb51.cc/ajax/159882.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐