提供了默认的国际化解析XyLocaleResolver,
如果后台服务需要国际化功能,在请求header中需要添加Accept-Language的头信息,当前只提供中文和英文两种语言:
Accept-Language=en 英文 Accept-Language=zh 中文
后续若需要其他,参照java.util.Local中的语言修改。
@Bean
@ConditionalOnProperty(value = "xy.core.i18n.enable", havingValue = "true", matchIfMissing = true)
public LocaleResolver localeResolver() {
log.info("loading LocaleResolver............");
return new XyLocaleResolver();
}
#是否开启配置
xy.core.i18n.enable=true
public class MessageUtil implements BeanFactoryAware {
private static MessageSource messageSource;
public synchronized static String getMessage(String key) {
Locale locale = LocaleContextHolder.getLocale();
return messageSource.getMessage(key, null, locale);
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
messageSource = beanFactory.getBean(MessageSource.class);
}
}