Helius
2020-05-27 2dd3a086f2edeb9f364935c3fb98f18c2eea2fa8
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
26
27
28
29
30
31
package com.xcong.excoin.utils;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
 
/**
 * @author wzy
 * @date 2020-05-05 16:57
 **/
@Component
@Slf4j
public class MessageSourceUtils {
 
    private static MessageSource messageSource;
 
    public MessageSourceUtils(MessageSource messageSource) {
        MessageSourceUtils.messageSource = messageSource;
    }
 
    public static String getString(String key) {
        try {
            return messageSource.getMessage(key, null, LocaleContextHolder.getLocale());
        } catch (NoSuchMessageException e) {
            log.error("#获取国际化异常#", e);
            return key;
        }
    }
}