📜 ⬆️ ⬇️

Google Translate Non Ajax API

Everyone knows the Google Translate service. It translates quite well, well, at least, so that you can understand.
So, didn’t anyone want to use the capabilities of Google translator for their own purposes?


For a start, I tried to solve all this with the adw0rd method. I decided quickly, but a lot of text did not pass. Everything was as he wrote. No more than 2 kb of text at a time. No, in fact it is quite acceptable, but I would like more. At least once in 16. And then I went by the method of the Old Moor. Sending request by POST.
I admit, I had to suffer ... About 2-3 minutes.

And that's what happened:
 QString translate (QString text, QString from, QString to)
 {
     QString url = QString ("/ translate_a / t? Client = t & sl =" + from + "& tl =" + to);
     QHttpRequestHeader header = QHttpRequestHeader ("POST", url, 1, 1);
         header.setValue ("Host", "www.google.com");
         header.setValue ("User-Agent", "Mozilla / 5.0");
         header.setValue ("Accept-Encoding", "deflate");
         header.setContentLength (text.length ());
         header.setValue ("Connection", "Close");

     QByteArray ba ("text =");
         ba.append (text);

     QHttp http;
         http.setHost ("www.google.com");
         http.request (header, ba);

     return QString (http.readAll ());
 }

')
Well, if, suddenly, you want to download in the form of a project that can be compiled into a dll and .framework, then here is the link:
ASTranslator (sources)

PS crosspost from my blog: Google Translate Non Ajax API

Source: https://habr.com/ru/post/52549/


All Articles