In this article, we will discuss two utilities, DeepL Translator and Translate Shell, which allow a user to translate strings to another language directly from the system terminal.
Using DeepL Translator
The DeepL Translator uses machine learning technology to translate text between languages. If you can’t figure out the language of a text yourself, the DeepL Translator automatically identifies it for you. Your system must have an active internet connection to use the translator as it makes use of the DeepL API for translating text.
The DeepL Translator supports the following languages:
English German French Italian Dutch Spanish Russian Portuguese Polish
The Linux package for the DeepL Translator is free to use. However, you can purchase a subscription if you are planning to use the tool frequently. Although the plans and pricing are different for each country, each one has a free subscription for the users as well.
Installing DeepL Translator
To run DeepL Translator on your Linux machine, you will have to install the latest version of Node.js first.
Now, download and install the Yarn package manager. The process is a bit different for some Linux distributions. In this guide, we will discuss how to install Yarn on Debian and Fedora.
On Debian-based distributions like Ubuntu, download the Yarn GPG key using curl.
Add the Yarn Debian repository to your system’s repository list.
Update the repository list and install Yarn using APT.
On Fedora and other RPM-based distros, first you’ll have to add the Yarn repo to the repository list. The Node.js dependencies will be installed automatically in Fedora, therefore you don’t need to install them manually.
You can install Yarn using either DNF or yum. Type any of the following commands in the terminal.
Now that you’ve installed the Yarn package manager on your system, it is time to download the DeepL Translator package. To install DeepL Translator, type:
You can verify if Yarn has successfully installed DeepL Translator on your system by checking the version information for the package.
How to Use the DeepL Translator
Translating text with the DeepL Translator is simple. To translate a string to another language, specify the language code and the string with the command.
As mentioned above, the DeepL Translator can detect the language of the specified piece of text. To do so, use the detect option with the deepl command.
Like other Linux commands, you can pipe deepl with the standard output. For example:
If you can’t figure out how to use the translator, you can check the help section using the -h flag. The developers have provided help pages for each option available in the utility.
Using the Translate Shell Utility
Translate Shell is one of the most widely-used command-line language translators available on Linux. Previously, it was known as Google Translate CLI. The power of Google Translate, Bing Translator, Apertium, and Yandex Translate make it a reliable tool for translating text strings right from the terminal.
To install Translate Shell on your Linux machine, download the executable file and add it to your system’s environment variables.
Assign executable permissions to the downloaded file.
Add the executable to the environment variables.
How to Use Translate Shell
Translating text with Translate Shell is quite easy when compared to the DeepL Translator. In the application, there are three output modes: Default, Interactive, and Brief.
In the default mode, the output contains information related to the translation. On the other hand, the brief mode will only display the translated text.
By default, the utility translates the text to the English language. To translate a string in English using Translate Shell:
The system will display the following output.
If you want to translate a string to another language apart from English, you’ll have to use the language code. For example, to convert a string from the English language to Spanish:
Output:
If Translate Shell is unable to identify the language of the text, you can specify the language code with the command.
Note that in the last two commands, the left side of the colon (:) character is for the source language and the right side is for the destination language.
To translate a single string to multiple languages, pass the respective language codes separated by the Plus (+) character.
The aforementioned command will translate the specified text to Spanish and Hindi.
You can pass both the source and destination languages as well.
If you do not know the language of the string, you can use the -id flag with the default trans command.
To translate complete files to another language, pass the name of the file.
Use the -brief flag to switch to a simple output format.
Output:
To use the interactive Translate Shell:
Now you can start typing your statements and the system will translate the text in an interactive way.
Translating Text in the Linux Command Line
Sometimes while browsing the internet, you might have come across a text written in a language you don’t understand. While most browsers nowadays have automatic language translation features, they don’t work well every time. In such situations, having a command-line language translator can be helpful.
You can also choose to translate a webpage using online tools. Several tools are available on the internet that can help you in translating any web page to your desired language instantly.