Twitter Translation

Published:

My friend Britt mentioned today that he was about to launch twitter.jp. How exciting! But I don't understand Japanese. If only I could easily translate all those tweets in languages I don't understand.

I played around with Google's new AJAX Translation API before and I wondered how hard it would be to use that from a GreaseMonkey script. The answer: hard. I'm not sure what the exact problem was but every way I tried to include Google's APIs into the pages I was manipulating, including creating my own iframe and using document.write failed. In the end I used a static proxy html file (hosted in one of my Amazon S3 buckets for cheap efficiency) with some sneaky cross-site communication (the request goes over in location.hash, the response comes back in window.name).

My script is now up on userscripts.org: twitlator.user.js

To use it simply go to a page listing a bunch of tweets, like the public timeline and find a tweet in a language you don't under stand. For example:

Click the translate! link and several moments later you've got:

Yep. People aren't posting anything interesting in Japanese either.

I'm pretty sure my script will only work on Firefox 3. I'm using getElementsByClassName which I think wasn't introduced until Firefox 3. Why aren't you running it already?