LOCALES = ( {"id": "en", "country": "美国", "language": "英语", "native": "English", "tag": "en_US"}, {"id": "zhHans", "country": "中国大陆", "language": "简体中文", "native": "简体中文", "tag": "zh_CN"}, {"id": "ko", "country": "韩国", "language": "韩语", "native": "한국어", "tag": "ko_KR"}, {"id": "zh", "country": "中国台湾", "language": "繁体中文", "native": "繁體中文", "tag": "zh_TW"}, {"id": "es", "country": "西班牙", "language": "西班牙语", "native": "Español", "tag": "es_ES"}, {"id": "in", "country": "印度尼西亚", "language": "印尼语", "native": "Bahasa Indonesia", "tag": "in_ID"}, {"id": "ja", "country": "日本", "language": "日语", "native": "日本語", "tag": "ja_JP"}, {"id": "de", "country": "德国", "language": "德语", "native": "Deutsch", "tag": "de_DE"}, {"id": "fr", "country": "法国", "language": "法语", "native": "Français", "tag": "fr_FR"}, {"id": "pt", "country": "巴西", "language": "葡萄牙语", "native": "Português", "tag": "pt_BR"}, {"id": "ar", "country": "阿拉伯", "language": "阿拉伯语", "native": "العربية", "tag": "ar_SA"}, {"id": "th", "country": "泰国", "language": "泰语", "native": "ไทย", "tag": "th_TH"}, {"id": "tl", "country": "菲律宾", "language": "菲律宾语", "native": "Filipino", "tag": "tl_PH"}, {"id": "vi", "country": "越南", "language": "越南语", "native": "Tiếng Việt", "tag": "vi_VN"}, {"id": "it", "country": "意大利", "language": "意大利语", "native": "Italiano", "tag": "it_IT"}, {"id": "tr", "country": "土耳其", "language": "土耳其语", "native": "Türkçe", "tag": "tr_TR"}, {"id": "pl", "country": "波兰", "language": "波兰语", "native": "Polski", "tag": "pl_PL"}, ) 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}"