Skip to content

Instantly share code, notes, and snippets.

@nkt
Last active August 29, 2015 14:23
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 nkt/46e41d10ff37e4884ca5 to your computer and use it in GitHub Desktop.
Save nkt/46e41d10ff37e4884ca5 to your computer and use it in GitHub Desktop.
CLI Yandex.Translate

Usage

trans hello # привет
trans hello | say # it's saying!
function trans {
# key from https://tech.yandex.ru/keys/
local key=""
local input=${@//[&]/%26}
local link="https://translate.yandex.net/api/v1.5/tr.json/translate?key=$key&lang="
function trans_translate() {
translated=$(curl -s "$link$key&lang=$1&text=$input" | awk -F'"' {' print $10 '})
}
trans_translate "ru"
if [[ "$translated" == "$input" ]]; then
trans_translate "en"
fi
echo $translated
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment