The translation button from Google has proved to be very useful in most situation (by me), especially since the language detection was introduced. However, I feel that there is something lacking. The problem is that the translation generated replaces the current active window/tab while sometimes I prefer to have another window/tab open. The translation button itself is a JavaScript, so we can play with is just a little bit. Here is the original code for translation button (I use the code for translation into English):

javascript:
var t = ((window.getSelection&&window.getSelection()) || (document.getSelection&&document.getSelection()) || (document.selection&&document.selection.createRange && document.selection.createRange().text));
var e = (document.charset || document.characterSet);
if (t!='') {location.href='http://translate.google.com/translate_t?text=' + t + '&hl = en&langpair=auto|en&tbb=1&ie=' + e;} else {location.href='http://translate.google.com/translate?u=' + escape(location.href) + '&hl = en&langpair=auto|en&tbb=1&ie=' + e;};

In order to make the translation to be opened in a new window/tab, we just have to make a bit change in it:

javascript:
var t = ((window.getSelection&&window.getSelection()) || (document.getSelection&&document.getSelection()) || (document.selection&&document.selection.createRange && document.selection.createRange().text));
var e = (document.charset||document.characterSet);
if (t!='') {var myWindow=window.open('http://translate.google.com/translate_t?text=' + t + '&hl=en&langpair=auto|en&tbb=1&ie='+e,'Translation','')} else
{var myWindow=window.open('http://translate.google.com/translate?u=' + escape(location.href) + '&hl=en&langpair=auto|en&tbb=1&ie=' + e,'Translation','')};

If you hate this kind of stuff, just drag and drop the link below to your browser toolbar:
Translate to English

I hope this is useful. Please let me know if you have a better idea. Obviously, any questions are welcome.

edited: thanks for the suggestion

Related Posts

Related Posts by Categories



3 comments

  1. Anonymous  

    10:24 AM

    replace "window.open(..." with "var myWindow=window.open(..." and remove "var a = location.href;" and "location.href = a;"
    so no reopen of current page

  2. Ismail Habib  

    10:47 AM

    thanks, indeed it's better!

  3. John Free Web Design  

    8:01 PM

    I'm responding to an email I received from a French-speaking acquaintance. I've been able to cobble most of it together using Google translation and modifying the formal output to informal, and then feeding it back though just to make sure i didn't screw it up. But there are two pieces that i can't get right.

Post a Comment



Recent Entries

Recent Comments