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}"