Could anyone please create a macro to translate the content of the current clipboard and replace it with a translation in one of the available languages?
It would also be very useful to have any available alternative translations displayed (possibly via another keyboard shortcut).
Hi @CafeTran_Training, I'm not an expert in scripts, so I created this macro. Maybe it'll help you a little.
You have to select the languages with the cursor, because you cannot use Enter etc. here. Everything else is done by the macro.
Since you have linked to this thread on two other forums, I assume that my above instructions worked fine for you.
On the CafeTran forum you say that “you need the uber-useful Keyboard Maestro to execute the macros.” Just for clarification:
The Python script itself runs perfectly fine also without KM. You can run it with other launchers (Alfred, LaunchBar, etc.) or from within an AppleScript, etc., or of course simply from the Terminal.
In the Terminal, to get the result to the clipboard just pipe it to pbcopy. If your system’s LANG variable is correctly set to UTF-8 (the language doesn’t matter) then you don’t need the first line.
So, this…
/usr/local/bin/python3 '<path/to/the/script>/translate.py' -l DE "$(pbpaste)" | pbcopy
would be a standalone command line for the Terminal that gets the input from the clipboard and pastes the output to the clipboard.
BTW, I’ve never heard of that CafeTran thingy before, but it looks very interesting. I’m also working as translator (not my main job though) and in the past I used OmegaT or, ahem, no CAT tool at all. I will definitely give CafeTran a serious try next time!
PS:
I’ve just seen that the forum links you’ve posted on Proz and Freshdesk go to post#2 in this thread. I’m not sure if this was your intention, since you also uploaded the ‘DeepL via Python’ macro file (which is from post #3).
Yes, Tom, your instructions helped me to get the Python script running. Thanks again!
The piping to the clipboard is also very nice. Must look into Alfred some day …
About CafeTran: I’ve compared it with the other currently available CAT (computer-assisted translation) tools for the Mac platform thoroughly. It’s an advanced, high-performance app, with a very responsive developer. If you have any questions about CafeTran, I’d be very happy to help you!
Unfortunately, with DeepL via Translate Shell there are encoding issues on the Mac. I’ll try to find a workaround, when I find some time. Or better: let’s hope the author finds some solution…
I guess it will be easier to use the Translate Shell script, which supports DeepL. Read the docs on Github, it has stuff like dictionary mode and alternate translations (not sure if also for DeepL, but I think so).
If Translate Shell does what you want, then it’s just a matter of grabbing the shell output, which will probably be more straightforward than getting it from the web page. (The script is using the API of the transllation engine.)
I’ve already written a KM macro for Translate Shell. It does not cover the alternate translations and other modes of Translate Shell, but I’m sure you can copy some elements from the macro.
You also find some (hopefully) useful information in my macro post, e.g. how to install Translate Shell and a workaround for a bug (if the bug is still there).
According to this Wiki article you can use KM variables in the JS action.
So, setting a variable to the Clipboard token %SystemClipboard% and then using that variable as shown in the Wiki article should work.
Hint: If you posted a downloadable minimal example (+ the information what you are trying to achieve on exactly which web page URL) we could test it for you.
I’ve tried your “Send Clipboard Content to DeepL” macro in Safari (with the proper Safari actions) and it doesn’t work. But it doesn’t work either if I replace the KM variable with a fix string (const strClip = "test string";).