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:
43
shared/i18n.ts
Normal file
43
shared/i18n.ts
Normal 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'
|
||||
}
|
||||
Reference in New Issue
Block a user