{{1}}
答案 0 :(得分:0)
这似乎有您要查找的详细信息:http://www.ekiras.com/2016/01/springboot-internalization-and-i18n.html
配置:
@Bean public LocaleResolver localeResolver() { SessionLocaleResolver slr = new SessionLocaleResolver(); slr.setDefaultLocale(Locale.US); // Set default Locale as US return slr; } @Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource source = new ResourceBundleMessageSource(); source.setBasenames("i18n/messages"); // name of the resource bundle source.setUseCodeAsDefaultMessage(true); return source; }
Controller(注意参数中的Locale):
@RestController public class HomeController { @Autowired private MessageSource messageSource; @RequestMapping("/msg") public String msg(@RequestHeader("Accept-Language") Locale locale){ return messageSource.getMessage("msg",null,locale); } }