Files
rustdesk-api-web/src/utils/i18n.js
T

26 lines
662 B
JavaScript
Raw Normal View History

2024-09-25 22:24:16 +08:00
import en from '@/utils/i18n/en.json'
import zhCN from '@/utils/i18n/zh_CN.json'
2024-10-22 12:40:44 +08:00
import ko from '@/utils/i18n/ko.json'
2024-09-25 22:24:16 +08:00
import { useAppStore } from '@/store/app'
export function T (key, params, num = 0) {
const appStore = useAppStore()
2024-09-25 22:24:16 +08:00
const lang = appStore.setting.lang
2024-10-22 12:40:44 +08:00
const trans = {
'en': en,
'zh-CN': zhCN,
'ko': ko,
}
const tran = trans[lang][key]
2024-09-25 22:24:16 +08:00
if (!tran) {
return key
}
const msg = num > 1 ? (tran.Other ? tran.Other : tran.One) : tran.One
2024-09-25 22:24:16 +08:00
//msg 是这样 {name} is name
//params 是这样 {name: 'zhangsan'}
//替换
return msg.replace(/{(\w+)}/g, function (match, key) {
return params[key] || match
})
}