Created
August 5, 2012 02:19
-
-
Save bryant/3261156 to your computer and use it in GitHub Desktop.
Quickie CLI interface to Google Translate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USER_AGENT="Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Firefox/17.0" | |
translate () { | |
slang="$1" | |
tlang="$2" | |
shift | |
shift | |
phrase="$@" | |
post_data="sl=$slang&tl=$tlang&js=n&prev=_t&hl=$tlang&\ | |
ie=UTF-8&layout=2&eotf=1&text=${phrase// /+}&file=" | |
url="http://translate.google.com" | |
wget -q -O - --user-agent="$USER_AGENT" \ | |
--post-data="$post_data" \ | |
$url | \ | |
grep --only-matching "<span title=\"$phrase\"[^>]*>[^<]*</span>" | |
echo | |
} | |
translate $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment