Translate Shell: Google Translate from terminal

hebrewCame across a word or sentence in a language you do not understand? For most of us, the one-stop webservice is Google Translate. Thanks to Translate Shell, a new utility to access Google Translate, you don’t need to fire a browser to translate text any more. The tool, essentially a shell script, provides various options to translate text or webpages, even interactively.

Translate Shell detects your locale automatically and uses it as the target language to translate text to. However, there are options to specify the target language. As for the input text language, it depends on Google Translate to detect it automatically (if input language is not mentioned specifically in the cmdline options).


Translate Shell needs gawk. To install gawk on Ubuntu:

$ sudo apt-get install gawk

The easiest option is to download the latest version directly and use it:

$ wget
$ chmod +x ./trans
$ sudo mv ./trans /usr/bin/


Using UTF-8 codeset as default locale is advisable, as it potentially supports all languages. You can check whether your codeset is UTF-8 using:

$ locale
$ echo $LC_CTYPE

In my case the locale is en_US.UTF-8.

Some sample usage examples:

  • Translate some text
    $ trans 'Saluton, Mondo'
  • Show a brief output (just the translation)
    $ trans -b 'Saluton, Mondo'
  • Translate briefly and interactively (one line per input)
    $ trans -b -I
  • Show list of language codes
    $ trans -R
  • Translate something into French
    $ trans :fr 'Hello World!'
  • Translate something into multiple languages (use + for multiple)
    $ trans :zh+ja 'Hello World!'
    OR use -t option
    $ trans -t zh_ja 'Hello World!'
  • Specify input language (if Google Translate auto-detection fails) in in:out format
    $ trans ja:en 手紙
    OR use the -s option
    $ trans -s ja -t en 手紙
  • To translate multiple words individually do not use quotes
    $ trans en:zh freedom of speech
  • Single quotes are preferable if the text has symbols like <!> so that it’s not interpreted by the shell. However, in cases like the input text contains a single quote, use double quotes.
    $ trans :zh "I'm lovin' it! McDonald's"
  • Use the play (-p) option to listen to a translation (needs MPlayer, mplayer2, mpg123, or eSpeak)
    $ trans :ja -b -p "Saluton, Mondo"
  • Translate a text file
    $ trans :fr file://input.txt
  • Translate a webpage
    $ trans :fr
  • Translate a webpage and open in browser
    $ trans :fr -browser firefox
  • Show detailed help
    $ trans -H

Environment Variables

The following environment variables are supported:

BROWSER        : for option -browser
PLAYER         : for option -player
HTTP_PROXY     : for option -proxy
TRANS_PS       : for option -prompt
TRANS_PS_COLOR : for option -prompt-color
HOME_LANG      : for option -l
SOURCE_LANG    : for option -s
TARGET_LANG    : for option -t

vim integration

Add the following line to your ~/.vimrc:

set keywordprg=trans\ :en

Use <Shift-k> to view the translation of the word under the cursor.

GoogleCL is another utility that let you access many of the Google services.

Webpage: Translate Shell

One thought on “Translate Shell: Google Translate from terminal”

Leave a Reply

Your email address will not be published. Required fields are marked *