scripts

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

translate (678B)


      1 #!/bin/sh
      2 
      3 # use the google translate service
      4 # depends: curl
      5 
      6 if test -z "$1"; then
      7     echo "usage: $(basename $0) text"
      8     echo "examples:"
      9     echo "    $(basename $0) text"
     10     echo "    TL=el $(basename $0) text"
     11     echo "    SL=en TL=pl $(basename $0) text"
     12     exit 1
     13 fi
     14 
     15 TEXT=$1
     16 SL=$(test -n "$SL" && echo "$SL" || echo auto)
     17 TL=$(test -n "$TL" && echo "$TL" || echo en)
     18 
     19 TRANSLATEURL='http://translate.google.com/'
     20 UA='Mozilla 5.0'
     21 NEWLINE='\
     22 '
     23 
     24 # do translate
     25 curl --user-agent "$UA" \
     26     --data "sl=$SL" \
     27     --data "tl=$TL" \
     28     --data-urlencode "text=$TEXT" \
     29     --silent $TRANSLATEURL \
     30     | sed "s/<\/span>/$NEWLINE/g" | grep 'result_box' | sed 's/.*>//'