Last active
December 18, 2015 10:56
-
-
Save comm1x/12e826390cd795e007ae to your computer and use it in GitHub Desktop.
Translate text in clipboard
This file contains hidden or 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
import os | |
import gtk | |
from textblob import TextBlob | |
word = gtk.clipboard_get(selection="PRIMARY").wait_for_text() | |
if not word: | |
word = gtk.clipboard_get(selection="CLIPBOARD").wait_for_text() | |
if word: | |
source_lang = TextBlob(word).detect_language() | |
target_lang = 'ru' if source_lang == 'en' else 'en' | |
translate = TextBlob(word.lower()).translate(to=target_lang) | |
os.system('notify-send "%s"' % translate) | |
else: | |
os.system('notify-send "No word"') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment