开发者

Google Translate call from JS using POST

开发者 https://www.devze.com 2022-12-14 08:29 出处:网络
We\'re using google translate to translate some shorter texts dynamically on our site. The current implementation looks pretty much like this example in google code playground.

We're using google translate to translate some shorter texts dynamically on our site. The current implementation looks pretty much like this example in google code playground.

Now w开发者_运维技巧e need to translate slightly longer texts, which are too long for GET-method. From google documentation it seems to be possible to use POST for sending the translation string.

Can anybody explain how to get it to use POST as there is no form that's submitted and the data sent to google contains only text and source/target languages?

Thanks in advance.


As it says in the documentation, it is not possible with JavaScript. But what you can do is create a webservice in between Google and you in a server side language. And then use JavaScript to run parameter to the.

Google Translate call from JS using POST

(http://bildr.no/view/551563)


To answer my own question: It seems it's impossible to get the JS translator call to use POST. The workaround would be to send(ajax) the translation-string to our server, make the server connect to Google, get the translation, send(ajax) it back to client and update it.

The other evident option is to clip to text to small enough chunks to fit GET...

0

精彩评论

暂无评论...
验证码 换一张
取 消