Introduction
This article will give a brief description of how to create a multi-language text editor which will convert the word typed in English into desired language using Google Transliteration API. It will not only show text into the translated language, but will also submit the exact Unicode values corresponding to that language.
Google Transliteration API
Google Transliteration API service is an API service provided from Google labs which helps to transliterate the text. It provides AJAX API interfaces to interact with the service. We can translate between many languages including more than 70 international languages. It translate word by word, not the whole sentence.
The "Hello, World" of the Google AJAX Language API
Including the AJAX Language API on Your Page
To include the AJAX Language API in your page, utilize the Google AJAX API loader. The common loader allows you to load all of the AJAX APIs that you need, including the language API. You need to include both the Google AJAX APIs script tag and call google.load("language", "1"):
The first script tag loads the google.load function, which lets you load individual Google APIs.
google.load("language", "1") loads Version 1 of the Language API. Currently, the AJAX Language API is in Version 1, but new versions may be available in the future. See the versioning discussion below for more information.
Language Translation
Use google.language.translate method translate a English text string to some other language:
google.language.translate("Hello world", "en", "es", function(result) {
if (!result.error) {
var container = document.getElementById("translation");
container.innerHTML = result.translation;
}
});
Here in the translate method, first argument is the string in English that needs to be translated. Second is the source language code. Here it is “en” which signifies English. Third is the destination language “es” which is Spanish. For a complete list of supported languages and codes, please refer to http://code.google.com/apis/ajaxlanguage/documentation/referenceTransliteration.html. Fourth argument is the callback function with will be called as soon as we get response from Google. Here result is the response.
More examples
Transliterate text area
The following example enables transliteration in a textarea with language as Hindi, so that users can type in Hindi using an English keyboard. For information on selecting a different language, see the API class reference in http://code.google.com/apis/ajaxlanguage/documentation/referenceTransliteration.html#LanguageCode
This article will give a brief description of how to create a multi-language text editor which will convert the word typed in English into desired language using Google Transliteration API. It will not only show text into the translated language, but will also submit the exact Unicode values corresponding to that language.
Google Transliteration API
Google Transliteration API service is an API service provided from Google labs which helps to transliterate the text. It provides AJAX API interfaces to interact with the service. We can translate between many languages including more than 70 international languages. It translate word by word, not the whole sentence.
The "Hello, World" of the Google AJAX Language API
Including the AJAX Language API on Your Page
To include the AJAX Language API in your page, utilize the Google AJAX API loader. The common loader allows you to load all of the AJAX APIs that you need, including the language API. You need to include both the Google AJAX APIs script tag and call google.load("language", "1"):
The first script tag loads the google.load function, which lets you load individual Google APIs.
google.load("language", "1") loads Version 1 of the Language API. Currently, the AJAX Language API is in Version 1, but new versions may be available in the future. See the versioning discussion below for more information.
Language Translation
Use google.language.translate method translate a English text string to some other language:
google.language.translate("Hello world", "en", "es", function(result) {
if (!result.error) {
var container = document.getElementById("translation");
container.innerHTML = result.translation;
}
});
Here in the translate method, first argument is the string in English that needs to be translated. Second is the source language code. Here it is “en” which signifies English. Third is the destination language “es” which is Spanish. For a complete list of supported languages and codes, please refer to http://code.google.com/apis/ajaxlanguage/documentation/referenceTransliteration.html. Fourth argument is the callback function with will be called as soon as we get response from Google. Here result is the response.
More examples
Transliterate text area
The following example enables transliteration in a textarea with language as Hindi, so that users can type in Hindi using an English keyboard. For information on selecting a different language, see the API class reference in http://code.google.com/apis/ajaxlanguage/documentation/referenceTransliteration.html#LanguageCode
No comments:
Post a Comment