Files
dticket.tootaio.com/shared/i18n.ts
xiaomai 1318e766d5 feat(i18n): add multi-language support (en/zh) across app and server
Implement useLocale composable and shared translation dictionaries
Translate public pages, booking flow, and receipt views
Store booking locale to send localized WhatsApp notifications
2026-05-08 15:31:44 +08:00

44 lines
947 B
TypeScript

export const SUPPORTED_LOCALES = ['en', 'zh'] as const
export type AppLocale = typeof SUPPORTED_LOCALES[number]
export const DEFAULT_LOCALE: AppLocale = 'en'
export const LOCALE_OPTIONS: Array<{
value: AppLocale
label: string
shortLabel: string
}> = [
{
value: 'en',
label: 'English',
shortLabel: 'EN'
},
{
value: 'zh',
label: '中文',
shortLabel: '中'
}
]
export function resolveLocale(value: string | null | undefined, fallback: AppLocale = DEFAULT_LOCALE): AppLocale {
const normalized = String(value || '').trim().toLowerCase()
if (!normalized) {
return fallback
}
if (normalized === 'zh' || normalized.startsWith('zh-') || normalized.startsWith('cn')) {
return 'zh'
}
if (normalized === 'en' || normalized.startsWith('en-')) {
return 'en'
}
return fallback
}
export function getOppositeLocale(locale: AppLocale): AppLocale {
return locale === 'zh' ? 'en' : 'zh'
}