Implement useLocale composable and shared translation dictionaries Translate public pages, booking flow, and receipt views Store booking locale to send localized WhatsApp notifications
44 lines
947 B
TypeScript
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'
|
|
}
|