A Better Way to Use Google Translate

Google Translate is an invaluable tool for anyone who lives in a world where multiple languages are spoken. No machine translation system is perfect, but the one Google has created is one of the best — and it’s constantly improving.

Typically, however, this artifact of power is accessed through a web interface. The reason I don’t like this is because it’s slow. You have to navigate to Google Translate, select the input language, select the target language, type in your text, and then click “Translate”. But that’s not good enough for you, is it? You want to translate das ist gut, ja? and receive this is good, yes?!

To that end I have written a Python script which uses the Google Translate API to translate its input into a language of your choice. It automatically detects the input language and can translate into any language supported by Google Translate (over 9000 50 at the time of writing). The script translates into English by default, but you can easily change this with the -t (--target) argument — allow me to demonstrate.


Translate to English:

$ translate Hola! ¿Habla usted español?
Hello! Do you speak Spanish?

Translate to Swedish:

$ translate -t sv Hello! Do you speak Spanish?
Hej! Talar du spanska?

Translate to Swedish, by piping fortune to translate:

$ fortune -s | translate -t sv
<james> men, då jag använde en Atari, var jag mer sannolikt att vinna på lotteri i tio länder samtidigt, än att få snabbare X


To install this script, just save it as translate, make it executable, and place it on your PATH. It’s written in Python, so you will need Python installed to run it. In addition, you will need the modules json (included in version 2.6 onwards) and argparse (included in version 2.7 onwards).