Softpedia
 

NEWS CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
Home > News > Webmaster > Tips and Tricks

March 22nd, 2008, 13:11 GMT · By Catalin Bocanu

Automatic Text Translation with Javascript

SHARE:

Adjust text size:


Google Language Learner
Enlarge picture
If you publish the text content of a website in multiple languages, the
chances of having more visitors will be increased. There are many alternatives to provide multilanguage support for a given website and in this direction automatic translation methods will decrease the time of content publishing.


Google AJAX language API (application programming interface) allows you to translate various words or phrases from 13 languages using 29 translation pairs. Besides the text translation, Google AJAX language API gives you also the opportunity to perform the language detection using only Javascript. This method is a very efficient alternative for offline translations tools.

Regarding the implementation of Google AJAX Language API in your own HTML pages, applications or scripts, let's consider the next Javascript code integrated in a HTML page:

CODE

Google AJAX Language API Usage Example


google.load("language", "1")
function translate() {
google.language.translate("The First Automatic Translation", "en","fr", function(output) {
alert(output.translation)
})
}
google.setOnLoadCallback(translate);








In order to add the Language API in your page head (the loader will include all the Google APIs (line 4)), you must specify the Javascript directive google.load("language", "1"), which will load the version 1 of Google AJAX Language API. The function translate will allow the translation of the string 'The First Automatic Translation' from English to French. The translation result will be displayed in an alert window. The directive google.setOnLoadCallback(translate) will permit you to use API functions after the page has loaded. If you comment the google.setOnLoadCallback(translate) line by adding // characters in front of it, you will notice that after recalling the page in your browser address bar, the alert window will not appear after the page loading.

In this situation, you can use the Translate button. The corresponding code situated into the page body tags demonstrates how to call a Javascript function from HTML. You can change the script by adding the corresponding Javascript directive for language detection of translation output. For more information, you can check the Google AJAX Language API documentation.

TELL US WHAT YOU THINK:

23,834 hits · 3 comments · Link to this article · Print article · Send to friend · Subscribe to news

MUST-READ RELATED ARTICLES:


ManagedQ Search Application

A New Functionality for Google Navigation Toolbar

Get a Simple Blog Application for Beginners

Useful Secrets of Gmail Service

A Promising Alternative for Google Reader

READER COMMENTS:


Comment #1 by: webprogrammer on 24 Mar 2008, 04:38 UTC reply to this comment

Well, its pretty nice stuff. But I think you have missed out a very important point to mention. This service is does not support more than a 500 character request. Neither they are planning to increase the limit in near future.
see this,
http://groups.google.com/group/Google-AJAX-Search-API/browse_thread/thread/036689f97278375e#

Thanks
-Webprogrammer


Comment #2 by: Sur'at on 19 May 2008, 12:22 UTC reply to this comment

HI!
This program is very nice.
I have a little problem.
I must to find more information about text translators.
If have it please send my mail.
Thank you!
Bye!


Comment #3 by: aa on 03 Oct 2011, 08:41 UTC reply to this comment

aaa bbvbgfn ngnng ngn gng

Copyright © 2001-2012 Softpedia. Contact/Tip us at

WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM