Google translate client for OS X [closed]

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

Solution 1:

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

Solution 2:

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.

Solution 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.

Solution 4:

  • 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