offline translator for sublime

mail@pastecode.io avatar
unknown
python
2 years ago
690 B
18
Indexable
Never
import sublime
import sublime_plugin
import time
import os
import sys

dict_path = os.path.dirname(os.path.abspath(__file__)) + '\\full-eng-rus'

sys.path.insert(1, os.path.dirname(os.path.abspath(__file__)))
from pystardict import Dictionary

class OfflineTranslate(sublime_plugin.TextCommand):
	def run(self, edit):
		v = self.view
		word = v.substr(v.sel()[0])
		dict1 = Dictionary(dict_path)
		try:
			translate = dict1.dict[word.lower()]
		except:
			self.view.show_popup('I can\'t find this word', location=-1, on_navigate=print)
			raise ValueError('I can\'t find this word')

		self.view.show_popup(translate, location=-1, max_width=700, on_navigate=print)