A 316 characters snippet to translate your Twitter timeline

Open your Twitter page then copy and paste this snippet in your browser location bar to translate your Twitter timeline in english :
javascript:$.getScript("http://www.google.com/jsapi",function(){google.load("language","1",{callback:function(){$(".entry-content").each(function(){var a=$(this),b=google.language,c=a.html();b.detect(c,function(d){d.language&&b.translate(c,d.language,"en",function(e){e.translation&&a.html(e.translation)})})})}})});
To translate in another language, search for the string "en" in the snippet and replace it by any language enum of the Google Translate API : http://code.google.com/intl/fr/apis/ajaxlanguage/documentation/reference.html#LangNameArray This is the compressed version of this script :
$.getScript('http://www.google.com/jsapi', function() {
    google.load('language', '1', {'callback':function() {
        $('.entry-content').each(function(){
            var $self = $(this), l = google.language, text = $self.html();
            l.detect(text, function(r) {
                if (r.language) {
                    l.translate(text, r.language, 'en', function(r) {
                        if (r.translation) {
                            $self.html(r.translation);
                        }
                    });
                }
            });
        });
    }});
});
This entry was posted on Monday, June 21st, 2010 at 6:20 pm and is filed under JavaScript. You can follow any comments to this entry through the RSS 2.0 feed. You can leave a comment, or trackback from your own site.

2 comments

Leave a comment