Exemplo n.º 1
0
 def init_translator(self):
     try:
         self.translator = Translator()
         self.translator.set_provider("yandex")
         self.langs = self.translator.get_langs()
     except Exception as e:
         message = Message()
         message.level("error") \
                 .title("Error on start") \
                 .message(str(e)) \
                 .show()
         quit()
Exemplo n.º 2
0
    def translate(self):
        text = self.source_txt.toPlainText()
        message = Message()

        if text == "":
            message.level("warn") \
                    .title("Can't translate") \
                    .message("You need to write something!") \
                    .show()
            return
        if self._from == "":
            message.level("warn") \
                    .title("Can't translate") \
                    .message("Choose a source language") \
                    .show()
            return
        if self._to == "":
            message.level("warn") \
                    .title("Can't translate") \
                    .message("Choose a target language") \
                    .show()
            return

        try:
            translated = self.translator.translate(text, self._from, self._to)
            self.output_txt.setPlainText(translated)
        except Exception as e:
            message.level("error") \
                    .title("Something wrong happen") \
                    .message(str(e)) \
                    .show()