mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-26 09:52:34 +00:00
tests: do not warn about missing translation if the key doesn't exist at all
otherwise code like the following raises an useless warning: >>> try: >>> value = translate(somekey) >>> except KeyError: >>> value = somekey # use a literal value as seen in click_tests/common.py _get_action_index
This commit is contained in:
parent
0c77c5102a
commit
c246ba4994
@ -99,11 +99,15 @@ class Translation:
|
|||||||
if tr is not None:
|
if tr is not None:
|
||||||
return tr
|
return tr
|
||||||
if self.lang != "en":
|
if self.lang != "en":
|
||||||
|
# check if the key exists in English first
|
||||||
|
retval = TRANSLATIONS["en"]._translate_raw(key)
|
||||||
|
# if not, a KeyError was raised so we fall through.
|
||||||
|
# otherwise, warn that the key is untranslated in target language.
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
f"Translation key '{key}' not found in '{self.lang}' translation file",
|
f"Translation key '{key}' not found in '{self.lang}' translation file",
|
||||||
stacklevel=_stacklevel + 2,
|
stacklevel=_stacklevel + 2,
|
||||||
)
|
)
|
||||||
return TRANSLATIONS["en"]._translate_raw(key)
|
return retval
|
||||||
raise KeyError(key)
|
raise KeyError(key)
|
||||||
|
|
||||||
def translate(self, key: str, _stacklevel: int = 0) -> str:
|
def translate(self, key: str, _stacklevel: int = 0) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user