From b0c7683be98237db4b5b702139e2d206dee2cc46 Mon Sep 17 00:00:00 2001 From: WhatDidYouExpect <89535984+WhatDidYouExpect@users.noreply.github.com> Date: Sun, 6 Jul 2025 21:55:51 +0200 Subject: [PATCH] sliently fallback + add a fallback key in example.py and en.json but NOT it.json --- example.py | 3 ++- locales/en.json | 3 ++- main.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/example.py b/example.py index cf3aa8d..c2814d7 100644 --- a/example.py +++ b/example.py @@ -1,3 +1,4 @@ from main import _ -print(_("hello_key")) \ No newline at end of file +print(_("hello_key")) +print(_("fallback_key")) \ No newline at end of file diff --git a/locales/en.json b/locales/en.json index 1fdcd8b..0452f0d 100644 --- a/locales/en.json +++ b/locales/en.json @@ -1,3 +1,4 @@ { - "hello_key": "Hello World!" + "hello_key": "Hello World!", + "fallback_key": "This is a fallback!" } \ No newline at end of file diff --git a/main.py b/main.py index 3c87219..8f4f05e 100644 --- a/main.py +++ b/main.py @@ -91,7 +91,7 @@ def get_translation(lang: str, key: str): if key in lang_translations: return lang_translations[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 def _(key: str) -> str: