The Google Translate API are not free.We built a HACK which allows us to use it for FREE!!
Note:This hack is a result of one night work done for submission of some college project and has been used only for 2 days for a max of 10 queries. It is based on pure observance and is not intended to cause any harm. The author is in no way responsible for the actions of the reader.
TL;DR: if you are looking for the code that allows you to use Google Translate in your app for FREE then go to the end of this post.
This is how we went about building it:
If you go to translate.google.com and try to translate a sentence for example:(just click on the image for better view)
Then for some one who has basic understanding of web might think that sending a request of the form “translate.google.com/<source language code>/<target language code>/<sentence to be translated>” will get them the results , but this does not workout.
So we go a little bit deeper in our exploration, we use one of our favorite development tool “Firebug” to examine how the page responds to our actions. So now our plan is to observe the AJAX requests that the page makes. For observing these we Switch on our firebug and go to the ‘net’ tab:
In case it says its off then just switch it on and reload the page.
So these are the requests sent during our text change, now we need to figure out which one of these are useful for us. For this we checkout the requests going to translate.google.com and for which the status is ‘OK’, and this is what we observe:
TAdAA…!!! we got it !!
This was the url where the request was sent:
Now most of the work is done , the only thing that remains is to generalize the request url and extract the desired ans from the response which is pretty simple.
This is a small C# code snippet that does everything for you:
string text="i am loving it";
string url = "http://translate.google.com/translate_a/t?client=t&text=" + text.Replace(" ", "%20") + "&hl=en&sl=en&tl=ta&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&sc=1";
WebRequest wr = WebRequest.Create(url);
Stream resp= wr.GetResponse().GetResponseStream();
StreamReader respReader = new StreamReader(resp);
string s = "",ans=respReader.ReadToEnd();
s = arr;
return s;// this is the translated text!!
Just change the variable ‘text’ to the sentence you want to translate. For translation to the language of your choice just look up the language code with the help of firebug and substitute it in place of ‘ta’ in ‘tl=ta’ in the request url.