mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
25 lines
805 B
Java
25 lines
805 B
Java
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());
|
||
}
|
||
}
|