Aug 292010
 

Occasionally use Google Translate to make a quick translation of texts, and I must say that the web interface is functional but not so comfortable.

For example if you have a .txt file you copy and paste, then copy and paste the translated version, quite a bit uncomfortable for long texts, and so with a quick google I found this handy little python script that allows you to work from command line.


./translate -h
Usage: translate [–help|-h]
[–verbose|-v]
[(–source|-s) <source language>]
[(–destination|–dest|-d) <destination language>]
[(–filename|–file|-f) <filename>|<text to translate> …]

The script translate some text from one language to another, giving the result on standard output.

By default, translate runs as a filter (accepting text to translate on standard input and outputting the result to standard output).

Source language defaults to auto-detection (which can be specified with “-s -“) and destination language defaults to English. Languages should be entered as language codes, for instance en, de, es. Inspect http://translate.google.com for a full list of supported languages. If auto-detection is used, the language detected will be shown on stderr.

If there are no non-option arguments the text to translate is taken from stdin by default (which is the same as giving “-f -“). If there are non-option arguments these are instead taken as the source text. If you want to use it this way, it’s best to give the argument “–” to show that no more options will appear. Alternatively a file can be used as input by using the -f option.

All information and error messages go to standard error and so quiet operation is possible by redirecting stderr to /dev/null, for example
translate -d de -f story_en.txt 2>/dev/null

The –verbose or -v switch enables verbose output (to stderr).

Popular Posts:

Flattr this!

  2 Responses to “Google-Translate from command line”

  1. […] command-line translation Filed under: Linux — 0ddn1x @ 2010-09-07 19:18:57 +0000 http://www.linuxaria.com/pills/google-translate-da-linea-di-comando Leave a Comment TrackBack […]

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*