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

How to use Ngx-Charts in Angular ?

Charts helps us to visualize large amount of data in an easy to understand and interactive way. This helps businesses to grow more by taking important decisions from the data. For example, e-commerce can have charts or reports for product sales, with various categories like product type, year, etc. In angular, we have various charting libraries to create charts.  Ngx-charts  is one of them. Check out the list of  best angular chart libraries .  In this article, we will see data visualization with ngx-charts and how to use ngx-charts in angular application ? We will see, How to install ngx-charts in angular ? Create a vertical bar chart Create a pie chart, advanced pie chart and pie chart grid Introduction ngx-charts  is an open-source and declarative charting framework for angular2+. It is maintained by  Swimlane . It is using Angular to render and animate the SVG elements with all of its binding and speed goodness and uses d3 for the excellent math functio...

Understand Angular’s forRoot and forChild

  forRoot   /   forChild   is a pattern for singleton services that most of us know from routing. Routing is actually the main use case for it and as it is not commonly used outside of it, I wouldn’t be surprised if most Angular developers haven’t given it a second thought. However, as the official Angular documentation puts it: “Understanding how  forRoot()  works to make sure a service is a singleton will inform your development at a deeper level.” So let’s go. Providers & Injectors Angular comes with a dependency injection (DI) mechanism. When a component depends on a service, you don’t manually create an instance of the service. You  inject  the service and the dependency injection system takes care of providing an instance. import { Component, OnInit } from '@angular/core'; import { TestService } from 'src/app/services/test.service'; @Component({ selector: 'app-test', templateUrl: './test.component.html', styleUrls: ['./test.compon...

How to solve Puppeteer TimeoutError: Navigation timeout of 30000 ms exceeded

During the automation of multiple tasks on my job and personal projects, i decided to move on  Puppeteer  instead of the old school PhantomJS. One of the most usual problems with pages that contain a lot of content, because of the ads, images etc. is the load time, an exception is thrown (specifically the TimeoutError) after a page takes more than 30000ms (30 seconds) to load totally. To solve this problem, you will have 2 options, either to increase this timeout in the configuration or remove it at all. Personally, i prefer to remove the limit as i know that the pages that i work with will end up loading someday. In this article, i'll explain you briefly 2 ways to bypass this limitation. A. Globally on the tab The option that i prefer, as i browse multiple pages in the same tab, is to remove the timeout limit on the tab that i use to browse. For example, to remove the limit you should add: await page . setDefaultNavigationTimeout ( 0 ) ;  COPY SNIPPET The setDefaultNav...