wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
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;
};