sliently fallback + add a fallback key in example.py and en.json but NOT it.json

This commit is contained in:
WhatDidYouExpect 2025-07-06 21:55:51 +02:00
parent 39d7a46b56
commit b0c7683be9
3 changed files with 5 additions and 3 deletions

View file

@ -1,3 +1,4 @@
from main import _ from main import _
print(_("hello_key")) print(_("hello_key"))
print(_("fallback_key"))

View file

@ -1,3 +1,4 @@
{ {
"hello_key": "Hello World!" "hello_key": "Hello World!",
"fallback_key": "This is a fallback!"
} }

View file

@ -91,7 +91,7 @@ def get_translation(lang: str, key: str):
if key in lang_translations: if key in lang_translations:
return lang_translations[key] return lang_translations[key]
fallback = translations.get("en", {}).get(key, key) fallback = translations.get("en", {}).get(key, key)
print(f"{RED}Missing key: '{key}' in language '{lang}', falling back to: '{fallback}'{RESET}") #print(f"{RED}Missing key: '{key}' in language '{lang}', falling back to: '{fallback}'{RESET}")
return fallback return fallback
def _(key: str) -> str: def _(key: str) -> str: