INNER CODE UNIT · Python

normalize_locale

GHJJ123/brainrotguard · i18n/__init__.py:22

def normalize_locale(locale: str | None) -> str:
    """Normalize user/config locale to a supported code."""
    if not locale:
        return DEFAULT_LOCALE
    value = locale.strip().lower().replace("_", "-")
    if value in ("no", "nn", "nb-no", "no-no"):
        return "nb"
    if value.startswith("nb"):
        return "nb"
    if value.startswith("en"):
        return "en"
    return DEFAULT_LOCALE


def get_locale(config) -> str:
    """Extract normalized locale from config."""
    app = getattr(config, "app", None)
    return normalize_locale(getattr(app, "locale", DEFAULT_LOCALE))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…