mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-31 04:46:11 +01:00
Fix error translation
This commit is contained in:
parent
99df19347b
commit
23e2e73ab7
@ -23,9 +23,9 @@ class Translation:
|
||||
def translate(self, page, word, language, error=True):
|
||||
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:
|
||||
translated_word = self.translate_inner(page, word, fallback_language)
|
||||
translated_word = self.translate_inner(page, word, fallback_language, error)
|
||||
|
||||
if translated_word:
|
||||
if isinstance(translated_word, dict):
|
||||
@ -41,7 +41,7 @@ class Translation:
|
||||
return "Error while getting translation"
|
||||
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)
|
||||
try:
|
||||
if not self.cached_translation:
|
||||
@ -59,6 +59,7 @@ class Translation:
|
||||
try:
|
||||
translated_page = data[page]
|
||||
except KeyError:
|
||||
if error:
|
||||
logger.error(
|
||||
f"Translation File Error: page {page} "
|
||||
f"does not exist for lang {language}"
|
||||
@ -73,6 +74,7 @@ class Translation:
|
||||
translated_word = translated_page[word]
|
||||
return translated_word
|
||||
except KeyError:
|
||||
if error:
|
||||
logger.error(
|
||||
f"Translation File Error: word {word} does not exist on page "
|
||||
f"{page} for lang {language}"
|
||||
@ -84,6 +86,7 @@ class Translation:
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
if error:
|
||||
logger.critical(
|
||||
f"Translation File Error: Unable to read {language_file} due to {e}"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user