For this tutorial the software used is Translate Shell, previously known as Google Translate CLI.
Translate Shell allows you to use Google Translate, Bing Translator, Yandex Translator and Apertium from the command line, while including all translation engines mentioned above Google is the default one.
Before downloading Translate Shell you need to get the gawk package by running:
Once installed download Translate Shell using wget by running:
Note: on Debian and based Linux distributions you can install wget by running apt install wget.
Once downloaded give Translate Shell execution rights by running:
Lets try by translating a single word from Italian (to English since English is the default destination language). To translate the word pinguino run:
Translate a single word on Linux terminal:
Note: using quotation marks is optional for single words and mandatory for sentences.
As you can see Translate Shell detected the source language as Italian and translated it to English despite the destination language wasn’t specified.
Now let’s translate the same word from English to Spanish. To specify a destination language use “:” followed by the destination language as in the example below:
As you can see, Translate Shell translated it properly.
Translate more than a single word on Linux terminal:
Now let’s translate more than a single word, the following example shows the “Linux hint” translation, note for more than a single word quotation marks are mandatory.
Translate words from English into several other languages on Linux terminal:
Translate Shell also allows you to translate to different destination languages, the following example shows how to translate the sentence “At LinuxHint we seek the best content quality for readers” to Spanish and Chinese simultaneously by just separating language codes with a + symbol:
Specify the source language when translating words into other language on Linux terminal:
Sometimes translators fail to auto detect the source language, Translate Shells supports source language specification by placing the source language code before colon:
Specify both source and destination languages when translating on LInux terminal:
Of course you can specify both source and destination languages:
Detect languages on Linux Terminal using Translate Shell:
You can use Translate Shell also to detect languages only, without proceeding with translation, obtaining additional information on the detected language by adding the -id flag as shown in the example below:
Translate files from English into other language on Linux terminal:
Translate Shell also allows you to translate files. Using nano or any text editor you want create a text file with content on any language you want to translate to test Translate Shell.
Then press CTRL+X to save and exit
To translate the content to Spanish use the syntax shown below adding file://<Path-To-File> as content source to translate:
Translate websites into other language on Linux terminal:
With Translate Shell it is possible to translate websites too using the syntax shown below to translate linuxhint.com.
As you can see Translate Shell returned a URL with a version of LinuxHint in Spanish:
https://translate.google.com/translate?hl=en&sl=auto&tl=es&u=https://linuxhint.com
Translate words into other language on Linux terminal with interactive mode:
Translate Shell also offers an interactive mode, the following example shows how to launch the interactive mode to translate content from Spanish to English:
Using Translate Shell as dictionary:
Translate Shells can be also used as dictionary if the option -d is implemented, the following example shows Translate Shells being used as dictionary for the word “encrypt”:
Play sound to include spoken translation in the output:
To end this tutorial lets add sound to hear translations, to achieve it you need to install a terminal media player such as mplayer, on Debian and based Linux distributions run:
Play sound to include spoken translation in the output:
Once installed, use the option -p to add sound to the output, the following example shows how to translate from Chinese to Spanish including the spoken translation:
I hope you found this tutorial on how to translate words from English into other language on Linux terminal useful. Keep following LinuxHint for more tips and updates on Linux and networking.