Saturday, November 19, 2011

Google Translate from command line

translate(){ wget -qO- "$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; }
2010-03-08 03:15:48
Usage:translate <phrase> <source-language> <output-language> Example:translate hello en es
See this for a list of language codes:

translate() { lng1="$1";lng2="$2";shift;shift; wget -qO- "${@// /+}&langpair=$lng1|$lng2" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; }
allow multiword translations
cmd=$( wget -qO- "$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; ); echo "$cmd"
2010-03-13 01:09:00
translate <phrase> <source-language> <output-language> works from command line
wget -U "Mozilla/5.0" -qO - "" | sed 's/\[\[\[\"//' | cut -d \" -f 1
tl = target language (en, fr, de, hu, ...);
you can leave sl parameter as-is (autodetection works fine)
substitute "example" with desired string;
curl -s -A "Mozilla" "" | awk -F'"' '{print $2}'
Translates a phrase from English to Portuguese
Translates a string from English to Portuguese by using google translator web service. Source: