The Dictionary App has a very cool experience on MacOSX. But I have to install dictionaries to use. Is it possible to bind it to Google Translate?

Thanks!

  • It doesn't look like it would work, at least without extensive hacking and rebuilding of the Dictionary app and extension because as it stands custom dictionaries are static and aren't programs which means that I can't just write a "dictionary" which takes the text and translates. – Sirens Nov 9 '15 at 2:04
up vote 22 down vote accepted

Unfortunately it doesn't appear to be possible, or at least straightforward. As an alternative, you may want to consider creating an OS X Service that opens Google Translate in a browser window, for any highlighted word or phrase you have selected.

If this sounds suitable, follow the procedure below:

Creating a translation Service

  • Open the Automator app from your Applications folder
  • Select Service as the type of document and click Choose
  • In the window that appears, click the search field and type 'AppleScript'
  • Drag and drop the Run AppleScript action from the list on the left into the area labelled 'Drag actions or files here to build your workflow'

Copy the script below and paste it into the Run Applescript action:

on run {input, parameters}
    set phrase to input as string
    set phrase to quoted form of phrase

    set ui_lang to "en"
    set from_lang to "en"
    set to_lang to "zh-CN"

    do shell script "open 'https://translate.google.com/?hl='" & ui_lang & "'&sl='" & from_lang & "'&tl='" & to_lang & "'&text='" & phrase
end run

Your window should look like the following:

Automator workflow

There are three values that you may want to change in the above script:

  • ui_lang - the language used for the page interface
  • from_lang - the source language
  • to_lang - the destination language

Change one or more of these to achieve the desired translation. To find the correct language parameters, refer to the Language Reference. In the example above en refers to English, and zh-CN to Chinese (Simplified).

After making your changes, click File > Save... and in the panel that appears type a suitable name (e.g. Translate English to Chinese).


Using the translation Service

After saving your workflow above, you can make use of your translation service with one of the following two methods:

1. The Service Menu method

  • Highlight a word or phrase in any application
  • Click the Application Menu to the right of the Apple icon (), then click Services and Translate English to Chinese (or the name you gave your Service when saving it):

Service menu example

2. The Contextual Menu method

  • Highlight a word or phrase in any application
  • Right-click the text and select Services then Translate English to Chinese (or your custom named Service):

Contextual menu example


Whichever method you use, a browser window should appear with your translated text:

Google Translate example

  • Wow. This is bad-ass. thank you so much. – DragonFax Feb 18 '17 at 19:44
  • Absolutely brilliant — thanks (I just set it up to go from English to Chinese (S), the same way as you did and then modified it to do Chinese (S) to English. A BIG help! Thanks!! – user291332 Jun 7 at 9:15

This one does everything like the soulcake's answer but if the translater's url is already present - loads new translation in the same tab

on run {input, parameters}
    set phrase to input as string

    set ui_lang to "en"
    set from_lang to "en"
    set to_lang to "ru"

    set theBaseUrl to "https://translate.google.com/"
    set theUrl to theBaseUrl & "?hl=" & ui_lang & "&sl=" & from_lang & "&tl=" & to_lang & "&text=" & phrase

    tell application "Google Chrome"
        activate

        if (count every window) = 0 then
            make new window
        end if

        set found to false
        set theTabIndex to -1
        repeat with theWindow in every window
            set theTabIndex to 0
            repeat with theTab in every tab of theWindow
                set theTabIndex to theTabIndex + 1
                if theTab's URL starts with theBaseUrl then
                    set found to true
                    exit repeat
                end if
            end repeat

            if found then
                exit repeat
            end if
        end repeat

        if found then
            set URL of theTab to theUrl
            set theWindow's active tab index to theTabIndex
            set index of theWindow to 1
        else
            tell window 1 to make new tab with properties {URL:theUrl}
        end if
    end tell

end run
  • Unfortunately, It returns a bug while trying using it. – yonivav Jul 8 at 7:22
  • @yonivav what is the bug? can you describe the steps to reproduce it? – vladkha Jul 13 at 7:14

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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