MCPcopy Create free account
hub / github.com/PlexPt/rocket-pt / I18nMessage

Class I18nMessage

src/main/java/com/rocketpt/server/common/base/I18nMessage.java:12–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import lombok.extern.slf4j.Slf4j;
11
12@Slf4j
13@UtilityClass
14public class I18nMessage {
15
16 static {
17 ReloadableResourceBundleMessageSource messageSource =
18 new ReloadableResourceBundleMessageSource();
19 messageSource.setCacheSeconds(5);
20 messageSource.setBasenames("classpath:i18n/message");
21 I18nMessage.init(messageSource);
22 }
23
24 private static MessageSource messageSource;
25
26 public static void init(MessageSource messageSource) {
27 Objects.requireNonNull(messageSource, "MessageSource can't be null");
28 I18nMessage.messageSource = messageSource;
29 }
30
31 /**
32 * 读取国际化消息
33 *
34 * @param msgCode 消息码
35 * @param args 消息参数 例: new String[]{"1","2","3"}
36 * @return
37 */
38 public static String getMessage(String msgCode, Object[] args) {
39 try {
40 return I18nMessage.messageSource.getMessage(msgCode, args,
41 LocaleContextHolder.getLocale());
42 } catch (Exception e) {
43 if (log.isDebugEnabled()) {
44 e.printStackTrace();
45 }
46 log.error("===> 读取国际化消息失败, code:{}, args:{}, ex:{}", msgCode, args,
47 e.getMessage() == null ? e.toString() : e.getMessage());
48 }
49 return "-Unknown-";
50 }
51
52 /**
53 * 获取一条语言配置信息
54 *
55 * @param msgCode 消息码
56 * @return 对应配置的信息
57 */
58 public static String getMessage(String msgCode) {
59 return I18nMessage.getMessage(msgCode, null);
60 }
61}

Callers

nothing calls this directly

Calls 1

initMethod · 0.95

Tested by

no test coverage detected