Files
moeka-project/packages/i18n/src/index.ts
T
f85a809d7c refactor(stage-*): analytics and telemetry, including consent (#1414)
---------

Co-authored-by-agent: Codex <267193182+codex@users.noreply.github.com>
Co-authored-by-agent: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: RainbowBird <rbxin2003@outlook.com>
Co-authored-by: Neko <neko@ayaka.moe>
2026-03-24 13:01:39 +08:00

50 lines
1.0 KiB
TypeScript

export const all = {
'en': 'English',
'es': 'Español',
'fr': 'Français',
'ja': '日本語',
'ko': '한국어',
'ru': 'Русский',
'vi': 'Tiếng Việt',
'zh-Hans': '简体中文',
'zh-Hant': '繁體中文',
}
export const localeRemap: Record<string, string> = {
'zh-CN': 'zh-Hans',
'zh-TW': 'zh-Hant',
'zh-HK': 'zh-Hans',
'zh-Hant': 'zh-Hant',
'zh-Hans': 'zh-Hans',
'en': 'en',
'en-US': 'en',
'en-GB': 'en',
'en-AU': 'en',
'es': 'es',
'es-ES': 'es',
'es-MX': 'es',
'es-AR': 'es',
'fr': 'fr',
'fr-FR': 'fr',
'ja': 'ja',
'ja-JP': 'ja',
'ko': 'ko',
'ko-KR': 'ko',
'ru': 'ru',
'ru-RU': 'ru',
'vi': 'vi',
'vi-VN': 'vi',
}
export function resolveSupportedLocale(
locale: string | null | undefined,
supportedLocales: readonly string[],
fallbackLocale = 'en',
): string {
const normalizedLocale = localeRemap[locale ?? fallbackLocale] ?? locale ?? fallbackLocale
return supportedLocales.includes(normalizedLocale)
? normalizedLocale
: fallbackLocale
}