Translation Using Google AJAX API
Today i need a translation of a English word to hindi,I use the google translator for doing that.But I want that to do in my localhost.So i read through the Google AJAX API to do that.
Now Translation would be very easy using the Google AJAX API.Here is the Hello World program to do that.
First load the Google Translator API to our page
<script type=”text/javascript” src=”http://www.google.com/jsapi”>
</script>
Then this is the script for communicate with the API
<script type=”text/javascript”>
google.load(“language”, “1″);
//Initialise the translation
function initialize() {
//Fetch the text to translate
var text = document.getElementById(“text”).innerHTML;
//Convert to english(en) to hindi(hi)
//Note:Instead of ‘en’,'hi’ u put the available language codes.
//Then the Callback function is called to write the translated text.
google.language.translate(text, ‘en’, ‘hi’,
function(result) {
var translated = document.getElementById(“translation”);
if (result.translation) {
translated.innerHTML = result.translation;
} } );
};
google.setOnLoadCallback(initialize);
</script>
Put this in your html body tag.In this the id “text” (i glad to see you) is converted to Hindi and fix it in id “translation”.
<body>
<div id=”text”>i glad to see you</div>
<div id=”translation”></div>
</body>
Thats it save the above script and Translate by yours.
Source & Documentation @: http://code.google.com/apis/ajaxlanguage/documentation/