Skip to main content

How To Use Google Translate From Commandline In Linux

Install Translate Shell

Translate Shell can be installed in three ways.

Method1 – 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.

Method2 – 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/

Method3 – 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

Use Google Translate From Commandline In Linux using “Translate Shell”

1. Translate a word/sentence

To translate a word, just type:

$ trans வணக்கம்

Sample output:

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

Hello

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 ]

adverb
how
எப்படி
இருக்கீங்க? 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 -briefparameter 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

Sample output:

translate shell 1

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:

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

नमस्ते
(namaste)

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

What about translating a website? That’s also possible.

$ trans https://www.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://www.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 another cool thing that I liked in 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 on Unix-like systems. As you can see, using Google translate service from command line is easy, kind of fun and interesting.

Comments

Popular posts from this blog

4 Ways to Communicate Across Browser Tabs in Realtime

1. Local Storage Events You might have already used LocalStorage, which is accessible across Tabs within the same application origin. But do you know that it also supports events? You can use this feature to communicate across Browser Tabs, where other Tabs will receive the event once the storage is updated. For example, let’s say in one Tab, we execute the following JavaScript code. window.localStorage.setItem("loggedIn", "true"); The other Tabs which listen to the event will receive it, as shown below. window.addEventListener('storage', (event) => { if (event.storageArea != localStorage) return; if (event.key === 'loggedIn') { // Do something with event.newValue } }); 2. Broadcast Channel API The Broadcast Channel API allows communication between Tabs, Windows, Frames, Iframes, and  Web Workers . One Tab can create and post to a channel as follows. const channel = new BroadcastChannel('app-data'); channel.postMessage(data); And oth...

Working with Node.js streams

  Introduction Streams are one of the major features that most Node.js applications rely on, especially when handling HTTP requests, reading/writing files, and making socket communications. Streams are very predictable since we can always expect data, error, and end events when using streams. This article will teach Node developers how to use streams to efficiently handle large amounts of data. This is a typical real-world challenge faced by Node developers when they have to deal with a large data source, and it may not be feasible to process this data all at once. This article will cover the following topics: Types of streams When to adopt Node.js streams Batching Composing streams in Node.js Transforming data with transform streams Piping streams Error handling Node.js streams Types of streams The following are four main types of streams in Node.js: Readable streams: The readable stream is responsible for reading data from a source file Writable streams: The writable stream is re...

Certbot SSL configuration in ubuntu

  Introduction Let’s Encrypt is a Certificate Authority (CA) that provides an easy way to obtain and install free  TLS/SSL certificates , thereby enabling encrypted HTTPS on web servers. It simplifies the process by providing a software client, Certbot, that attempts to automate most (if not all) of the required steps. Currently, the entire process of obtaining and installing a certificate is fully automated on both Apache and Nginx. In this tutorial, you will use Certbot to obtain a free SSL certificate for Apache on Ubuntu 18.04 and set up your certificate to renew automatically. This tutorial will use a separate Apache virtual host file instead of the default configuration file.  We recommend  creating new Apache virtual host files for each domain because it helps to avoid common mistakes and maintains the default files as a fallback configuration. Prerequisites To follow this tutorial, you will need: One Ubuntu 18.04 server set up by following this  initial ...