Saturday, October 15, 2011

Word and text translation bookmarklet

Sometimes (I hope rarer and rarer :)) I need to translate an unknown foreign word on the page. I used to select it, open Google Dictionary Translate, paste it, set source and destination languages if needs and only then press the button to translate it.

Some time later I discovered bookmarklets. I liked the approach and made one for myself.

Drag this link En<>Ru the bookmark panel to be able translate words or text.

To change default source and destination languages put their codes in place of en and ru.

Source code.
(function() {
    var t;
    try {
        t= ((window.getSelection && window.getSelection()) ||
            (document.getSelection && document.getSelection()) ||
            (document.selection &&
            document.selection.createRange &&
        t = "";

    if(t && (t=t.toString()) && t.length){""+t+"#en|ru|"+t);

I used Javascript Compressor to get compressed version to use it in the bookmarklet.


  1. How do I use this same bookmarklet only for spanish translation into english

  2. You should change link in code to "|en&q="+t.
    And don't forget to obfuscate new code for bookmarklet.


Note: Only a member of this blog may post a comment.