Skip to content

Instantly share code, notes, and snippets.

@hanksudo
Last active January 17, 2016 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanksudo/bc873267d85b00d79baf to your computer and use it in GitHub Desktop.
Save hanksudo/bc873267d85b00d79baf to your computer and use it in GitHub Desktop.
Google Translate API shell script
#!/bin/sh
usage ()
{
echo 'Usage :'
echo "\t$0 Text"
exit
}
if [ "$#" -ne 1 ]
then
usage
fi
# Set your API KEY here.
APIKEY=""
declare -a arr=("zh-tw" "ja")
for LANG in "${arr[@]}"
do
RESULT=`curl -s https://www.googleapis.com/language/translate/v2?q=$1\&target=zh-tw\&key=$APIKEY 2>/dev/null | sed -n -e '/"translatedText":/ s/^.*"\(.*\)".*/\1/p'`
echo $LANG: $RESULT
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment