Skip to content

Instantly share code, notes, and snippets.

@mehranz
Created December 3, 2018 20:00
Show Gist options
  • Select an option

  • Save mehranz/3640a665bdf051b83888723a074d507d to your computer and use it in GitHub Desktop.

Select an option

Save mehranz/3640a665bdf051b83888723a074d507d to your computer and use it in GitHub Desktop.
a script to translate english to persian and persian to english with google translate and show the result as notification
#!/bin/bash
text="$@"
if [[ "$text" =~ ^[a-z] ]];then
translate="$(wget -U "Mozilla/5.0" -qO - "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=fa&dt=t&q=$(echo $text | sed "s/[\"'<>]//g")" | sed "s/,,,0]],,.*//g" | awk -F'"' '{print $2}')"
else
translate="$(wget -U "Mozilla/5.0" -qO - "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=$(echo $text | sed "s/[\"'<>]//g")" | sed "s/,,,0]],,.*//g" | awk -F'"' '{print $2}')"
fi
notify-send "$translate"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment