The Google AJAX Language API is Going to be a Big Deal
Update: I've completed a Drupal module that will make all comments on your site translatable using the API. You can download it from the Attachment section below.
Update II: It is now official Drupal module.
Today, Google released their AJAX Language API.
These are interesting times for anyone who cares about foreign language translation on the Web. This paragraph is available in any language that Google is able to translate from English. Try it. Click the links in the top right to see it transform to Italian, Spanish, French, Portuguese, and back to English again. Download the script below. Put it to work on your own blog, or better yet, improve it somehow. Or, leave a comment and let me know how you imagine the API could be put to good use.
I've spent considerable time imagining what the Internet would be like if it had a truly open translation API unleashed upon it. Imagine a Web service to which anyone could send a chunk of text, in any language, and get back the same text in some other language.
Seems simple, but for a while, this was surprisingly hard. Google had done it, but only interactively - you had to go the Google Translate page, copy and paste your text, submit the form, copy the result, and paste it somewhere else.
Things started to look more promising when I found the Unofficial Google Translate API. You could programatically send it a string and a language pair, and some JavaScript would hand you the result, but only by querying the same old Language Tools page you used to visit, and trimming away the HTML around the result.
Worse, Google appeared to have some sort of referer filtering in place. I could translate things from a static page on my local machine, but when I tried to build a Facebook app to implement it, I discovered that the endpoint wouldn't respond to requests originating from my web host.
I gave up for a while. That was reality. But back to cool things we could imagine:
- A Facebook app that would let you write a blog or wall post, and translate it with one click, to the language of your choice, before submitting it.
- Reading Twitters by your friend, who only speaks German, and being able to translate them into English without copying and pasting anything.
- Learning Portuguese by reading Brazil's equivalent of the New York Times, translating it to English to check your comprehension paragraph-by-paragraph.
- Configure a language pair for each of your GMail contacts. They write in French, you read in German, seamlessly.
- A Drupal module that creates automated translations of every new node for every language you have installed.
Well, Google has made things interesting again. Too bad my imagination is too big for my PHP and JavaScript chops. I wish I knew enough to plow through Facebook's FBJS architecture - I couldn't figure out how to load and initialize the language API because Facebook prepends the application ID to all my identifiers. I also wish I knew enough to load the API in a Greasemonkey script. But I'm hoping someone else will.
The script I'm using here uses jQuery to gather all elements of class "translatable" and build a series of links that issue AJAX requests for the respective languages. It would be nice to dynamically change the links to reflect the available destination languages only - German, for instance, can only be translated to English or French. It would also be nice if it didn't completely munge children of the DOM element being translated. But this is my first time really getting my hands dirty with jQuery. It's incomplete, it's buggy, but it's an exciting start.
| Attachment | Size |
|---|---|
| translate.js_.txt | 845 bytes |

Comments
Comments are now translatable as well.
Well done, Dave!
Thanks for commenting on my AJAX Translation WordPress Plugin!
I really like your idea about Facebook and twitter. 500 characters limit sound perfect for these shout wall posts or status.
I was thinking use uOGT in another day, but found my website will be soon rejected by Google Translate Service. This AJAX one really helps!
Your implementation looks great!
Looks great dave!
If i wanted to try it for myself, where could I download the script?
Great work mate!
@clee
The script to make arbitrary elements translatable is in the Attachment section above, or: http://minimalmedia.com/files/translate.js_.txt
Add it to your page and mark up some elements with
class="translatable".The Drupal module in Attachments will make all of the comments on your site translatable.
I am totally ignorant about jQuery so I was wondering what are prerequisites to implement your jQuery plugin on a website.
is there any non-JQuery version as well? I am more interested to know how did you keep text formation "alive" while translating text between tags?
Hi, Pretty wicked! I've converted your script into an Mediawiki extension that translates selected RSS feeds on request.
Check: http://delft.campuswiki.nl/en/Housing:Marktplaats
This sample is an RSS feed from marktplaats.nl (the Dutch equivalent to eBay) where the 'to let' postings are mostly in Dutch.
Only too bad that it does not work on internet exploder !
Greetings,
Thatcher
Great stuff Dave!
I will look at having to implment your solution
Ciao,
vMarcus
How can i translate more than 500 characters to a long text, with this script? Thanks
I used Google AJAX Language API to develop Free Online Translation Service page which use Google AJAX Language API. I also used Google AJAX Language API to translate the user interface of Online Translation Service to the following languages: English, Arabic, Bulgarian, Chinese, Croatian, Czech, Danish, Dutch, Finnish, French, German, Greek, Hindi, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Romanian, Russian, Spanish, Swedish.
Post new comment