Yahoo
Skip to main content
Advertisement
Advertisement
Advertisement
Advertisement

This Tool Let Me Use Google Translate in the Linux Terminal

Young woman studying on a laptop at a white desk, with the Linux mascot Tux beside her wearing a graduation cap.
Lucas Gouveia/How-To Geek | SibRapid/ Shutterstock

Need quick translations on the go when working on the Linux terminal? It can get bothersome to open your browser, go to Google Translate, and type your text every time. With this tool, you can translate within your terminal. Let's explore it together.

What is Translate Shell, and How is It Useful?

Translate Shell , previously known as Google Translate CLI, is a command-line translation tool. Behind the scenes, it uses several translation engines such as Google, Bing Translator, Apertium, and Yandex, with Google Translate being the default option. It has many great options and features that make it worth trying.

Oftentimes, you're working on documents and may need to translate a few words or a part of the document. You could copy it and paste it into Google Translate or other translation services. While this is feasible, doing it repeatedly can feel annoying. Moreover, those of us who love to use the terminal and want to stick to it prefer to use tools that can get the job done without exiting it.

Advertisement
Advertisement

Since Translate Shell uses most of the popular engines, you don't have to worry about accuracy. You mostly get good results. Add to that the fact that it's a command-line tool. You can pair it up with other CLI tools or terminal features to make it even more powerful.

Setting Up Translate Shell

Before diving into installing Translate Shell, you need to get the dependencies first. The two must have are:

In case you don't have gawk installed, get it through your distribution's package manager, where it's usually simply called "gawk". For example, to install with Debian or Ubuntu, use this command:

Installing gawk on Linux as a prerequisite for Translate Shell.

Other than the two above, the developers also recommend having cURL , GNU FriBidi, eSpeak , less/more, rlwrap, and a spell checker like aspell . These aren't mandatory. But having them will allow you to make the most of Translate Shell.

Advertisement
Advertisement

There are various ways to get Translate Shell on your Linux system. Let's start with the most common one: Linux package managers . The tool comes with most of the popular distros. So, pick the package manager your distro uses from the list.

Another option is to download the official self-contained executable file and run it.

If you prefer to build it from source , then run the following commands:

Lastly, if you have Docker installed and set up, you can try it out with these commands:

To confirm your installation, simply run:

Checking the version of Translate Shell to confirm its installation.

You should see its current installed version along with some other useful information.

Translating Text Using the Tool

Let's start doing some translations. The most basic way to translate something using Translate Shell is to pass it inside quotes to the trans command.

Doing a basic word translation in Translate Shell.

If you try to translate without adding any flags, you'll get a detailed breakdown of the translation. Let's see another example. This time, a sentence.

Doing a sentence translation in Translate Shell.

If you don't want the detailed breakdown, you can use the -brief flag.

Using the brief flag in Translate Shell to avoid a detailed translation breakdown.
Advertisement
Advertisement

This time, you only get the translated text as the output. You can also use Translate Shell as an interactive shell. That way, you don't need to write the trans command every time. All you have to do is input your text that needs to be translated. The -shell flag lets you do that.

Translating text using Translate Shell's interactive shell.

To exit the interactive shell, type ":q" (without quotes) and hit Enter.

Translate Shell tries to auto-detect the input language and translate it. I also like how the tool supports transliteration. You can type a language using another language, such as English, and still get it translated. However, I've seen that using transliteration can reduce accuracy, especially when you don't specify the language.

You can specify the target language in many ways. For example, using a colon (:) or equal sign (=) followed by the short form of the target language.

Translating text to a target language using Translate Shell.

You can also translate to multiple languages at the same time. For that, you need to write the languages using a plus (+) sign, like this:

Translating text to multiple languages using Translate Shell.

The plus sign works as a delimiter here. An alternative way to specify the language is to use the -t option. In that case, you can also write the language name instead of the short code.

Likewise, you can specify the source language from which you want to translate. Again, there are many different ways to do this. Here's a short list covering them:

This is useful when the tool fails to recognize the language you're trying to translate from. Lastly, as you'd expect, you can specify both the source and the target language for translation.

Translating text from a source language to a target language using Translate Shell.
Advertisement
Advertisement

The only problem you might face is not remembering the short forms for all the languages. However, it's not that difficult to get used to once you memorize the common language names.

Exploring Some Advanced Features

There are advanced features worth exploring, should you find the tool to be useful. For example, it has a dictionary mode. If the target language is the same as the input you provide, the tool shows you a detailed dictionary definition of the word instead of translating it.

An instance of Translate Shell's dictionary mode.

You can also use dictionary mode by passing the -d flag. This allows you to check the word definition regardless of the source or target language.

Translate Shell can also help you identify a language. For that, you have to use the -id option.

Identifying a language using Translate Shell.

Want to hear the translated text? You can also do that using the -p flag.

If you want to hear the original text spoken instead, then use the -sp flag.

Now comes the interesting part. Since we're in the terminal, we can make good use of it. How? By combining Translate Shell with other command-line tools and features. Here's a quick example of using the echo command .

Piping the output of the echo command to the Translate Shell tool.

You can use a file as an input option to translate its content. Use the -i option for that.

Another way to do this is to use a file URI scheme, like this:

It's not just local files. You can even translate a whole web page.

In this case, your browser will launch that web page in the translated language.

Advertisement
Advertisement

Likewise, you can save the translated text to an output file using the -o option.

This will create a file with the specified name and save the output text to it.


Overall, this was a fun tool to play with when I needed some quick translations. I didn't have to bother going to the browser for that. If you want to learn more about the tool's features, refer to its man page or visit the GitHub repository . If you want to get more creative, try combining Translate Shell with other Linux text editing tools .

Advertisement
Advertisement
Mobilize your Website
View Site in Mobile | Classic
Share by: