Yesterday, while browsing the Google blog, I stumbled across a recent entry they did regarding the release of their new AJAX language API. While reading it, I had a couple of crazy ideas what it could potentially be used for. One of those ideas was to dynamically translate content on my blog.
So after grabbing a bite to eat on my way home tonight, I decided to take a stab at creating a Wordpress plugin that would automatically translate content on the fly. My basic game-plan was to grab the HTTP header associated with the user’s language, intercept a few Wordpress locations, and do some dynamic translating of the content. I just wanted to do the titles at first, thinking that would be enough. But to be honest, I was so excited after getting that working that I decided to take a stab at the rest of the content on my blog, including posts, excerpts, categories, and tags.
It wasn’t easy. One of the major problems I had was the failure of the Google API to translate any content with HTML tags in it (which obviously makes sense, but makes it difficult to translate dynamic content littered with it). So what I ended up having to do is decompose the content into text fragments, translate those, and then recompose it back together with the appropriate markup.
The result, after about three hours, is a blog that translates itself to whatever language you are trying to view it in (assuming of course Google supports that language). If you want to test it out, you should be able to use Firefox. From the preferences panel, choose “Advanced”, “Languages”, and pick a new language to view the blog in (making sure to move it to the top of your list). If you stick with a well known language and refresh on this blog, you should see most of the dynamic content on this blog magically transform into the language of your choice.
If you don’t have Firefox, you can head on over to my Flickr set to view a few photos.
I think this plugin is actually pretty elegant. If you consider how it works, it’s basically dynamic content driving server side scripts which in term drive the creation of dynamic client-side Javascript that ultimately performs the translation. Dynamically.
And while that by itself is really exciting to me, there’s another benefit that’s subtle but has the potential to really change how blogging is done. If you leave out the source translation language identifier in the API call for the translation, Google will automatically try to detect it for you. That feature is fairly useless if I write all the content on my blog myself and always stick to my primary language (since auto-detection will always come up with that language), which is the typical case for most people. However, if you couple a blog that can translate itself for every user and add the ability to auto-detect what language they commented in, you can then allow users to comment in their native language, and automatically translate it for everyone else. Quite simply, it allows for language independent information sharing.
A Reader Leaves A Comment In Chinese
Comment Translated To English When Viewed In EnglishThere are obviously a few bugs, and I have to give some major thought to the big picture. But as a proof of concept I think it’s pretty exciting. I posted a few comments below in various languages. If all is well, they should be translated to english for you (assuming you are viewing the blog in english). Obviously there are some subtle translation differences, but for the most part the meaning still comes across. If you don’t believe it, view the HTML source — you should see the comments in their original languages prior to the AJAX translation.
Ultimately this plugin will end up over on BraveNewCode, a place where Dale Mugford and myself are going to throw all the really cool things we’re working on in our spare time.
* Update - head over to the official Wordpress Without Borders page to download an alpha version of the plugin.
note: multibyte strings should work as well, but there appears to be a bug in Wordpress 2.5 that’s limiting my use of them below — this works in Wordpress 2.3.3 though
|
32 comments
|
A “byte” you say? I guess it deserves a chuckle.
I like the Russian even though I can’t read a word of it, i think it’s the way the font is.
i recognized the new api last week and gave it a test, too.. it`s really working great.. nice try.. i`m the same opinion like you, it could be a really great thing and make a lot of things very easy..
wünsche dir einen schönen tag ;)
liebe grüße
Chris
Well, I could leave my comments in seven different languages but I don’t have the keyboard to leave it in Japanese :)
WHOA. this is flippin’ sweeet. I was just loking at a WP translation plugin yesterday but this? Oh man, the languages translated before my eyes…
If you need a tester, pick me! pick me! :D
Very impressive!
And what’s more, seeing this here, I wonder why practically every website doesn’t do this (newspapers, forums)? And how long until they do?
Good innovating man!
you`re right, Duane Storey :) of course.. es macht aber auch viel spaß und auf deutsch geschrieben klingt mein deutsch auch etwas normaler und nicht so naja bisschen seltsam ;) aber es ist wirklich innovativ.. ich seh schon foren plugins kommen, blog plugins, das übliche.. vielleicht wirds ein trend werden, wer weiß.. ;)
It would be cool if translated comments could be marked somehow (flag icon?). And if the end-user could choose to view a comment in it’s original language on the site. For example I speak both English and Spanish and would prefer to read both of those languages without translation even though I have my browser set to English. It would be nice to click an icon to remove translation on a given comment especially if I could quickly identify it’s original language.
Even simply marking that comments have been translated would clarify communication. I could imagine for example a pedantic commenter correcting someone’s translated grammar or worse confusion stemming from the assumption that a given commenter meant exactly what they wrote even though we are not reading exactly what they wrote.
Por ejemplo, este comentario esta en espanol.
And the rest is in English.
Wow! I changed to Spanish and seeing it translate inline was really, really cool. Great job with this. Are you going to be open sourcing the code?
[...] Duane Story has put together a proof of concept on a self-translating blog using the new Google Ajax Language API - Wordpress without Borders. [...]
Wow, loving this plugin! I’ve tested it out and it works nice in French, Spanish and Chinese (I have a firefox plugin that switches the user agent around). Translations are slightly dodgy but as you said the meaning is still there! Having said that there are some interesting chinese comments going on here - my girlfriend (who is chinese) was a bit perplexed!
The one thing I would be careful about is forcing the translation on a user - sometimes people would probably just prefer to read the article in english (even if it isn’t their native language).
Look forward to seeing this being released!
So… how does one turn this *off*? Just because my system is set to Dutch doesn’t mean I can’t read English… and I’d rather not read your blog as a series of badly mangled pseudo-Dutch phrases or be forced to change my entire system language.
Machine translation as a last resort? Sure. But machine translation by default? Horrible idea.
It also seems rather silly that the code for this repeats the same code snippet over and over again with only a single ID changed, instead of just looping over an array of content to translate. It adds 36KB to this page.
[...] Without BordersTitle Tags And WordpressWordpress 2.5 BetaMedia Burner Beta Wordpress Without BordersTitle Tags And WordpressWordpress 2.5 BetaMedia Burner [...]
chupa mi pinga carajo
[...] This use of Google’s new AJAX language API with WordPress is absolutely fantastic. I can’t wait to try my hands at it. [...]
Does it… does it work in Klingon?
Cool idea… I’ll be interested to see how long it takes for private newspapers and online journals to implement something like it.
By the way, you’ve got a bunch of code showing at the bottom of the page :P
I have to say this is by far the the coolest plugin I have seen! I can’t wait to see this one built. I’ve been looking for a translator plugin for a while and haven’t found any I like that actually function properly. This is going to be really cool… can’t wait to see it finished.

Del.icio.us
Digg