Highlight2Translate

By fredar Last update Jan 1, 2009 — Installed 8,344 times.

request!

in
Subscribe to request! 8 posts, 6 voices



rfu Scriptwright

First of all, thanks for at great script!

Can we get some more control about where the "box" is showing?

 
fredar Script's Author

thanks
you can control the position of the box by change the source code a little bit,
first of all, find the lines of code:

window.div.style.left=(window.event.screenX+window.scrollX+10).toString()+"px"
window.div.style.top=(window.event.screenY+window.scrollY+10).toString()+"px"

and change it to

window.div.style.left=(window.event.screenX+window.scrollX+boxHorizonalPositionAwayFromCursor).toString()+"px"
window.div.style.top=(window.event.screenY+window.scrollY+boxVerticalPositionAwayFromCursor).toString()+"px"

for example:

window.div.style.left=(window.event.screenX+window.scrollX+100).toString()+"px"
window.div.style.top=(window.event.screenY+window.scrollY+100).toString()+"px"

Then the box will 100 px away from the cursor (horizontally and vertically)

 
avro User

Small request. I have an idea that I hope can be incorporated in your next update.

1) If the highlighted words are already the same language to be translated to, cancel script (or block the translation bubble from appearing).

2) If the highlighted words are not really words but instead text url links, or code (for example (window.event.screenY+window.scrollY+10) from above, this too cancels script.

Really nice script. Thank you.

 
DyNama User

i agree with avro. the box appearing for highlighted english translating it into english is the only reason i sometimes disable this script. i do occasionally highlight text for other reasons :-) otherwise this script is terrific!

 
666f6f Scriptwright

Great script, thanks.

I too find it inconvenient to translate everything I mark. My proposal is to translate only if a predefined key is pressed. For example Shitft+Selection.

 
666f6f Scriptwright
FirefoxWindows

Replacing if (window.text=="") return; with if (event.altKey || window.text=="") return; makes the translation popup to show up only if the Alt key is pressed.

 
moditripit User
FirefoxWindows

I disabled it for english because i want to translate to english only

in window.detectLanguage=function(result), i put an if statement around unsafeWindow.google.language.translate.....

window.detectLanguage=function(result) {
   window.text = window.text.toString()
   if (result.language != 'en')
     {
   unsafeWindow.google.language.translate(window.text,result.language,languageAfterTranslation.toString(),translateResult)
     }
   }

also, i changed window.div.innerHTML=window.text+": "+result.translation; to window.div.innerHTML=result.translation; in order to make it only show the translation

 
DyNama User
FirefoxWindows

thanx, moditripit! i made your changes and love it!