Use Google Translate from a Linux terminal

If you often had to work with foreign languages or actually English is not your native language, you probably often used Google Translate. Naturally you have always been using it from your favourite browser, but what if you are working on a Linux terminal and got a string of text to translate?

You can do it directly from the command line instead of having to access a browser on the side. To do that you need “Google Translate CLI”.

To install it, first you need to have installed wget and gawk; you can find them on your distribution’s package manager.

Than you can install “Google Translate CLI” with the following procedure:
sudo -s
cd /usr/src/
wget https://github.com/soimort/google-translate-cli/archive/master.tar.gz
tar -xvf master.tar.gz
cd google-translate-cli-master/
make install

Then, to use it you have to invoke the “trs“.

By passing just a string in quotes, “Google Translate CLI” will attempt to recognize the original language and translate the string in English. For example:
trs "Testo di prova"
will return:
Test text

If you want to specify both the origin language and the destination language, you need to specify the languages codes in curly brace with an equal (=) sign between the languages. For example:
trs {en=es} "hello world"
will return:
hola mundo

If you want to see a complete list of language codes used by Google Translate, you can visit this page.