"""Small runtime translation helper for the desktop UI."""

from __future__ import annotations


SUPPORTED_LANGUAGES = {"en", "ja"}
_language = "en"


def normalize_language(language: object) -> str:
    code = str(language or "en").lower().replace("_", "-")
    return "ja" if code == "ja" or code.startswith("ja-") else "en"


def set_language(language: object) -> str:
    global _language
    _language = normalize_language(language)
    return _language


def current_language() -> str:
    return _language


def tr(english: str, japanese: str) -> str:
    return japanese if _language == "ja" else english


def tracks(count: int) -> str:
    if _language == "ja":
        return f"{count} 曲"
    return f"{count} track" if count == 1 else f"{count} tracks"
