Create Smarter Google Translate Keyword Bookmarks


Reader Jerry Lue read our feature on creating smarter keyword bookmarks, and took the initiative to create a set of smart bookmarks that interact with Google Translate. These keyword bookmarks either translate the current page, or even translate a phrase directly from the Firefox location bar.

Google translate a phrase:
This keyword bookmark lets you translate a phrase by simply entering it into the location bar—create a new bookmark with a keyword like trans, give it a name, and paste in the following javascript code:

javascript:strRaw="%s";strArray=strRaw.split("%20");for(i=3;i<strArray.length;i++){strArray[2] =strArray[2] +"%20"+strArray[i] ;};location="http://translate.google.com/translate_t?sl="+strArray[0] +"&tl="+strArray[1] +"#"+strArray[0] +"|"+strArray[1] +"|"+strArray[2]

Now you can use the bookmark with this syntax (you can also use "auto" as the source language).

trans <from lang> <to lang> <phrase>

As an example, you would use the following to translate the phrase "no hablo espanol" into English:

trans es en no hablo espanol

Google translate the current web page:
This bookmark works similarly to the first one, except you only need the to and from language:

javascript:strRaw="%s";strArray=strRaw.split("%20",3);location="http://translate.google.com/translate?prev=_t&hl=en&ie=UTF-8&u="+location.href+"&sl="+strArray[0] +"&tl="+strArray[1]

So to translate the current page from an unknown language to English, you would use the following (if you named the keyword "translate").

translate auto en

Intelligent translate:
The last version combines both techniques together, making a smart bookmark that detects whether you entered a phrase after the to/from languages and either translates the phrase or the current page.

javascript:strRaw="%s";strArray=strRaw.split(" ");if(strArray.length==2){location="http://translate.google.com/translate?prev=_t&hl=en&ie=UTF-8&u="+location.href+"&sl="+strArray[0] +"&tl="+strArray[1] ;}else{for(i=3;i<strArray.length;i++){strArray[2] =strArray[2] +"%20"+strArray[i] ;};location="http://translate.google.com/translate_t?sl="+strArray[0] +"&tl="+strArray[1] +"#"+strArray[0] +"|"+strArray[1] +"|"+strArray[2] ;};

These bookmarks just barely show off the power of this technique, and we'd love to hear some of your ideas for powerful keyword bookmarks that show off the command line comeback. Thanks, Jerry Lue!


Comments

Be the first to comment on this story!

Trending Stories Right Now