Last active
April 24, 2017 07:31
-
-
Save musdevs/e6df16a8e0df98e596e973dae048e8a7 to your computer and use it in GitHub Desktop.
Скрипт для перевода выделенного текста с помощью Яндекс переводчика
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
#!/bin/sh | |
# The my private key can be get from https://tech.yandex.ru/keys/get/?service=trnsl | |
key="********************************************************" | |
# get selected text from active window | |
text="$(echo $(xsel -o) | sed "s/[\"\'<>]//g")" | |
# get translation from yandex | |
result="$(wget -qO - "https://translate.yandex.net/api/v1.5/tr.json/translate?key=$key&text=$text&lang=en-ru")" | |
# convert result from string: {"code":200,"lang":"en-ru","text":["читатель"]} | |
translate="$(echo $result | sed 's/.*\[\"\(.*\)\"\].*/\1/')" | |
# save translation log | |
echo "$text $translate" >> ~/translate.log | |
# show translation result | |
notify-send -u critical "$text" "$translate" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment