This script provides a convenient way to check spelling, pronunciation, and translation of words or text using a dictionary (such as Google Translate) directly from your Linux desktop. It can be easily integrated with a keyboard shortcut, making it globally accessible for quick translation and pronunciation of selected text.
As a non-native English speaker, I often find myself needing to verify the spelling, pronunciation, or translation of words, phrases, or paragraphs using an online dictionary like Google Translate. To streamline this process, I developed a script that allows me to quickly translate and hear the pronunciation of selected text with a simple keyboard shortcut.
This script utilizes command-line tools (trans or translate-shell, xclip, and notify-send) to achieve the following functionalities:
- Translation: Translates the selected text using an online translator (Google Translate in this case).
- Pronunciation: Retrieves the pronunciation of the translated text.
Ensure the following packages are installed on your Linux system:
trans
or translate-shell: Command-line translator supporting Google Translate, Bing Translator, Yandex.Translate, etc.xclip
: Command-Line interface to X selections (clipboard).notify-send
or libnotify-bin: Program to send desktop notifications.
You can install these packages using the package manager of your Linux distribution (e.g., apt for Debian/Ubuntu).
-
Download the Script: Save the script (translator.sh) to a directory of your choice (e.g., ~/.local/bin/):
mkdir -p ~/.local/bin/ # Create the directory if it doesn't exist curl -o ~/.local/bin/translator.sh https://gist.githubusercontent.com/mh-firouzjah/9aec6745dc0ec4a3f204e65839bf2b38/raw/ee5d27ed892d6a13283855fc2284d5a984e55d89/translator.sh
-
Make the Script Executable: Ensure the script is executable:
chmod +x ~/.local/bin/translator.sh
-
Test the Script: Run the script from the command line to ensure it works:
~/.local/bin/translator.sh
-
Assign a Keyboard Shortcut: Set up a keyboard shortcut in your Linux Desktop/WM to execute the script (translator.sh) when triggered. This process may vary depending on your desktop environment.
After setting up the script and keyboard shortcut:
- Highlight/Select Text: Use your mouse to highlight or select any text within any window.
- Invoke Translation and Pronunciation: Press the assigned keyboard shortcut to initiate the translation and pronunciation of the selected text.
- View Translation and Pronunciation: A pop-up notification will display the translation and pronunciation of the selected text.
Feel free to customize the script according to your preferences and needs. You can adjust the translation settings, modify the keyboard shortcut, or enhance the functionality based on different dictionaries or services.
- Note: For detailed configuration and usage of the
translate-shell
package, refer to its official GitHub repository. This repository provides comprehensive documentation and examples to help you customize the translation settings according to your preferences and linguistic needs.