Command line translate with Google APIs
This file contains 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
# $ 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