Read Googlified in Multiple Languages
API, HowTo March 23rd, 2008 - By HaochiTraditionally, translating a blog post requires sending your readers to translation services, such as Google Translate and Babel Fish. However, with the revolutionary Google Language API, you can offer content in several languages right on your website now and better experience for the readers.
Due to the fact that I have too much free time during the Spring Break, I wrote a small piece of JavaScript code that uses the API to translate posts on this blog. You can test it out on this blog. It works in Windows’ version of Firefox 2, Internet Explorer 7, Opera 9, and Safari 3, but it should work wherever the Google Language API works (but works better in FF & Opera in my tests).
Well, if you also want to have this cool tool on your site, I packed all the necessary files that you need to set the thing up into a 10kB .zip file, which included the script itself, a readme file, and a couple of flag icons by Mark James of Famfamfam.
Once again, this is not the greatest solution, but it works - brought to you by Haochi.



March 23rd, 2008 at 10:55 pm
Great job! will try this later. Thanks!^_^
March 24th, 2008 at 3:35 am
Well done!
March 24th, 2008 at 8:24 am
Hi,
Great job! :)
I am thinking in implement your code in my WordPress Blog. Do you know if it can cause some slowness in the site loading?
Thank you. Have a nice day. :)
March 24th, 2008 at 11:16 am
@Ken & Tom
Thanks. :)
@Marcos
No, it won’t slow down the loading of the page, if you include the Google Language API and my script right before the closing of the body tag, so that it will only start loading when all your other contents are loaded.
March 24th, 2008 at 12:29 pm
Hi Haochi,
Thank you very much for your help.
And also thank you for the script. :)
March 24th, 2008 at 1:21 pm
Hi Haochi,
How can I know what is the “translateClass” that my site uses?
Thanks! :)
March 24th, 2008 at 2:14 pm
@Marcus
That would be “postContent”, but unfortunately it seems like that the content on your site is way too long for the API so the translation wouldn’t so up. (for example, it wouldn’t work on the home page but works on the About/Sobre page.)
I am not sure why, but when the content is over a certain length, the translation wouldn’t show up although part of it is correctly returned. I will look into that later.
If you choose to use it, you might also want to find ‘en’ (with the single quotes) and change it to ‘es’ (also with the quotes) and add English in the languages variable.
March 24th, 2008 at 3:03 pm
Hum, I understood, Haochi.
I will take a look on this.
Thank you very much. :)
March 26th, 2008 at 8:45 pm
I just hacked together a plugin for a tool that let’s you chat with visitors to your website using any jabber client, http://www.hab.la. If you have a lot of international visitors and want them to be able to read your blog, and be able to carry on poorly translated chats with you, you might want to check out my blog post on the subject: http://hab.la/blog/articles/2008/03/26/now-hab-la-gives-you-one-of-those-un-earpiece-thingys-autotranslate-rocks
May 20th, 2008 at 6:18 am
Hi ,
I am not able to run it. Can u please Help me on this.
What should I use in ranslateClass and un place of key=YOUR_API_KEY_HERE.. I am a newbee so please help
Thanks & Regards,
Abhay K. Singh
July 24th, 2008 at 9:58 am
Nice ~~
Google Language API also offers a REST based API that you could call to programmatically translation, which truely becomes handy because you won’t put the load javascript efforts onto every user of your website.
Also there are some limitations on the length of characters you could translate using the rest api, but during the development of http://www.thetruechina.com/, we found that you could split the contents into several pieces and do translation seperately.
Hope this helps,
Alex