0

There is an article (https://medium.com/@mrdoro/fast-translation-with-google-translator-and-mac-osx-817e32233b7a) from Lukasz Dorosz about using Apple Automator to integrate Google translator with macOS. I did it and it works. My question is - How can I integrate DeepL translator with macOS?

Using Automator you can integrate a Goole Translator with macOS in few steps:

Open an Automator and create a new Service. The top section set in this way: From the left column you need to find and grab two functions: Run >Apple Script and Website Popup. Copy and Paste this code into Apple Script window.

on run {input, parameters}
    set output to "http://translate.google.com/translate_t?sl=auto&tl=ru&text=" & urldecode(input as string)
    return output
end run
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

How do I change the script to use the translator from DeepL instead of Google?

clemens
  • 16,716
  • 11
  • 50
  • 65
Dimitri
  • 1
  • 2
  • Just replacing the URL hasn't worked? – U880D Sep 22 '19 at 10:38
  • No it doesn't work :(( – Dimitri Sep 22 '19 at 11:29
  • You may have a look into [Using Deepl API to translate text](https://stackoverflow.com/questions/45937616/) and test also with something like https://www.deepl.com/translator#en/ru/hello. – U880D Sep 22 '19 at 11:40
  • Possible duplicate of [Using DeepL API to translate text](https://stackoverflow.com/questions/45937616/using-deepl-api-to-translate-text) – U880D Sep 22 '19 at 11:42
  • @Dimitri In what way didn't it work ? I'm guessing something happened, but just not what you want. Tell us what happened and tell us what URL you used to replace the Google translate one. – CJK Sep 22 '19 at 11:59
  • 1
    @Dimitri There's now an app for Windows and Mac: https://www.deepl.com/en/app/ – ThreeCheeseHigh Oct 01 '19 at 07:44

1 Answers1

0

You can see the DeepL link format by clicking the share button. The links look like this:

https://www.deepl.com/translator#de/en/Dies%20ist%20kein%20Haus.

So your script should look something like this:

on run {input, parameters}
    set output to "https://www.deepl.com/translator#de/en/" & urldecode(input as string)
    return output
end run
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

If the text is long enough, the source language in the link should also be irrelevant, since the DeepL language recognizer determines the actual language.

The DeepL app that @tecmec recommended in his comment is probably much better than any script.

clemens
  • 16,716
  • 11
  • 50
  • 65