2026-09-04 05:41:09 +00:00
|
|
|
import { zhTW } from "./locales/zh-TW";
|
|
|
|
|
|
2026-09-03 16:16:34 +00:00
|
|
|
export const supportedLocales = ["zh-TW"] as const;
|
|
|
|
|
export type Locale = (typeof supportedLocales)[number];
|
|
|
|
|
|
2026-09-04 05:41:09 +00:00
|
|
|
const messages = { "zh-TW": zhTW } as const;
|
2026-09-03 16:16:34 +00:00
|
|
|
|
|
|
|
|
export const locale: Locale = "zh-TW";
|
2026-09-04 05:41:09 +00:00
|
|
|
export type MessageKey = keyof typeof zhTW;
|
|
|
|
|
export type MessageParams = Record<string, string | number>;
|
|
|
|
|
|
|
|
|
|
export function t(key: MessageKey, params?: MessageParams): string {
|
|
|
|
|
const message: string = messages[locale][key];
|
|
|
|
|
if (!params) return message;
|
|
|
|
|
return message.replace(/\{(\w+)\}/g, (match, name: string) =>
|
|
|
|
|
Object.prototype.hasOwnProperty.call(params, name) ? String(params[name]) : match,
|
|
|
|
|
);
|
|
|
|
|
}
|