LOCALES = ( {"id": "en", "country": "美国", "language": "英语", "native": "English"}, {"id": "zhHans", "country": "中国大陆", "language": "简体中文", "native": "简体中文"}, {"id": "ko", "country": "韩国", "language": "韩语", "native": "한국어"}, {"id": "zh", "country": "中国台湾", "language": "繁体中文", "native": "繁體中文"}, {"id": "es", "country": "西班牙", "language": "西班牙语", "native": "Español"}, {"id": "in", "country": "印度尼西亚", "language": "印尼语", "native": "Bahasa Indonesia"}, {"id": "ja", "country": "日本", "language": "日语", "native": "日本語"}, {"id": "de", "country": "德国", "language": "德语", "native": "Deutsch"}, {"id": "fr", "country": "法国", "language": "法语", "native": "Français"}, {"id": "pt", "country": "巴西", "language": "葡萄牙语", "native": "Português"}, {"id": "ar", "country": "阿拉伯", "language": "阿拉伯语", "native": "العربية"}, {"id": "th", "country": "泰国", "language": "泰语", "native": "ไทย"}, {"id": "tl", "country": "菲律宾", "language": "菲律宾语", "native": "Filipino"}, {"id": "vi", "country": "越南", "language": "越南语", "native": "Tiếng Việt"}, {"id": "it", "country": "意大利", "language": "意大利语", "native": "Italiano"}, {"id": "tr", "country": "土耳其", "language": "土耳其语", "native": "Türkçe"}, {"id": "pl", "country": "波兰", "language": "波兰语", "native": "Polski"}, ) DEFAULT_LANGUAGE = "th" _BY_ID = {item["id"]: item for item in LOCALES} def resolve(language: str) -> dict: text = (language or "").strip() if text in _BY_ID: return dict(_BY_ID[text]) lowered = text.lower() for item in LOCALES: if item["id"].lower() == lowered: return dict(item) raise RuntimeError("不支持这个语言地区") def public_list() -> list[dict]: return [ { "id": item["id"], "country": item["country"], "language": item["language"], "native": item["native"], "label": f'{item["country"]} · {item["language"]}', } for item in LOCALES ] def film_path(language: str, book_id: str) -> str: locale = resolve(language)["id"] book_id = str(book_id or "").strip() if not book_id: raise RuntimeError("没有这部剧") if locale == "en": return f"/film/{book_id}" return f"/{locale}/film/{book_id}"