translate (625B)
1 #!/bin/sh 2 # 3 # parazyd - (c) wtfpl 2016 4 # use the google translate service 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=${SL:-en} 17 TL=${TL:-hr} 18 19 TRANSLATEURL='https://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/.*>//'