Skip to content

Instantly share code, notes, and snippets.

@syui
Created October 26, 2013 07:13
Show Gist options
  • Save syui/7166264 to your computer and use it in GitHub Desktop.
Save syui/7166264 to your computer and use it in GitHub Desktop.
# google_translate [-j, -e]
# $ google_translate -e power line
function google_translate() {
local str opt arg
str=`pbpaste` # clipboard
arg=`echo ${@:2} | sed -e 's/ */+/g'` # argument
en_jp="?hl=ja&sl=en&tl=ja&ie=UTF-8&oe=UTF-8" # url
case "$1" in
"-j") opt="?hl=ja&sl=ja&tl=en&ie=UTF-8&oe=UTF-8&text=${arg}";; # jp -> en translate
"-e") opt="${en_jp}&text=${arg}";; # en -> jp translate
*) opt="${en_jp}&text=${str}";; # en -> jp translate
esac
w3m +20 "http://translate.google.com/${opt}" # goto 20 line
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment