25 lines
708 B
Java
Raw Normal View History

2020-02-13 10:48:51 +08:00
package com.ruoyi.common.utils;
2021-10-22 10:04:15 +08:00
import com.ruoyi.common.utils.spring.SpringUtils;
2020-02-13 10:48:51 +08:00
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
/**
* 获取i18n资源文件
2021-10-22 10:04:15 +08:00
*
2020-02-13 10:48:51 +08:00
* @author ruoyi
*/
2021-10-22 10:04:15 +08:00
public class MessageUtils {
2020-02-13 10:48:51 +08:00
/**
* 根据消息键和参数 获取消息 委托给spring messageSource
*
* @param code 消息键
* @param args 参数
* @return 获取国际化翻译值
*/
2021-10-22 10:04:15 +08:00
public static String message(String code, Object... args) {
2020-02-13 10:48:51 +08:00
MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
}
}