Fix error translation

This commit is contained in:
= 2025-01-19 12:52:16 -05:00
parent 99df19347b
commit 23e2e73ab7

View File

@ -23,9 +23,9 @@ class Translation:
def translate(self, page, word, language, error=True): def translate(self, page, word, language, error=True):
fallback_language = "en_EN" fallback_language = "en_EN"
translated_word = self.translate_inner(page, word, language) translated_word = self.translate_inner(page, word, language, error)
if translated_word is None: if translated_word is None:
translated_word = self.translate_inner(page, word, fallback_language) translated_word = self.translate_inner(page, word, fallback_language, error)
if translated_word: if translated_word:
if isinstance(translated_word, dict): if isinstance(translated_word, dict):
@ -41,7 +41,7 @@ class Translation:
return "Error while getting translation" return "Error while getting translation"
return word return word
def translate_inner(self, page, word, language) -> t.Union[t.Any, None]: def translate_inner(self, page, word, language, error) -> t.Union[t.Any, None]:
language_file = self.get_language_file(language) language_file = self.get_language_file(language)
try: try:
if not self.cached_translation: if not self.cached_translation:
@ -59,35 +59,38 @@ class Translation:
try: try:
translated_page = data[page] translated_page = data[page]
except KeyError: except KeyError:
logger.error( if error:
f"Translation File Error: page {page} " logger.error(
f"does not exist for lang {language}" f"Translation File Error: page {page} "
) f"does not exist for lang {language}"
Console.error( )
f"Translation File Error: page {page} " Console.error(
f"does not exist for lang {language}" f"Translation File Error: page {page} "
) f"does not exist for lang {language}"
)
return None return None
try: try:
translated_word = translated_page[word] translated_word = translated_page[word]
return translated_word return translated_word
except KeyError: except KeyError:
logger.error( if error:
f"Translation File Error: word {word} does not exist on page " logger.error(
f"{page} for lang {language}" f"Translation File Error: word {word} does not exist on page "
) f"{page} for lang {language}"
Console.error( )
f"Translation File Error: word {word} does not exist on page " Console.error(
f"{page} for lang {language}" f"Translation File Error: word {word} does not exist on page "
) f"{page} for lang {language}"
)
return None return None
except Exception as e: except Exception as e:
logger.critical( if error:
f"Translation File Error: Unable to read {language_file} due to {e}" logger.critical(
) f"Translation File Error: Unable to read {language_file} due to {e}"
Console.critical( )
f"Translation File Error: Unable to read {language_file} due to {e}" Console.critical(
) f"Translation File Error: Unable to read {language_file} due to {e}"
)
return None return None