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
This commit is contained in:
2026-05-08 15:31:44 +08:00
parent b05cfd2c0e
commit 1318e766d5
14 changed files with 789 additions and 209 deletions

43
shared/i18n.ts Normal file
View File

@@ -0,0 +1,43 @@
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'
}