Skip to content

Instantly share code, notes, and snippets.

@comm1x
Last active December 18, 2015 10:56
Show Gist options
  • Save comm1x/12e826390cd795e007ae to your computer and use it in GitHub Desktop.
Save comm1x/12e826390cd795e007ae to your computer and use it in GitHub Desktop.
Translate text in clipboard
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