scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

commit 6e5516496ce07ab96faf6c023ca3cb6825fe0483
parent 8b8b7a58139341c599021d1609217ab8a0c121e3
Author: lostd <lostd@2f30.org>
Date:   Fri, 23 Aug 2013 00:13:06 +0300

style fixes, use environment variables for languages

Diffstat:
Mtranslate | 28+++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/translate b/translate @@ -1,14 +1,20 @@ #!/bin/sh -if test -z "$1" -then - echo usage: $0 text - exit +# use the google translate service +# depends: curl + +if test -z "$1"; then + echo "usage: $(basename $0) text" + echo "examples:" + echo " $(basename $0) text" + echo " TL=el $(basename $0) text" + echo " SL=en TL=pl $(basename $0) text" + exit 1 fi TEXT=$1 -SL=auto -TL=el +SL=$(test -n "$SL" && echo "$SL" || echo auto) +TL=$(test -n "$TL" && echo "$TL" || echo en) TRANSLATEURL='http://translate.google.com/' UA='Mozilla 5.0' @@ -17,8 +23,8 @@ NEWLINE='\ # do translate curl --user-agent "$UA" \ - --data "sl=$SL" \ - --data "tl=$TL" \ - --data-urlencode "text=$TEXT" \ - --silent $TRANSLATEURL \ - | sed "s/<\/span>/$NEWLINE/g" | grep result_box | sed 's/.*>//' + --data "sl=$SL" \ + --data "tl=$TL" \ + --data-urlencode "text=$TEXT" \ + --silent $TRANSLATEURL \ + | sed "s/<\/span>/$NEWLINE/g" | grep 'result_box' | sed 's/.*>//'