Added A Google Translate Widget to my Movable Type Blog

| No TrackBacks
translate-screenshot.pngThis weekend I added a custom Google Translate widget to my blog.  Even though I'm an extremely patriotic American, I still appreciate the rest of the world and the many languages it speaks.  As a result, I've tried to make it somewhat convenient for foreign visitors to translate my blog into their native language.  I implemented the functionality of the translate widget in JavaScript; using jQuery of course.  You can find the full JavaScript here.  But, here are the important pieces (the functions) that you might care about if you're trying to implement your own Google Translate widget:

var gT = "http://translate.google.com/translate?u=%u&sl=en&tl=%tl";

function isKolichDotCom(){
return window.location.href.indexOf("http://mark.koli.ch") == 0;
}

function setupTranslate(){
$("p.translateflag").click(function(e){
var href = encodeURIComponent(window.location.href);
var tl = $(this).attr("tl");
gT = gT.replace("%u",href);
gT = gT.replace("%tl",tl);
window.top.location.href = gT;
});
}

$(document).ready(function(){
if(isKolichDotCom()){
setupTranslate();
}
});

I'd love to turn this post into a HOWTO and explain more about how everything works, but I need to take care of some other things around the house.  Plus, my right wrist is recovering from a brutal week @work, so I need to keep computer use to a minimum right now (carpal tunnel).  Enjoy.

Did You Find this Helpful?

Did you find this post helpful, or at least, interesting?

  

Send Mark a Direct Message

If you'd like to send me a direct message, please do so below. However, I do not publicly post comments or messages submitted directly to me. So, if you're going to try to SPAM me, or my blog, you're pretty much wasting your time.

400 characters remaining

Error

About Mark

A Silicon Valley native, Mark Kolich is a full-time Software Engineer, a casual entrepreneur, and a consultant for hire. A web technologies expert, his current focus is on building powerful and robust cloud-driven web-applications using Java, PHP, Perl, AJAX, DHTML, CSS, and JavaScript. His favorite programming languages are PHP, Java and JavaScript. He uses Linux, enjoys biking to work, loves building great software, and always writes elegant, readable, and maintainable code.

No TrackBacks

No trackbacks attached to this entry.

Twitter (@markkolich)

Translate

About this Entry

This page contains a single entry by Mark Kolich published on March 15, 2009 3:54 PM.

HOWTO: Use jQuery To Install Firefox Extensions (InstallTrigger.install) was the previous entry in this blog.

HOWTO: Stop a BlueCoat Caching Web-Proxy from Caching Your Site is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.