🐛[bugfix] 翻訳エンジンを変更した時に常にmodel.authenticationTranslator(...)を行うように修正

エンジン変更時にmodel.translator.translator_statusのステータスを変更する必要があった
This commit is contained in:
misyaguziya
2023-09-16 03:03:52 +09:00
parent 44463faa7b
commit 4b0b573645
2 changed files with 25 additions and 14 deletions

11
main.py
View File

@@ -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()

View File

@@ -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):