Created
January 15, 2014 21:54
-
-
Save rafapolo/8445524 to your computer and use it in GitHub Desktop.
traduz no terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
QUERY=$* | |
# Split Alfred query into parts: | |
SOURCE_LANGUAGE=`echo "$QUERY" | awk '{ print $1; }' ` | |
DESTINATION_LANGUAGE=`echo "$QUERY"| awk '{ print $2; }' ` | |
# Transform the text to something Google translate understands | |
set +o histexpand | |
TEXT_TO_TRANSLATE=$(echo "$QUERY"|sed 's/ /+/g'|sed 's/'$SOURCE_LANGUAGE'//'|sed 's/'$DESTINATION_LANGUAGE'//') | |
# Call Google and ask for the answer | |
curl -s -A "Mozilla" "http://translate.google.com.br/translate_a/t?client=t&text=$TEXT_TO_TRANSLATE&hl=pt-BR&sl=$SOURCE_LANGUAGE&tl=$DESTINATION_LANGUAGE&multires=1&ssel=0&tsel=0&sc=1" | iconv -f iso8859-1 -t utf-8 | awk -F'"' '{print $2}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment