trans hello # привет
trans hello | say # it's saying!
Last active
August 29, 2015 14:23
-
-
Save nkt/46e41d10ff37e4884ca5 to your computer and use it in GitHub Desktop.
CLI Yandex.Translate
This file contains 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
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