any hint on how to create a keyboard shortcut to translate a selected text in Safari (or, even better, in any app?)
Yes this is possible with the Shortcuts app. It will work in Safari or any app that lets you select text. You can bind it to any keyboard shortcut. You can even use it on iPhones and iPads.
It's very easy to set one up and customize it, say if you want to change the translation language:
I found a Safari extension that translates selected text.
This extension is made by uetchy and is named Polyglot. You can find instructions on GitHub or simply download Polyglot from App Store.
- Install Polyglot.app from the Mac App Store
- Open the Polyglot.app in Applications
- Configure Settings in Polyglot.app
- Open Safari > Settings > Extensions
- Activate Polyglot Extension
- Extension is now available Note: any pages that were already open before the extension was activated may need to be reloaded for the extension to work on them.
Here is what I did for the most simple possible shortcut. Let's you highlight some text anywhere in macOS, run this Shortcut (I do it from the Services menu or add a keyboard shortcut to it), and it will open a pop-up Safari window with your text in Google Translate.
- Receive [Text] input from [Quick Actions]
- URL [Encode] [Shortcut Input]
- https://translate.google.com/?sl=auto&tl=en&text=**URL Encoded Text**
- Show webpage at URL
Make sure in step 3, the URL Encoded Text variable is part of the URL, i.e. let no space exist between them. Add the [URL ENCODED TEXT] variable right into the URL itself, not as an additional variable via the "+" sign.
And make sure "Services" is checked under the "Quick Actions" sidebar preferences.