From 67a7a6a6beeae2b36de38c4dd59d4895b6a188bc Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 5 Mar 2015 17:16:19 +0100 Subject: utils: normalize naming of google wrappers --- util/bin/google.translate | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 util/bin/google.translate (limited to 'util/bin/google.translate') diff --git a/util/bin/google.translate b/util/bin/google.translate new file mode 100755 index 00000000..06c6a5a8 --- /dev/null +++ b/util/bin/google.translate @@ -0,0 +1,27 @@ +#! /bin/sh +set -euf + +sl=${SL:="auto"} +tl=${TL:="en"} + +usage(){ + echo 'TL= targetlanguage, valid strings are in the style of "en", "pl" or "de". default "en"' + echo 'SL= sourcelanguage, same TL, default is auto' + echo 'Example: TL="de" ./translate.google "whats up?"' + + exit 0 +} + +translate(){ + text=$* + url="http://translate.google.com/translate_a/t?client=t&sl=$sl&tl=$tl" + curl -A "Mozilla/5.0" -Ss "$url" --data-urlencode "text=$text" | + sed 's/\[\[\[\"//' | + cut -d \" -f 1 +} + +if [ $# -eq 0 ]; then + usage +fi + +translate $* -- cgit v1.2.3