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.
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.
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)
Updated 08-09-2011 at 05:49 PM by MrCode ("Transhlate"? WTF? :p)
Tags google, linux, programming
I present "gtsh" (Google Translate for the SHell), a tiny(!) shell script that acts as a frontend to Google Translate:
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:
Shallow post…could be useful, though… >_>
Code:
#!/bin/bash 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)" else wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-$3}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; fi
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:
Code:
[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 ~]$
Total Comments 1
Comments
-
Had to try your code....
Posted 08-21-2011 at 04:49 AM by peonuser
Updated 08-22-2011 at 10:24 PM by peonuser