提交 | 用户 | 时间
|
722af2
|
1 |
package com.dl.common.utils; |
X |
2 |
|
|
3 |
import com.dl.common.utils.spring.SpringUtils; |
|
4 |
import lombok.AccessLevel; |
|
5 |
import lombok.NoArgsConstructor; |
|
6 |
import org.springframework.context.MessageSource; |
|
7 |
import org.springframework.context.i18n.LocaleContextHolder; |
|
8 |
|
|
9 |
/** |
|
10 |
* 获取i18n资源文件 |
|
11 |
* |
|
12 |
* @author Lion Li |
|
13 |
*/ |
|
14 |
@NoArgsConstructor(access = AccessLevel.PRIVATE) |
|
15 |
public class MessageUtils { |
|
16 |
|
|
17 |
private static final MessageSource MESSAGE_SOURCE = SpringUtils.getBean(MessageSource.class); |
|
18 |
|
|
19 |
/** |
|
20 |
* 根据消息键和参数 获取消息 委托给spring messageSource |
|
21 |
* |
|
22 |
* @param code 消息键 |
|
23 |
* @param args 参数 |
|
24 |
* @return 获取国际化翻译值 |
|
25 |
*/ |
|
26 |
public static String message(String code, Object... args) { |
|
27 |
return MESSAGE_SOURCE.getMessage(code, args, LocaleContextHolder.getLocale()); |
|
28 |
} |
|
29 |
} |