从 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: "你好"
我的问题是我无法获得罗马化(使用英文字母的发音)。这是已知问题。
现在数据就在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 异常 101)。有没有办法用ajax检索这个罗马化数据?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
今天看来不可能,但 Google Translate API 上存在解决此问题的悬而未决的问题。如果我们能够围绕这个问题召集足够多的人,也许 Google 会提高其优先级:
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) < a href="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" rel="noreferrer">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
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