Question

I have a text-box, and I want to enter a string in language A and send it to Google Translate. After Google has translated it, I want to take the new string (in language B) (after translation) and store it in some variable.

How can I do it?

Was it helpful?

Solution

The basic idea is shown in a simple example of Language Translation like this:

google.language.translate("Hello world", "en", "es", function(result) {
  if(!result.error) {
    var container = document.getElementById("translation");
    container.innerHTML = result.translation;
  }
});

translation is the id of your textbox. In this case where you put the translation result.

result is the translation itself. You can assign it to a new variable in any way you want.

In the above example you're translating "Hello world" from "en" (English) to "es" (Spanish).

The above code is written in JavaScript.

Take a look at Google AJAX Language API for more detailed steps.

OTHER TIPS

Read on Google AJAX Language API to understand how you can use Google's translation services programmatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top