Instantly share code, notes, and snippets.

Embed
What would you like to do?
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