mirror of
https://github.com/type-challenges/type-challenges.git
synced 2025-12-08 19:06:13 +00:00
21 lines
548 B
TypeScript
21 lines
548 B
TypeScript
export const defaultLocale = 'en'
|
|
|
|
export const supportedLocales = ['en', 'zh-CN'] as const
|
|
|
|
export const messages = {
|
|
en: require('./locales/en.json'),
|
|
'zh-CN': require('./locales/zh-CN.json'),
|
|
}
|
|
|
|
export type SupportedLocale = keyof typeof messages
|
|
|
|
export function t(locale: SupportedLocale, key: string): string {
|
|
return messages[locale][key] || messages[defaultLocale][key]
|
|
}
|
|
|
|
export function f(name: string, locale: string, ext: string) {
|
|
if (locale === defaultLocale)
|
|
return `${name}.${ext}`
|
|
return `${name}.${locale}.${ext}`
|
|
}
|