48 lines
1.1 KiB
Plaintext
48 lines
1.1 KiB
Plaintext
// i18n 国际化配置
|
|
// 这是一个简化的 i18n 实现,用于支持多语言切换
|
|
|
|
// 语言资源
|
|
const messages: UTSJSONObject = new UTSJSONObject()
|
|
|
|
// 默认语言
|
|
const defaultLocale = 'zh-CN'
|
|
|
|
// 当前语言(响应式)
|
|
let currentLocale = defaultLocale
|
|
|
|
// 翻译函数
|
|
function t(key: string, values: UTSJSONObject | null = null, locale: string | null = null): string {
|
|
const targetLocale = locale ?? currentLocale
|
|
// 这里应该从 messages 中获取翻译,简化实现直接返回 key
|
|
// 实际项目中应该加载语言资源文件
|
|
return key
|
|
}
|
|
|
|
// 创建响应式 locale 对象
|
|
class LocaleWrapper {
|
|
get value(): string {
|
|
return currentLocale
|
|
}
|
|
set value(newLocale: string) {
|
|
currentLocale = newLocale
|
|
}
|
|
}
|
|
const localeObj = new LocaleWrapper()
|
|
|
|
// I18n Global Context
|
|
class I18nGlobal {
|
|
t(key: string, values: UTSJSONObject | null = null, locale: string | null = null): string {
|
|
return t(key, values, locale)
|
|
}
|
|
locale: LocaleWrapper = localeObj
|
|
}
|
|
|
|
// I18n Instance
|
|
class I18nInstance {
|
|
global: I18nGlobal = new I18nGlobal()
|
|
}
|
|
|
|
// 导出 i18n 对象
|
|
const i18n = new I18nInstance()
|
|
export default i18n
|