problem with translation api

0 views
Skip to first unread message

david1721

unread,
Nov 10, 2009, 12:05:17 AM11/10/09
to Google AJAX APIs
Hi

I am using the translation api on my website. For the most part it
works fine but
on some items with longer descriptions nothing happens. I have seen
references
to a size limit of 5000 chars but I think it is only working if there
are less than 500.
I have also read something about using post rather than get but I am
setting the
text string var in a js function by using the innerHTML of the
element that contains the text so I don't understand how I can define
the request as a get or a post since I'm not sending the text as a
form var. Can someone tell me what I need to do
here?

Thanks

Jeremy Geerdes

unread,
Nov 10, 2009, 12:16:05 AM11/10/09
to google-ajax...@googlegroups.com
Well, here's the deal. The Translation API as deployed by Google
utilizes a technique called JSONP to send your original string to
Google and receive a translated string in response. The only way that
works, though, is by appending a remote script element to the document
head and sending parameters via its url (i.e., the get method). The
problem here is that MSIE has a url length limit, and Google has
implemented one of its own for security reasons. So the only way to
utilize the full 5,000 urlencoded string length limit is to submit the
information via the POST method as a header instead of on the url.
Unfortunately, JSONP doesn't support this. So you have to resort to
building your own server-side proxy. This proxy will be a very simple
application which will simply send the data on to Google using the
POST method, receive the response from Google, and then push it back
to the client. So the whole process ends up looking like this:

In the client, you initialize an XMLHttpRequest object and send your
source string via POST to your own server-side proxy. Your server-side
proxy gathers the information, sends it on to Google, receives a
response, and returns that response to the client. Your client-side
script receives and parses the response, and then finishes the
translation process.

Jeremy R. Geerdes
Effective website design & development
Des Moines, IA

For more information or a project quote:
http://jgeerdes.home.mchsi.com
http://jgeerdes.blogspot.com
http://jgeerdes.wordpress.com
jgee...@mchsi.com

Unless otherwise noted, any price quotes contained within this
communication are given in US dollars.

If you're in the Des Moines, IA, area, check out Debra Heights
Wesleyan Church!

And check out my blog, Adventures in Web Development, at http://jgeerdes.blogspot.com
!
Reply all
Reply to author
Forward
0 new messages