简体   繁体   中英

Right-click to translate (look up) with DeepL translator on MacOS

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM