Daily Ubuntu / Linux news and application reviews.

Google Translate CLI is a tool that lets you use translate text from the command line using Google Translate.

Google Translate Command Line

The tool should work on Linux, OS X, FreeBSD, NetBSD, OpenBSD and Windows (Cygwin or MinGW) and its only requirement is GNU awk.


Install Google Translate CLI


To install Google Translate CLI, firstly make sure you wave gwak installed (for the commands below, you'll also need wget, or you can use Git instead if you want).

In Ubuntu, install them using the following commands:
sudo apt-get install gawk wget

Then, install Google Translate CLI:
cd /tmp
wget https://github.com/soimort/google-translate-cli/archive/master.tar.gz
tar -xvf master.tar.gz
cd google-translate-cli-master/
sudo make install

Or, see the official installation instructions.


Usage


By default, Google Translate CLI translates text from any language into English so simply run "trs" followed by some text in a terminal to translate the text into English:
trs "some text"
Example:
$ trs "traducir texto de la línea de comandos utilizando Google Translate CLI"
translate text from the command line using Google Translate CLI
Instead of entering some text to translate, you can also enter the path to a text file.

Google Translate CLI supports setting both the source language (the language of the source text) as well as the target language (the language to translate the source text into):
trs {SOURCE=TARGET} "TEXT TO TRANSLATE"
replacing "SOURCE" with the language code for the source language and "TARGET" with the language code for the target language.

For a complete list of language codes used by Google Translate, see THIS page.

Example: translate "traducir texto de la línea de comandos utilizando Google Translate CLI" from Spanish to English and French:
$ trs {es=en+fr} "traducir texto de la línea de comandos utilizando Google Translate CLI"
translate text from the command line using Google Translate CLI
traduire le texte de la ligne de commande en utilisant Google Translate CLI
Example 2: translate "hola mundo" from Spanish to English, Romanian, German and Italian:
$ trs {es=en+ro+de+it} "hola mundo"
hello world
Bună ziua lume
Hallo Welt
ciao mondo

You don't have to enter both the source and the target language. For instance, you can enter just the target language and let Google Translate guess the source language. Example:
$ trs {=en+ro+de+it} "hola mundo"
hello world
Bună ziua lume
Hallo Welt
ciao mondo

It's important to note that you shouldn't use special characters (such as "!", "$", "`" or "\") inside the text to be translated, without escaping them. Also, don't use "[" and "]" as this will cause Google Translate CLI to fail.

«
Next
Newer Post
»
Previous
Older Post