Get Chinese Romanization from Google Translate API

感情迁移 提交于 2019-11-29 18:08:21

问题


The Google language translate API works cleanly to translate into Chinese:

<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: "你好"

My problem is I can't get the Romanization (pronunciation using English letters). This is a known issue.

Now the data is right there on translate.google.com (Example input: "Hello" Result: "Nǐ hǎo") and I can even see it by pointing my browser to:

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"}

But somehow when I try to get this URL with ajax it fails (XMLHttpRequest Exception 101). Is there any way to retrieve this Romanization data with ajax?


回答1:


It doesn't appear possible today, but there are open issues on the Google Translate API to address this. If we can rally enough people around the issue, perhaps Google will raise its priority:

1) http://code.google.com/p/google-ajax-apis/issues/detail?id=478&q=label%3AAPIType-Language&sort=-stars&colspec=ID%20Type%20Stars%20Status%20Modified%20Summary%20APIType%20Opened

2) http://code.google.com/p/google-ajax-apis/issues/detail?id=381&q=label%3AAPIType-Language&sort=-stars&colspec=ID%20Type%20Stars%20Status%20Modified%20Summary%20APIType%20Opened



来源:https://stackoverflow.com/questions/2750093/get-chinese-romanization-from-google-translate-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!