Skip to content

Instantly share code, notes, and snippets.

@musdevs
Last active April 24, 2017 07:31
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 musdevs/e6df16a8e0df98e596e973dae048e8a7 to your computer and use it in GitHub Desktop.
Save musdevs/e6df16a8e0df98e596e973dae048e8a7 to your computer and use it in GitHub Desktop.
Скрипт для перевода выделенного текста с помощью Яндекс переводчика
#!/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