Home Command line utilities How To Use Google Translate From Commandline In Linux

How To Use Google Translate From Commandline In Linux

By sk
Published: Updated: 17.5K views

Translate Shell (formerly known as Google Translate CLI) is a command-line translator powered by popular translation engines such as Google Translate (default), Bing Translator, Yandex.Translate and Apertium. It allows you to access one of these translation engines from your terminal.

Google Translate is my first preferred tool to translate English to my native language Tamil and vice versa. I am not a native English speaker, so I mostly depend on Google Translate for both my professional and personal usage. Thanks to Translate Shell, I can easily use Google translate from command line in my Linux machine.

Translate shell is a cross-platform utility, so it will work on most modern operating systems, including GNU/Linux, FreeBSD, MS Windows, and Mac OS X.

In this tutorial, we will see how to install Translate shell and how to translate a word, a sentence, or even a webpage from your preferred language to English and vice versa using Translate shell. Let's get started!

Install Translate Shell in Linux

Translate Shell can be installed in three ways.

Method 1 - Using Package manager

Translate Shell is available in the official repositories of popular Linux operating systems.

On Arch Linux and derivatives:

$ sudo pacman -S translate-shell

On Debian, Ubuntu, Linux Mint:

$ sudo apt-get install translate-shell

On Fedora:

$ sudo dnf install translate-shell

If it is not available in the official repositories, you can install it as described in any one of the following two methods.

Method 2 - Direct download

Download the self-contained executable file, make it as executable. move it to your $PATH and start using it.

$ wget git.io/trans
$ chmod +x trans
$ sudo mv trans /usr/local/bin/

Method 3 - Install from source

Clone Translate Shell git repository, compile and install it as shown below.

$ git clone https://github.com/soimort/translate-shell
$ cd translate-shell/
$ make
$ sudo make install

How to use Translate Shell

1. Translate a word or sentence

To translate a word, just type:

$ trans வணக்கம்

Sample output:



Translations of வணக்கம்
[ தமிழ் -> English ]

 Hello, Greetings, Good, Hi, Salute

As you see in the above output, I have translated a Tamil word called "வணக்கம்" (Vanakkam), which is used to greet people, to English. By default, Translate Shell will translate the given words/sentences to English.

To translate a whole sentence at once, Just type 'trans' command followed by the sentence within quotes like below.

$ trans "எப்படி இருக்கீங்க?"

Sample output:

எப்படி இருக்கீங்க?
(Eppaṭi irukkīṅka?)

How are you?

Translations of எப்படி இருக்கீங்க?
[ தமிழ் -> English ]

எப்படி இருக்கீங்க?
 How are you?

As you see in the above example, Translate Shell gives you the detailed translation of the given sentence.

When translating a sentence, put them inside quotes. If you don't put them inside the quotes, each word in the sentence will be translated alone like below.

$ trans எப்படி இருக்கீங்க?
எப்படி null
(null Eppaṭi)

How null
/null null/

Definitions of எப்படி null
[ தமிழ் -> English ]

இருக்கீங்க? null
(null Irukkīṅka?)

Are you? null
/null null/

Translations of இருக்கீங்க? null
[ தமிழ் -> English ]

இருக்கீங்க ?
Are you?

To get the brief translation of the given sentence, type the sentence with -brief parameter as shown below.

$ trans -brief "எப்படி இருக்கீங்க?"

The sample output would be:

How are you?

This above command will just display the actual translation.

2. Translate the contents of a file

I want to translate a whole text file to English, is it possible? Yes you can!

Let us see the contents of text file

$ cat greet.txt

Here is what I have in the text file.

வணக்கம். எப்படி இருக்கீங்க?

To translate this text file, just type:

$ trans file:///home/sk/greet.txt

Sample output:

Hello. How are you?

Cool isn't it?

3. Find language codes

As you know already, Google translate supports over 100 languages. So it is important to know the language codes to translate sentences to other languages.

To display the language codes, type:

$ trans -R
List language codes
List language codes

Just pick any language of your choice and translate the sentence instantly. You don't need a web browser. Everything will be displayed right from your Terminal.

4. Translate to one or more languages

As you noticed, all the translations that we have done so far are from other languages (Tamil in my case) to English. If you want to change the target language, type :(colon) followed by specific language code.

Say for example, to translate a word to Hindi, just type:

$ trans :hi வணக்கம்

This command will translate the Tamil word "வணக்கம்" to Hindi language.

Sample output:



Translations of வணக்கம்
[ தமிழ் -> हिन्दी ]

 नमस्ते, करें Hello, नमस्कार, Hello

We can also translate words to multiple languages in one go. To do so, use use a plus sign "+" as the delimiter. For instance, the following command will translate the given word to Hindi and Telugu.

$ trans :hi+te வணக்கம்
வணக்கம் null
(null Vaṇakkam)

नमस्ते null
(null namaste)

Translations of வணக்கம் null
[ தமிழ் -> हिन्दी ]

नमस्ते, को नमस्कार, Hello, नमस्कार

வணக்கம் null
(null Vaṇakkam)

హలో null
(null Halō)

Translations of வணக்கம் null
[ தமிழ் -> తెలుగు ]

హలో, h- ఇ- llo, కిట్టి, కు హలో

Alternatively, you can use -t option (instead of colon) to specify the target language(s). This command translates the given word to Hindi, Telugu and Kannada.

$ trans -t hi+te+kn வணக்கம்

To translate a sentence to multiple languages, quote the sentence like one argument as shown below.

$ trans :hi+te+kn "எப்படி இருக்கீங்க?"
எப்படி இருக்கீங்க? null
(null Eppaṭi irukkīṅka?)

आप कैसे हैं null
(null aap kaise hain)

Translations of எப்படி இருக்கீங்க? null
[ தமிழ் -> हिन्दी ]

எப்படி இருக்கீங்க?
आप कैसे हैं, आप कैसे हैं?

எப்படி இருக்கீங்க? null
(null Eppaṭi irukkīṅka?)

మీరు ఎలా ఉన్నారు null
(null Mīru elā unnāru)

Translations of எப்படி இருக்கீங்க? null
[ தமிழ் -> తెలుగు ]

எப்படி இருக்கீங்க?
మీరు ఎలా ఉన్నారు, మీరు ఎలా ఉన్నారు?

எப்படி இருக்கீங்க? null
(null Eppaṭi irukkīṅka?)

ನೀನು ಹೇಗೆ? null
(null Nīnu hēge?)

Translations of எப்படி இருக்கீங்க? null
[ தமிழ் -> ಕನ್ನಡ ]

எப்படி இருக்கீங்க?
ನೀನು ಹೇಗೆ?, ಹೇಗಿರುವಿರಿ?

Or, use -t option.

$ trans -t hi+te+kn "எப்படி இருக்கீங்க?"

5. Translate from a specific language

Sometimes, Google translate may wrongly identify the source text as some other language than you expected. In such cases, you need to specify the source language explicitly like below.

$ trans ta: வணக்கம்
வணக்கம் null
(null Vaṇakkam)

Hello null
/null null/

Translations of வணக்கம் null
[ தமிழ் -> English ]

Hello, Greetings, Good, Hi, Salute

Please mind that you must put the colon after the language code, not before. If you put the colon before language, it will be recognized as target language.

Alternatively, just use -s option (instead of colon) to specify the source language as shown below.

$ trans -s ta வணக்கம்

6. Interactive Translation

Translate Shell can also be used as interactive translator. That means you can translate line by line interactively.

To do so, use -shell option like below.

$ trans -shell -brief
Translate Shell
(:q to quit)
> வணக்கம்
Hello null
> எப்படி இருக்கீங்க?
How are you? null

Press Ctrl+c to quit the interactive translation.

7. Translate a website

We can translate a whole website or a specific web URL like below.

$ trans https://ostechnix.com/

This command will open a new browser window and translate the website into English. Since the above website is already in English, It just displayed:

The page you have attempted to translate is already in English.

To translate ostechnix.com site to some other language, for example Tamil, just type:

$ trans :ta https://ostechnix.com/
translate shell 2
Translate a website from command line

8. Dictionary mode

Google translate can also be used as a dictionary. To know the meaning of a given word, run:

$ trans :en வணக்கம்
வணக்கம் null
(null Vaṇakkam)

Hello null
/null null/

Translations of வணக்கம் null
[ தமிழ் -> English ]

    Hello, Greetings, Good, Hi, Salute

To enable dictionary mode no matter whether the source language and the target language are identical, use the -d option like below.

$ trans -d te: வணக்கம்

9. Language identification

To identify the language of a given text, use -id option.

$ trans -id வணக்கம்
Name Tamil
Family Dravidian
Writing system Tamil
Code ta
ISO 639-3 tam
SIL http://www-01.sil.org/iso639-3/documentation.asp?id=tam
Glottolog http://glottolog.org/resource/languoid/id/tami1289
Wikipedia http://en.wikipedia.org/wiki/Tamil_language

As you can see in the above output, I have used Tamil language.

10. Text-to-Speech

This is another useful feature of Translate Shell. Just like the Google translate web service, we can listen to the translation and original text. Put your headphone on and type the language of your choice to listen.

To listen to the translation, run:

$ trans -b -p :ta வணக்கம்

To listen to the original text, run:

$ trans -sp "எப்படி இருக்கீங்க?"

11. Terminal paging

Sometimes, the contents of translation might be too much for display in one screen. In such cases, use -v option to display the translation result page by page.

$ trans -d -v word

12. Getting help

To display help section, run:

$ trans --help

To display Translate shell man page:

$ trans -M

Note: Here M is capital letter.

And, that's all for now. You know how to use Google translate from command line in Linux and Unix-like systems. As you can see, using Google translate service from command line is easy, kind of fun and interesting.


You May Also Like


Axel López June 24, 2019 - 10:24 am

Good contribution!

Orewa March 19, 2020 - 10:09 am

Wtf, my brain so confused with hindi language. Change to English with familiar languages, like Japan, German, whatever.


Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More