From d1b0e89261f672b64a09ca86a6187b60fc6a0170 Mon Sep 17 00:00:00 2001 From: Deeman Date: Tue, 24 Feb 2026 16:16:45 +0100 Subject: [PATCH] fix(i18n): country_name filter now handles 2-letter ISO codes from DB articles.country stores "CH"/"DE"/etc., not English names. Update get_country_name() to try the input as an uppercase code first, falling back to the reverse-name lookup for any English-name values. Co-Authored-By: Claude Opus 4.6 --- web/src/padelnomics/i18n.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/web/src/padelnomics/i18n.py b/web/src/padelnomics/i18n.py index a94ff9b..f6c60f9 100644 --- a/web/src/padelnomics/i18n.py +++ b/web/src/padelnomics/i18n.py @@ -184,7 +184,11 @@ _COUNTRY_CODE_BY_EN_NAME: dict[str, str] = {v: k for k, v in COUNTRY_LABELS.item def get_country_name(country_str: str, lang: str) -> str: - """Return the localised name for a country stored as an English name in the DB. + """Return the localised name for a country stored as a 2-letter code or English name. + + Handles both formats stored in the DB: + - 2-letter ISO code: "CH" → "Schweiz" (de) / "Switzerland" (en) + - English name: "Switzerland" → "Schweiz" (de) Falls back to the original string if not found in translations. Used as a Jinja filter: {{ article.country | country_name(lang) }} @@ -192,7 +196,9 @@ def get_country_name(country_str: str, lang: str) -> str: if not country_str: return country_str effective_lang = lang if lang in _TRANSLATIONS else "en" - code = _COUNTRY_CODE_BY_EN_NAME.get(country_str, "") + # Accept both 2-letter code ("CH") and English name ("Switzerland") + upper = country_str.upper() + code = upper if upper in COUNTRY_LABELS else _COUNTRY_CODE_BY_EN_NAME.get(country_str, "") if not code: return country_str key = f"dir_country_{code}"