From 4b0b573645d5614c5dfb58d8663168eda6ae0af9 Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Sat, 16 Sep 2023 03:03:52 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B[bugfix]=20=E7=BF=BB=E8=A8=B3?= =?UTF-8?q?=E3=82=A8=E3=83=B3=E3=82=B8=E3=83=B3=E3=82=92=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=81=97=E3=81=9F=E6=99=82=E3=81=AB=E5=B8=B8=E3=81=ABmodel.aut?= =?UTF-8?q?henticationTranslator(...)=E3=82=92=E8=A1=8C=E3=81=86=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit エンジン変更時にmodel.translator.translator_statusのステータスを変更する必要があった --- main.py | 11 ++++++++ models/translation/translation_translator.py | 28 ++++++++++---------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index c09a0755..d4ec38ff 100644 --- a/main.py +++ b/main.py @@ -162,6 +162,7 @@ def setYourLanguageAndCountry(select): config.SOURCE_LANGUAGE = language config.SOURCE_COUNTRY = country config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) + model.authenticationTranslator(callbackSetAuthKeys) def setTargetLanguageAndCountry(select): languages = config.SELECTED_TAB_TARGET_LANGUAGES @@ -171,6 +172,7 @@ def setTargetLanguageAndCountry(select): config.TARGET_LANGUAGE = language config.TARGET_COUNTRY = country config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) + model.authenticationTranslator(callbackSetAuthKeys) def callbackSelectedLanguagePresetTab(selected_tab_no): config.SELECTED_TAB_NO = selected_tab_no @@ -186,6 +188,7 @@ def callbackSelectedLanguagePresetTab(selected_tab_no): config.TARGET_LANGUAGE = language config.TARGET_COUNTRY = country config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) + model.authenticationTranslator(callbackSetAuthKeys) def callbackSetAuthKeys(keys): config.AUTH_KEYS = keys @@ -299,7 +302,13 @@ def callbackSetDeeplAuthkey(value): print("callbackSetDeeplAuthkey", str(value)) if len(value) > 0 and model.authenticationTranslator(callbackSetAuthKeys, choice_translator="DeepL(auth)", auth_key=value) is True: config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) + model.authenticationTranslator(callbackSetAuthKeys) view.printToTextbox_AuthenticationSuccess() + elif len(value) == 0: + auth_keys = config.AUTH_KEYS + auth_keys["DeepL(auth)"] = None + config.AUTH_KEYS = auth_keys + model.authenticationTranslator(callbackSetAuthKeys) else: view.printToTextbox_AuthenticationError() @@ -521,6 +530,8 @@ view.createGUI() if model.authenticationTranslator(callbackSetAuthKeys) is False: # error update Auth key view.printToTextbox_AuthenticationError() + config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) + model.authenticationTranslator(callbackSetAuthKeys) # set word filter model.addKeywords() diff --git a/models/translation/translation_translator.py b/models/translation/translation_translator.py index b386835e..da4f911f 100644 --- a/models/translation/translation_translator.py +++ b/models/translation/translation_translator.py @@ -13,23 +13,23 @@ class Translator(): def authentication(self, translator_name, authkey=None): result = False - try: - if translator_name == "DeepL(web)": - self.translator_status["DeepL(web)"] = True - result = True - elif translator_name == "DeepL(auth)": + if translator_name == "DeepL(web)": + self.translator_status[translator_name] = True + result = True + elif translator_name == "DeepL(auth)": + try: self.deepl_client = deepl_Translator(authkey) self.deepl_client.translate_text(" ", target_lang="EN-US") - self.translator_status["DeepL(auth)"] = True + self.translator_status[translator_name] = True result = True - elif translator_name == "Google(web)": - self.translator_status["Google(web)"] = True - result = True - elif translator_name == "Bing(web)": - self.translator_status["Bing(web)"] = True - result = True - except: - pass + except: + self.translator_status[translator_name] = False + elif translator_name == "Google(web)": + self.translator_status[translator_name] = True + result = True + elif translator_name == "Bing(web)": + self.translator_status[translator_name] = True + result = True return result def translate(self, translator_name, source_language, target_language, message):