wangzhibo
2026-10-08 220e4fab27b7f419b3e89e2f2d28ae789aac09d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package xiaozhi.common.utils;
 
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
 
/**
 * 国际化
 * Copyright (c) 人人开源 All rights reserved.
 * Website: https://www.renren.io
 */
public class MessageUtils {
    private static MessageSource messageSource;
 
    public static String getMessage(int code) {
        return getMessage(code, new String[0]);
    }
 
    public static String getMessage(int code, String... params) {
        if (messageSource == null) {
            // 延迟初始化,确保Spring上下文已完全初始化
            messageSource = (MessageSource) SpringContextUtils.getBean("messageSource");
        }
        return messageSource.getMessage(code + "", params, LocaleContextHolder.getLocale());
    }
}