tGoogle translate on the cli - scripts - various script and utils
 (HTM) git clone git://z3bra.org/scripts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit a3214a8626c38015ae208537130f6dcfea6ddcf6
 (DIR) parent 66415b1db97dc8de8d413d8a8adab84195c81ef1
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Wed, 26 Mar 2014 19:42:32 +0100
       
       Google translate on the cli
       
       Diffstat:
         A translate                           |      30 ++++++++++++++++++++++++++++++
       
       1 file changed, 30 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/translate b/translate
       t@@ -0,0 +1,30 @@
       +#!/bin/sh
       +
       +# 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=$(test -n "$SL" && echo "$SL" || echo auto)
       +TL=$(test -n "$TL" && echo "$TL" || echo en)
       +
       +TRANSLATEURL='http://translate.google.com/'
       +UA='Mozilla 5.0'
       +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/.*>//'