Translate words from English into other language on Linux Terminal

Translate words from English into other language on Linux Terminal
This tutorial shows how to easily translate words from English into other languages on a Linux terminal. It also shows how to specify source language or more than a single destination language on the Linux terminal, how to identify languages without carrying out the translation process, how to identify languages from the terminal among more useful techniques to deal with languages.

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:

# apt install gawk -y

Once installed download Translate Shell using wget by running:

# wget git.io/trans

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:

# chmod +x trans

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:

# ./trans ‘pinguino’

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:

# ./trans :es penguin

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.

# ./trans :es ‘Linux hint’

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:

# ./trans :es+zh ‘At LinuxHint we seek the best content quality for readers’

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:

# ./trans zh: ‘在LinuxHint,我们为读者寻求最佳的内容质量’

Specify both source and destination languages when translating on LInux terminal:

Of course you can specify both source and destination languages:

# ./trans zh:es ‘在LinuxHint,我们为读者寻求最佳的内容质量’

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:

# ./trans -id "我们为读者寻求最佳的内容质量"

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.

# nano linuxhint-translation

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:

# ./trans :es file://linuxhint-translation

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.

# ./trans :es https://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:

# ./trans -shell es:en

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”:

# ./trans -d en: 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:

# apt install mplayer -y

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.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *