コード例 #1
0
 def translate(self, text, engine):
     # I should not hardcode fr and to languages here
     # Force async
     import settings, trman
     lang = settings.reader().userLanguage()
     return trman.manager().translate(
         text, engine=engine, fr='ja', to=lang, async=True)[0] or ''
コード例 #2
0
ファイル: mttest.py プロジェクト: blackknifes/VNR-Core
    def _translate(self):
        t = self._currentText()
        if t:
            dprint("enter")
            self._clearTranslations()
            self.translatorLabel.setText(self.translatorEdit.currentText())
            fr = self._currentFromLanguage()
            scriptEnabled = self._isTranslationScriptEnabled()
            params = {
                'fr': fr,
                'engine': self._currentTranslator(),
                #'ehndEnabled': scriptEnabled, # no longer change ehndEnabled
            }
            raw = trman.manager().translateTest(t, **params)
            if raw:
                self.directTranslationEdit.setPlainText(raw)

            if self._isGameTermsEnabled():
                #to = self._currentToLanguage()
                tt = textutil.normalize_punct(t)
                tt = termman.manager().applyGameTerms(tt, fr=fr)  #, to=to)
                if tt != t:
                    t = tt
                    self.setGameTextEditText(t or _EMPTY_TEXT)
                else:
                    self.setGameTextEditText(_EMPTY_TEXT)
            else:
                self.gameTextEdit.setPlainText(_DISABLED_TEXT)
            if t:
                mark = self._isMarkEnabled()
                t = trman.manager().translate(t,
                                              emit=True,
                                              mark=mark,
                                              scriptEnabled=scriptEnabled,
                                              **params)
                if t:
                    if settings.global_().isTermRubyEnabled():
                        t = richutil.renderRubyToPlainText(t)
                    self.finalTranslationEdit.setHtml(t)
            dprint("leave")
コード例 #3
0
    def __init__(self, q):
        ss = settings.global_()
        self._rubyEnabled = ss.isRubyEnabled()
        self._ttsEnabled = ss.isTtsEnabled()  # cached
        self._fullTranslationEnabled = ss.isFullTranslationEnabled()  # cached
        self._translationTipEnabled = ss.isTranslationTipEnabled()  # cached

        self.loadProgress = 100  # int [0,100]

        self.visitedUrls = []  # [str url]
        self.closedUrls = []  # [str url]

        import jlpman, trman, ttsman
        self._jlpAvailable = jlpman.manager().isAvailable()  # bool
        self._ttsAvailable = ttsman.manager().isAvailable()  # bool
        self._translatorAvailable = trman.manager().isAvailable()  # bool

        #layout = QtWidgets.QVBoxLayout()
        #layout.addWidget(self.addressWidget)
        #layout.addWidget(self.tabWidget)

        #w = QtWidgets.QWidget()
        #w.setLayout(layout)
        #layout.setContentsMargins(0, 0, 0, 0)
        #q.setCentralWidget(w)

        q.setCentralWidget(self.tabWidget)
        dock = SkTitlelessDockWidget(self.addressWidget)
        dock.setFeatures(QtWidgets.QDockWidget.NoDockWidgetFeatures)
        dock.setAllowedAreas(Qt.TopDockWidgetArea)
        q.addDockWidget(Qt.TopDockWidgetArea, dock)

        self._createShortcuts(q)
        self._createGestures()

        from PySide.QtCore import QCoreApplication
        qApp = QCoreApplication.instance()
        qApp.aboutToQuit.connect(self._onQuit)

        #self.newTabAfterCurrentWithBlankPage()

        self.loadVisitedUrls()
        self.loadClosedUrls()
コード例 #4
0
ファイル: mttest.py プロジェクト: blackknifes/VNR-Core
    def __init__(self, q):
        self._createUi(q)

        tm = trman.manager()

        tm.languagesReceived.connect(lambda fr, to:
                                     (self.setFromLanguageLabelText(fr),
                                      self.setToLanguageLabelText(to)))
        tm.normalizedTextReceived.connect(
            lambda t: self.normalizedTextEdit.setPlainText(t or _EMPTY_TEXT))
        tm.inputTextReceived.connect(
            lambda t: self.inputTextEdit.setPlainText(t or _EMPTY_TEXT))
        tm.encodedTextReceived.connect(
            lambda t: self.encodedTextEdit.setPlainText(t or _EMPTY_TEXT))
        tm.delegateTextReceived.connect(
            lambda t: self.delegateTextEdit.setPlainText(t or _EMPTY_TEXT))

        tm.splitTextsReceived.connect(
            lambda l: self.splitTextEdit.setPlainText('\n--------\n'.join(l)
                                                      if l else _EMPTY_TEXT))

        tm.delegateTranslationReceived.connect(
            lambda t: self.delegateTranslationEdit.setPlainText(t or
                                                                _EMPTY_TEXT))
        tm.jointTranslationReceived.connect(
            lambda t: self.jointTranslationEdit.setPlainText(t or _EMPTY_TEXT))

        tm.outputSyntacticTranslationReceived.connect(
            lambda t: self.outputSyntacticTranslationEdit.setHtml(t or
                                                                  _EMPTY_TEXT))
        tm.decodedTranslationReceived.connect(
            lambda t: self.decodedTranslationEdit.setHtml(t or _EMPTY_TEXT))
        tm.outputTranslationReceived.connect(
            lambda t: self.outputTranslationEdit.setHtml(t or _EMPTY_TEXT))

        tm.splitTranslationsReceived.connect(
            lambda l: self.splitTranslationEdit.setHtml(
                '<br/>--------<br/>'.join(l) if l else _EMPTY_TEXT))
コード例 #5
0
    def translatorManager(self):
        dprint("create translator manager")
        import trman
        ret = trman.manager()
        ret.setParent(self.q)

        ss = settings.global_()
        reader = settings.reader()

        if not reader.jbeijingLocation() and ss.isJBeijingEnabled():
            ss.setJBeijingEnabled(False)

        if not reader.fastaitLocation() and ss.isFastaitEnabled():
            ss.setFastaitEnabled(False)

        if not reader.ezTransLocation() and ss.isEzTransEnabled():
            ss.setEzTransEnabled(False)

        if not reader.dreyeLocation() and ss.isDreyeEnabled():
            ss.setDreyeEnabled(False)

        if not reader.atlasLocation() and ss.isAtlasEnabled():
            ss.setAtlasEnabled(False)

        if not reader.lecLocation() and ss.isLecEnabled():
            ss.setLecEnabled(False)

        ret.setInfoseekEnabled(ss.isInfoseekEnabled())
        ss.infoseekEnabledChanged.connect(ret.setInfoseekEnabled)

        ret.setExciteEnabled(ss.isExciteEnabled())
        ss.exciteEnabledChanged.connect(ret.setExciteEnabled)

        ret.setBingEnabled(ss.isBingEnabled())
        ss.bingEnabledChanged.connect(ret.setBingEnabled)

        ret.setGoogleEnabled(ss.isGoogleEnabled())
        ss.googleEnabledChanged.connect(ret.setGoogleEnabled)

        ret.setTransruEnabled(ss.isTransruEnabled())
        ss.transruEnabledChanged.connect(ret.setTransruEnabled)

        ret.setBaiduEnabled(ss.isBaiduEnabled())
        ss.baiduEnabledChanged.connect(ret.setBaiduEnabled)

        ret.setLecOnlineEnabled(ss.isLecOnlineEnabled())
        ss.lecOnlineEnabledChanged.connect(ret.setLecOnlineEnabled)

        #ret.setYoudaoEnabled(ss.isYoudaoEnabled())
        #ss.youdaoEnabledChanged.connect(ret.setYoudaoEnabled)

        ret.setHanVietEnabled(ss.isHanVietEnabled())
        ss.hanVietEnabledChanged.connect(ret.setHanVietEnabled)

        ret.setJBeijingEnabled(ss.isJBeijingEnabled())
        ss.jbeijingEnabledChanged.connect(ret.setJBeijingEnabled)

        ret.setFastaitEnabled(ss.isFastaitEnabled())
        ss.fastaitEnabledChanged.connect(ret.setFastaitEnabled)

        ret.setDreyeEnabled(ss.isDreyeEnabled())
        ss.dreyeEnabledChanged.connect(ret.setDreyeEnabled)

        ret.setEzTransEnabled(ss.isEzTransEnabled())
        ss.ezTransEnabledChanged.connect(ret.setEzTransEnabled)

        ret.setAtlasEnabled(ss.isAtlasEnabled())
        ss.atlasEnabledChanged.connect(ret.setAtlasEnabled)

        ret.setLecEnabled(ss.isLecEnabled())
        ss.lecEnabledChanged.connect(ret.setLecEnabled)

        #ret.setEnabled(ss.isTranslationEnabled())
        #ss.translationEnabledChanged.connect(ret.setEnabled)
        return ret
コード例 #6
0
 def translators(self):  # [str translator_name]
     import trman
     return ','.join(trman.manager().enabledEngines())
コード例 #7
0
        if not d.enabled:
            return
        fr = dataman.manager().currentGameLanguage()
        dprint("fr = %s" % fr)
        if not fr:
            return

        import gameagent, settings
        t = not settings.global_().isGameAgentEnabled(
        ) or not gameagent.global_().isConnected()
        dprint("game = %s" % t)
        if t:
            d.warmupTerms('game', d.targetLanguage, fr)

        import trman
        tos = trman.manager().getTranslationTargetLanguages()
        if not tos:
            return

        dprint("to = %s" % tos)
        for to in tos:
            for type in 'input', 'trans', 'output_nosyntax':  #'output_syntax':
                d.warmupTerms(type, to, fr)

    #  task = partial(d.warmup,
    #      terms=dm.terms(),
    #      hasTitles=dm.hasTermTitles(),
    #      hentai=d.hentai,
    #      language=d.language)

    #  if not async:
コード例 #8
0
ファイル: textreader.py プロジェクト: blackknifes/VNR-Core
 def _translateTextAndShow(self, text, time):
     trman.manager().translateApply(self._showTranslation,
                                    text,
                                    self.gameLanguage,
                                    time=time)