ForcePilot/backend/package/yuxi/channel/extensions/msteams/localization.py

42 lines
1.3 KiB
Python
Raw Normal View History

from __future__ import annotations
LANG_MAP = {
"zh-cn": "zh",
"zh-tw": "zh",
"zh-hk": "zh",
"en-us": "en",
"en-gb": "en",
"ja-jp": "ja",
"ko-kr": "ko",
"fr-fr": "fr",
"de-de": "de",
"es-es": "es",
}
WELCOME_MESSAGES = {
"zh": "👋 欢迎使用!发送消息开始对话。",
"en": "👋 Welcome! Send a message to start a conversation.",
"ja": "👋 ようこそ!メッセージを送信して会話を始めてください。",
"ko": "👋 환영합니다! 메시지를 별내 대화를 시작하세요.",
"fr": "👋 Bienvenue ! Envoyez un message pour commencer une conversation.",
"de": "👋 Willkommen! Senden Sie eine Nachricht, um eine Unterhaltung zu beginnen.",
"es": "👋 ¡Bienvenido! Envíe un mensaje para iniciar una conversación.",
}
ERROR_MESSAGES = {
"zh": "抱歉,处理请求时出错: {error}",
"en": "Sorry, an error occurred processing your request: {error}",
}
def normalize_locale(locale: str | None) -> str:
if not locale:
return "en"
locale = locale.lower()
return LANG_MAP.get(locale, locale[:2] if len(locale) >= 2 else "en")
def get_localized(key: str, locale: str | None, messages: dict, default_lang: str = "en") -> str:
lang = normalize_locale(locale)
return messages.get(lang, messages.get(default_lang, ""))