我想在我的网站上免费使用google翻译,我可以这样做吗?我该怎么办呢?下面的代码说:
XMLHttpRequest cannot load http://translate.google.com/translate_a/single?client=t&sl=auto&tl=en&hl=en…l=0&tsel=3&q=%D9%86%D8%A7%D9%85+%DA%A9%D8%A7%D8%B1%D8%A8%D8%B1%DB%8C/f.txt. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
或FireBug说:Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://translate.google.com/translate_a/single?client=t&sl=auto&tl=en&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&dt=sw&ie=UTF-8&oe=UTF-8&oc=1&otf=2&ssel=0&tsel=3&q=%D9%86%D8%A7%D9%85+%DA%A9%D8%A7%D8%B1%D8%A8%D8%B1%DB%8C/f.txt. This can be fixed by moving the resource to the same domain or enabling CORS.
如何启用Cros?
$.ajax({url:"http://translate.google.com/translate_a/single?client=t&sl=auto&tl=en&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&dt=sw&ie=UTF-8&oe=UTF-8&oc=1&otf=2&ssel=0&tsel=3&q=%D9%86%D8%A7%D9%85+%DA%A9%D8%A7%D8%B1%D8%A8%D8%B1%DB%8C/f.txt"
,type: 'GET'
,crossDomain: true
,dataType: "text"
,success:function(result){
alert(result);
}});
谢谢你的帮助!
这可能会有所帮助:
为了与Google进行互动,您需要使用Google Translate API来从第三方资源(例如您的网站)进行翻译。
该API的价格约为每百万个字符20美元,有关更多信息,请参见定价和条款。
我可能误解了你的问题。如果您要翻译整个网站,则可以使用免费的Google网站翻译器
如上所述,虽然付费是访问Google Translate的唯一方法,但是如果您想要免费的翻译API ,请尝试使用Yandex翻译API。希望这可以帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句