48 lines
1.2 KiB
Java
48 lines
1.2 KiB
Java
package com.zhgd.xmgl.util;
|
|
|
|
import org.springframework.context.MessageSource;
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
import org.springframework.context.support.ResourceBundleMessageSource;
|
|
|
|
/**
|
|
* @program: wisdomSite
|
|
* @description:多国语言资源工具
|
|
* @author: Mr.Peng
|
|
* @create: 2020-09-09 18:30
|
|
**/
|
|
|
|
public class MessageUtil extends ResourceBundleMessageSource {
|
|
|
|
private static MessageSource messageSource;
|
|
|
|
public static void setMessageSource(MessageSource source){
|
|
messageSource=source;
|
|
}
|
|
public MessageUtil() {
|
|
super();
|
|
//this.messageSource = messageSource;
|
|
}
|
|
|
|
/**
|
|
* 获取单个国际化翻译值
|
|
*/
|
|
public static String get(String pvsKey) {
|
|
try {
|
|
return messageSource.getMessage(pvsKey, null, LocaleContextHolder.getLocale());
|
|
} catch (Exception e) {
|
|
return pvsKey;
|
|
}
|
|
}
|
|
/**
|
|
* 获取单个国际化翻译值
|
|
*/
|
|
public static String get(String pvsKey,Object ... pvParams) {
|
|
try {
|
|
return messageSource.getMessage(pvsKey, pvParams, LocaleContextHolder.getLocale());
|
|
} catch (Exception e) {
|
|
return pvsKey;
|
|
}
|
|
}
|
|
|
|
}
|