Powered by Blogger.

How to Translate Text to desired language?


Just follow these steps and copy & paste the code you can translate text easily.

Step 1: Make a div with id (id is compulsory)
Like <div id="content">Loading…</div>

Step 2: Paste the following code to the head section under the script tag of your webpage.
google.load(“language”, “1”);

function initialize() {
var content = document.getElementById(‘content’);
// Setting the text in the div.
content.innerHTML = ‘<div id=”text”>Place Your Text Here (Hola, me alegro mucho de verte.)<\/div><div id=”translation”/>’;

// Grabbing the text to translate
var text = document.getElementById(“text”).innerHTML;

// Translate from Spanish to English and have the callback of the request
// put the resulting translation in the “translation” div.
// Note: by putting in an empty string for the source language (‘es’) then the translation
// will auto-detect the source language.
google.language.translate(text, ‘es’, ‘en’, function(result) {
var translated = document.getElementById(“translation”);
if (result.translation) {
translated.innerHTML = result.translation;
}
});
}
google.setOnLoadCallback(initialize);

Step 3: And the final step is to paste the following URL in src of the script tag.
http://www.google.com/jsapi?key=AIzaSyA5m1Nc8ws2BbmPRwKu5gFradvD_hgq6G0

The above example is translating Spanish to English You can translate as your choice.
Just change the code in
google.language.translate(text, ‘es’, ‘en’, function(result)
es stands for Spanish,
en stands for English
You can find more language code at http://code.google.com/apis/language/translate/v1/reference.html

No comments