10

I'm using Translate Client on Windows. This tool instantly get translation of selected text in any application by double press Ctrl What are alternatives for Mac OS X?
Good implementation would be as in Dictionary (select word Command+Control+D) enter image description here

UPDATE:

  1. http://www.yuriev.info/translator/translator.zip
    Article about this enter image description here
  • Are you looking for specific features, or does a basic service hacked together in 5 minutes suffice? – Daniel Beck Jun 13 '11 at 10:09
  • I'm looking for program that give me easy way to use google translate from any place in osx like it do translateclient.com under Windows. – diimdeep Jun 13 '11 at 10:15
  • Just a hint, the people most qualified to answer your question likely don't even have a Windows machine. "like this other thing you've never heard of and can't even try yourself" is therefore not a good idea if you want good answers. – Daniel Beck Jun 13 '11 at 10:25
  • 1
    Google has deprecated the Google Translate API, so there's unlikely to be nicer solutions than the one I suggested, that will still work in 2012. – Daniel Beck Jun 13 '11 at 13:11
  • 2
    UPDATE June 3: In the days since we announced the deprecation of the Translate API, we’ve seen the passion and interest expressed by so many of you, through comments here (believe me, we read every one of them) and elsewhere. I’m happy to share that we’re working hard to address your concerns, and will be releasing an updated plan to offer a paid version of the Translate API. Please stay tuned; we’ll post a full update as soon as possible. googlecode.blogspot.com/2011/05/… – diimdeep Jun 13 '11 at 13:15
11

Open /Applications/Automator.app, select to create a new Service, double-click Run AppleScript from the Utilities library, and enter the following script code into the text field:

on run argv
    tell application "Safari"
        make new document at end of documents
        set URL of document 1 to "https://translate.google.com/#view=home&op=translate&sl=en&tl=es&text=" & item 1 of argv
    end tell
end run

Save as Translate to Spanish.


Now you can select text in any application, and select Translate to Spanish from the context menu, or the Application » Services menu. A new Safari window will open, with the selected text as input to Google Translate.


You can assign a keyboard shortcut in System Preferences » Keyboard » Keyboard Shortcuts » Services.


Selecting from context menu (it's a submenu since I have too many applicable services, you can disable some in System Preferences):

enter image description here


The following page opens after clicking the menu item:

enter image description here

| improve this answer | |
  • Woow, that is very good. but it will be better if translation just appears in small popup. – diimdeep Jun 13 '11 at 10:47
  • @diimdeep That's why I asked for specific criteria. – Daniel Beck Jun 13 '11 at 11:04
  • This script doesn't work for me on macOS 10.12.4. Safari just opens a blank window. – Justin Searls Apr 9 '17 at 16:41
  • @JustinSearls Well, it worked six years ago. Note that due to the dependency of the exact URLs of a web service, this could always break (in fact, on my Mac it still works, but just opens translate.google.com with no translation). – Daniel Beck Apr 9 '17 at 19:57
3

I'd prefer a native application or a ⌃⌘D-style panel as well. But for now I'm using this AppleScript:

try
    tell application (path to frontmost application as text)
        set ans to text returned of (display dialog "" default answer "ja ")
    end tell

    set offs to offset of space in ans
    set i1 to text 1 thru (offs - 1) of ans
    set i2 to text (offs + 1) thru -1 of ans

    set sl to "en"
    set tl to "en"
    set z to offset of "-" in i1
    if i1 is "-" then
        set sl to "auto"
    else if z is 0 then
        set tl to i1
    else if z is (count i1) then
        set sl to text 1 thru -2 of i1
    else
        set sl to text 1 thru (z - 1) of i1
        set tl to text (z + 1) thru -1 of i1
    end if
    set base to "http://translate.google.com/#"
    set u to base & sl & "|" & tl & "|" & urldecode(i2)

    tell application "Safari"
        activate
        open location u
    end tell
end try

on urldecode(x)
    set cmd to "'require \"cgi\"; puts CGI.escape(STDIN.read.chomp)'"
    do shell script "echo " & quoted form of x & " | ruby -e " & cmd
end urldecode

The web client has some features that are essential to me, like transliterating text to the latin alphabet from other writing systems, and providing alternative translations for single words.

Extra: minimal userstyle for Google Translate.

| improve this answer | |
3

Open up Automator
Select Service
Select Utilities under Library
Select Run Shell Script
On the 'Shell:' dropdown menu, select '/usr/bin/ruby'
Type into the textbox:

require 'cgi'<br>
`open 'http://translate.google.com/#auto/en/#{CGI.escape(STDIN.read.chomp)}'`

Save the script as 'Translate to English' or whatever

Now, right clicking on any highlighted text and selecting 'Translate to English' will open up a new Google Translate page with the highlighted text translated into English.

| improve this answer | |
  • Kudos, this one actually still works. – Justin Searls Apr 9 '17 at 16:43
1
  • Open Automator
  • Create a new "Service"
  • Select Utilities → Library → Run Shell Script
  • Choose /usr/bin/ruby and paste this script:

    require 'cgi'
    system("open 'http://translate.google.com/#auto/en/#{CGI.escape(STDIN.read.chomp)}'")
    
  • This is what you should get:

    script interface

  • Save it under name "translate"

    Save it under name "translate"

  • Now you can translate any text:

    Translate any text

| improve this answer | |
0

A version of EN-RU translation for Google Chrome

on run argv
    tell application "Google Chrome"
        set myTab to make new tab at end of tabs of window 1
        set URL of myTab to "http://translate.google.com/#en|ru|" & item 1 of argv
        activate
    end tell
end run

And a keyboard shortcut trick still works perfectly (El Capitan). You'll find your new service in the list of services, end of "Text" section: enter image description here

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.