Files
medical-mall/uni_modules/i18n/index.uts
2026-01-22 08:54:47 +08:00

40 lines
894 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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 对象
const localeObj = {
get value(): string {
return currentLocale
},
set value(newLocale: string) {
currentLocale = newLocale
}
}
// 导出 i18n 对象(兼容 Vue I18n 的 API
const i18nInstance = {
global: {
t: t,
locale: localeObj
}
}
export default i18nInstance