Skip navigation.

exploreopera

| Help

Sign up | Help

My program for Opera

Update google-translate.js.

google-translate.js
Sample of menu: menu_bbcode_english.ini.
Button: Translate to English

Go to Page,"javascript:ujs_google_translate('auto|en')",,,"Window Mail Compose Icon"


* Google now supports automatic language detection. Therefore you can use universal button or hotkey for translation from any language to English.
* First start more fast.
* Works in Opera 9.5 beta2


About installation UserJS written here.

Block javascript pop-upsCompatibility with Opera 9.50 "Final"

Comments

avatar
Apologies for being annoying, but I know nothing of Javascript and I've been trying to modify the button version of this script for hours with no notable successes. I've managed to change the name and icon, but more important to me is that I'd like to use only the URL translating (that is, ignore what I have selected and translate the referring URL) and to have the translation performed in the same tab as the original page. If these are as trivial as I expected them to be before I started trying to implement them, it'd be great if you could comment with the amended code; otherwise I'll just make do with this, thanks for the effort either way.

EDIT: OK, so I'm probably going about it completely the wrong way, but here's what I have so far:
<a class="button" title="Autotranslate" href="opera:/button/Go%20to%20page,%20"javascript:location.href='http://209.85.171.104/translate_c?hl=en&sl=auto&tl=en&u='+escape(document.location);",,,"Panel%20Notes"">Autotranslate</a>

However, for some reason the Google frame still appears, even though the link generated appears to be identical to the one Google generates for removing the frame. Perhaps it's a referrer thing? The Firefox translator extension doesn't display the frame when translating, so I'm not sure. I actually only went looking for a translator button because I found this extension while using the work computers, which run Firefox, and decided I wanted a similar functionality. I think I've almost got it, just need a bit more help.

EDIT2: Never mind, I've figured it out! Here's the code if anyone else is interested in my pointless downgrade of your version:
<a class="button" title="Autotranslate" href="opera:/button/Go%20to%20page,%20"javascript:location.href='http://209.85.171.104/translate_p?hl=en&sl=auto&tl=en&u='+escape(document.location);",,,"Panel%20Notes"">Autotranslate</a>

Or as a button: Autotranslate

It was simply a matter of changing translate_c to translate_p. Google redirects it to translate_c anyway, but the frame's not there, so whatever, I'm not complaining. Anyway, in short, this version uses the Panel Notes icon (which might look weird if you use Notes, I have that panel removed though, so the icon is free), shows the translation in the same tab, and removes the translation frame. As you might guess, I eventually started from scratch with simpler JS, thanks to my inexperience, but all credit for inspiration goes to you. Thank you.

By Vague_Rant, # 6. June 2008, 12:50:59

avatar
Anonymous writes:

Thanks pal, worked in 9.5 and really useful.

But EDIT2 buttton is not working on 9.5

Also can we make translate window bigger, it's very small I think.

By anonymous user, # 16. June 2008, 12:42:44

avatar
But EDIT2 buttton is not working on 9.5

What's it?
Also can we make translate window bigger

A size depends on the amount of text. You can change it.
{h = 15; w = 20; if(txtLen > 2000){h = 50; w = 66}else if(txtLen > 250){h = 25; w = 33};

h - height in percent from Opera window.
w - width in percent from Opera window.
txtLen - number of symbols in translation.

By Lex1, # 16. June 2008, 13:13:38

avatar
it works well~~
Thanks very much.

By seemille, # 17. June 2008, 03:11:16

avatar
Thanks now I can resize the window.

I mean this button in 9.5 opens a page with an error:

Autotranslate

By nizamx, # 17. June 2008, 10:15:15

avatar
nizamx
Paranoiacs work in my.opera.com team :smile: . They do blocking a word "javascript" in links.
Go to page, "javascript:location.href='http://209.85.171.104/translate_p?hl=en&sl=auto&tl=en&u='+escape(document.location);",,,"Panel Notes"

By Lex1, # 17. June 2008, 10:44:48

avatar
I added the button I selected some russian text and new page opened saying translating then gave this message:

Translation from English into English is not supported.

Also in 9.5 can't add custom icon from http://nontroppo.org/tools/buttonmaker/ in fact icon appears fine on that site but on Opera it always notes icon.

By nizamx, # 17. June 2008, 19:56:03

avatar
I selected some russian text

Where? Google translates majority, but not all of pages.
http://nontroppo.org/tools/buttonmaker/

Works for me.

By Lex1, # 18. June 2008, 12:16:05

avatar
Please add to your post button links:
Translate to French
Translate to Polish
Translate to Deutsch
...

:smile:

By adas, # 18. June 2008, 14:27:02

avatar
Well sorry, now it works but this button does not translate selected text but the whole page while your first button translates selected text in a window. Loading the whole page takes quite longer time considering I want to translate selected sentences only.

By nizamx, # 18. June 2008, 17:15:50

avatar
nizamx
Yes, Vague_Rant was needed exactly it. If you needed translations of selected text, use my button.

adas
«javascript:google_translate('auto|de')», etc.

By Lex1, # 18. June 2008, 17:49:30

avatar
Lex1: I know... But will better when you add to post. Then post will interesting for user non-english too...

By adas, # 18. June 2008, 17:54:59

avatar
http://lexi.ucoz.ru is not working!

By leoalassia, # 19. June 2008, 19:01:37

avatar
Works already.

By Lex1, # 20. June 2008, 07:49:24

avatar
thanks! it is great! I see a big improvement.

By leoalassia, # 20. June 2008, 21:35:49

avatar
The_blur writes:

Thank you for making this great update. I love being able to translate little snippets of text with the click of a button. The button works as a charm and can be easily modified to translate to any language other than English.

I was able to create a keyboard shortcut to transalte to English (Alt + E) and to translate to Spanish (Alt + S). Again, thank you very much for this update.

By anonymous user, # 24. June 2008, 18:24:12

avatar
Hi the_blur, how can you do that? (shortcuts)

By leoalassia, # 24. June 2008, 20:39:53

avatar
The_Blur writes:

leoalassia,

I'm sure you know how to create your own keyboard shortcuts already but if not, simply follow these instructions http://my.opera.com/Tamil/blog/add-modify-keyboard-shortcut

Once you're there, assign a key and as an action, enter the following (which is the same as the button):

Go to page, "javascript:if(typeof google_translate=='function'){google_translate('auto|en')}else{void(window.open('http://translate.google.com/translate'+(document.selection.createRange().text?'_t?text='+document.selection.createRange().text:'?u='+escape(location.href))+'&hl=en&langpair=auto|en&tbb=1'+(document.characterSet?'&ie='+document.characterSet:'')));}"

If you would like translate to some other language such as spanish, then just change anything that says "en" to "es". Then to use it, simply highlight the text you want translated and press the shortcut key you assigned to it.

By anonymous user, # 26. June 2008, 01:20:52

avatar
thanks! I didn't know I could add javascript code to a shortcut!
thanks for your help!

By leoalassia, # 26. June 2008, 12:16:58

avatar
Version 1.6.14 solved several bugs such as auto go bottom of page while translating, thanks for the update.

By nizamx, # 19. August 2008, 20:28:45

avatar
hi lex, I want to know where I have to add the code if I want to translate a text that it's a link too (because the context menu is different)

By leoalassia, # 22. August 2008, 03:45:07

avatar
leoalassia
[Link Selection Popup Menu]

By Lex1, # 22. August 2008, 08:27:52

avatar
I have another issue. If the text that I want to translate is into a frame, it doesn't work. (I'm talking about <frame> tags)

By leoalassia, # 26. August 2008, 18:12:15

avatar
frame

Yes, it well known problem for any js-buttons. You can use allow-ini-variables.js and button:
Button, "Translate to English"="Go to Page,"javascript:void(inivar='%t')",,,"Window Mail Compose Icon" & Go to Page,"javascript:ujs_google_translate('auto|en')" "

By Lex1, # 26. August 2008, 20:51:37

avatar
I'm sorry, but I did what you said and it doesn't works for me...
I've analized your code because the function's name in my google-translate.js is not ujs_google_translate (it's just google_translate), but I fixed it with your last update, so I don't know where I'm wrong

By leoalassia, # 27. August 2008, 04:21:01

avatar
Yes, you are right, it works only for iframe. I did small fix for this bug.

By Lex1, # 27. August 2008, 16:15:02

avatar
thanks! now it works, but I want the frame object (your 'f' var) into the same page (not open a new window), so I've made this add to your code:

line 87:
else if(t && location.hostname != 'translate.google.com' && document.body instanceof HTMLFrameSetElement){
...
...
document.frames[1].document.documentElement.appendChild(f);
}

so it works fine, but as you can see I'm getting the frame[1] because I know that this frame is what I want... :D

By leoalassia, # 27. August 2008, 18:15:50

avatar
Fine idea. I added similar check of text selection for frames in script.

By Lex1, # 28. August 2008, 14:22:10

avatar
Hi Lex, I have a problem in Opera 9.60 RC 1, when the text contains this character: ' there is an error in javascript because it expects ;

I am using "javascript:inivar='%t';ujs_google_translate('auto|es')"

so it seems that %t is not escaped

By leoalassia, # 7. September 2008, 00:38:18

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

Please type this security code : 770348

Smilies