- install xsel,
sudo apt install xsel
- Install translate-shell
Then copy the following code into a notify-send.sh file,
#!/usr/bin/env bash
# Need https://github.com/soimort/translate-shell installed.
se=$(xsel -o)
re=$(/usr/bin/trans -b :zh "$se")
notify-send "$se" "$re" -i accessories-dictionary -t 2000
chmod a+x notify-send.sh
Then add a shortcut key in the system settings to run the notify-send.sh script.
Open any software, select a word, press the shortcut key, and a system notification will pop up to display the translation.
se
The selected word is stored in the script, and the re
translation result is stored.
Using translate-shell is one way to get translations, but other ways are also possible. For example, use wget to call the API of Google Translate or Baidu Translate, or write a Python script to open the Google Translate URL, parse the page to get the translation, and so on.
Using system notifications to display translation results is just a way to display translation results. You can also write a Python script to display the results using Tkinter, and destroy the window when the mouse leaves?
END
2018.5.3