Review your favorite Linux distribution.
Go Back > Blogs > MrCode
User Name


This is the first "blog" of any kind I've ever had, so it's probably not the greatest...

Just a little snippet about me:

I'd like to consider myself relatively tech-savvy; obviously I use Linux (Arch to be precise; K.I.S.S. FTW), and I enjoy learning new things about computers in general (both software and hardware-related).

This blog is mostly just for whenever I feel like telling the world about my experiences with computers/Linux (or just life in general), or just posting for the hell of it.
Rate this Entry

gtsh: how to use Google Translate without touching a web browser

Posted 08-09-2011 at 05:49 PM by MrCode
Updated 08-09-2011 at 05:49 PM by MrCode ("Transhlate"? WTF? :p)

I present "gtsh" (Google Translate for the SHell), a tiny(!) shell script that acts as a frontend to Google Translate:

if test -z $3; then
	echo "Usage: $0 \"<str>\" <lang1> <lang2>"
	echo "Translates string \"<str>\" from <lang1> to <lang2>"
	echo "(CLI frontend to Google Translate)"
	wget -qO- "$1&langpair=$2|${3:-$3}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/';
I found the original "script" here, and I adapted it to be just a tad more flexible.

The only thing is that you have to provide a valid two-letter language code for <lang1> and <lang2> (e.g. "es", "fr", "de", "zh", etc.), otherwise it'll just spit back the part of the page that shows an error (without a trailing newline, I might add O_o). For example:

[mrcode@lappy486 ~]$ gtsh "The quick brown fox jumps over the lazy dog." en de
Der schnelle braune Fuchs springt über den faulen Hund.
[mrcode@lappy486 ~]$ gtsh "The quick brown fox jumps over the lazy dog." en blah
{"responseData": null, "responseDetails": "invalid translation language pair", "responseStatus": 400}[mrcode@lappy486 ~]$
Shallow post…could be useful, though… >_>
Views 12112 Comments 1
« Prev     Main     Next »
Total Comments 1


  1. Old Comment
    Had to try your code....
    Posted 08-21-2011 at 04:49 AM by peonuser peonuser is offline
    Updated 08-22-2011 at 10:24 PM by peonuser


All times are GMT -5. The time now is 12:05 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration