wangzhibo
8 天以前 652993fc47ebecebfb0c3f42686a6d7f2615a1c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import messages from '@intlify/unplugin-vue-i18n/messages';
import { config } from '/@/config';
 
export const t = (key: string, params?: Record<string, string>) => {
    const language = config.i18n.locale;
 
    // @ts-ignore
    const message: string = messages?.[language]?.[key]?.loc?.source || key;
 
    // 参数插值
    if (params) {
        return message.replace(/\{(\w+)\}/g, (_, param) => params[param] || `{${param}}`);
    }
 
    return message;
};