import { zh } from './zh'; import { en } from './en'; import { hk } from './hk'; export type Locale = 'zh' | 'en' | 'hk'; export type TranslationKey = keyof typeof zh; const translations: Record = { zh, en, hk }; export function getTranslation(locale: Locale) { return translations[locale] || translations.zh; } // Replaces the old Astro `getLocaleFromUrl(url)` — locale is now derived // from the browser pathname (zh at `/`, en at `/en/*`, hk at `/hk/*`). export function getLocaleFromPathname(): Locale { if (typeof window === 'undefined') return 'zh'; const p = window.location.pathname; if (p.startsWith('/en')) return 'en'; if (p.startsWith('/hk')) return 'hk'; return 'zh'; } export function getLocalizedPath(path: string, locale: Locale): string { if (locale === 'en') { return `/en${path}`; } if (locale === 'hk') { return `/hk${path}`; } return path; }