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

34 lines
864 B
JavaScript
Raw Normal View History

2024-09-25 22:24:16 +08:00
import en from '@/utils/i18n/en.json'
2024-12-21 15:12:52 +01:00
import fr from '@/utils/i18n/fr.json'
2024-09-25 22:24:16 +08:00
import zhCN from '@/utils/i18n/zh_CN.json'
2024-10-22 12:40:44 +08:00
import ko from '@/utils/i18n/ko.json'
2024-10-22 19:46:05 +08:00
import ru from '@/utils/i18n/ru.json'
2024-11-26 10:42:21 +08:00
import es from '@/utils/i18n/es.json'
2025-01-19 21:19:57 +08:00
import zhTW from '@/utils/i18n/zh_TW.json'
2024-09-25 22:24:16 +08:00
import { useAppStore } from '@/store/app'
2025-01-19 21:19:57 +08:00
const trans = {
'en': en,
'fr': fr,
'zh-CN': zhCN,
'ko': ko,
'ru': ru,
'es': es,
'zh-TW': zhTW,
}
2024-09-25 22:24:16 +08:00
export function T (key, params, num = 0) {
const appStore = useAppStore()
2024-09-25 22:24:16 +08:00
const lang = appStore.setting.lang
2024-11-26 10:42:21 +08:00
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
})
}