@Configuration
등록@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
localeResolver.setDefaultLocale(Locale.KOREA);
return localeResolver;
}
spring:
messages:
basename: messages
messages.properties
greeting.message=안녕하세요
messages_en.properties
greeting.message=Hello
messages_fr.properties
greeting.message=Bonjour
@Autowired
private MessageSource messageSource;
요청 헤더 Accept-Language:en
or Accept-Language:fr
or 한국어는 디폴트
@GetMapping(path = "/hello")
public String hello(
@RequestHeader(name="Accept-Language", required=false) Locale locale) {
return messageSource.getMessage("greeting.message", null, locale);
}