user2057343
user2057343

Reputation: 45

How to use Google translate API from code

I am trying to create an app that send a word to translate.google.com, take the result of the translation and display it to the user. I composed the URL but I do not know how to extract the word/phrase from the webpage.

Example pseudo: en is code for english and es is code for spanish

String from = "en";
String to = "es";
String word = "hello"; //this will be user input text really
String URL = "http://www.translate.google.com/#" + from + "/" + to + "/" + word;

Therefore the request URL will look like http://www.translate.google.com/#en/es/hello

I now need to be able to retrieve the information from the result box and place it in a String so I can display it to the user.

Upvotes: 4

Views: 14450

Answers (2)

nopenope
nopenope

Reputation: 41

You will get json response from this

https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=ru&dt=t&dt=bd&dj=1&q=hello

Here 'hello' is translated to russian

NO API KEY REQUIRED

Upvotes: 4

StarsSky
StarsSky

Reputation: 6711

Google translate provide API for retrieving translations. You should use json object and GET request to the google translate server. In this link you can find the official Developer's Guide with code examples.

Upvotes: 6

Related Questions