1234567891011121314151617181920212223242526272829 |
- package com.sysu.admin.utils.i18n;
- import org.springframework.context.MessageSource;
- import org.springframework.context.i18n.LocaleContextHolder;
- import org.springframework.stereotype.Component;
- /**
- * 国际化工具类
- */
- @Component
- public class MessageUtils {
- private static MessageSource messageSource;
- public MessageUtils(MessageSource messageSource) {
- this.messageSource = messageSource;
- }
- /**
- * 获取单个国际化翻译值
- */
- public static String get(String msgKey) {
- try {
- return messageSource.getMessage(msgKey, null, LocaleContextHolder.getLocale());
- } catch (Exception e) {
- return msgKey;
- }
- }
- }
|