Skip to content

Instantly share code, notes, and snippets.

@hmcfletch
Created May 11, 2011 00:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hmcfletch/965650 to your computer and use it in GitHub Desktop.
Command line translate with Google APIs
# $ translate hola
# hello
# $ translate hello es
# hola
# $ translate hello fr
# bonjour
#
# USAGE:
#
# translate <phrase to translate> <destination language> [<source language>]
#
# destination language is assumed to be English unless otherwise specified
# source language is optional, it will try to auto detect the language if not present
#
translate() {
wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=${3:-}|${2:-en}" | sed -E -n 's/[[:alnum:]": {}]+"translatedText":"([^"]+)".*/\1/p';
echo ''
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment