Translate via Google from English to Korean and Back

Hi!

The following script should check if the selected text in Safari is English. If so, it should open http://translate.google.com/translate_t?hl=en#en|ko| with the text translated to Korean. If it’s not English, it should open http://translate.google.com/translate_t?hl=en#ko|en| and translate the text to English. But it doesn’t! And I can’t understand why…

tell application "Safari"
	set transText to do JavaScript "getSelection();" in document 1
	set theChars to the characters of transText
	if theChars contains "a" or "e" or "i" or "o" or "u" then
		open location "http://translate.google.com/translate_t?hl=en#en|ko|" & transText
	else
		open location "http://translate.google.com/translate_t?hl=en#ko|en|" & transText
	end if
end tell

Any insight is greatly appreciated!

If you need some Korean text to experiment on, try http://www.google.com/search?client=safari&rls=en-us&q=한글&ie=UTF-8&oe=UTF-8.

I’m thinking it has something to do with Safari’s cache of saved sites, insofar as the script will open whatever translate direction that I used last (i.e., Eng>>Kor or Kor>>Eng). How can I force it to open the correct site?

Nice one :slight_smile: !
But what do you mean with "doesn’t work! ?
Here, Safari 3.1.2 on Tiger 4.11, it works like (I suppose) it should…

Ciao
Farid

Browser: Safari 525.22
Operating System: Mac OS X (10.4)