# Spring Boot i18n(internationalization)

# Spring Boot i18n(internationalization)

by jihoon kim

HTML

<style>
.MJXp-math.MJXp-display {
  display:inline !important;
}
</style>
<div id="contents">
### 참고 : https://justinrodenbostel.com/2014/05/13/part-4-internationalization-in-spring-boot/

### Spring Boot internationalization
    1. message.properties 생성
        - messages.properties
        - messages_en.properties
        - messages_ko.properties
    2. I18nConfiguration 생성
    3. hello.html 작성

### messages.properties
    msg_hello = Hello
    msg_world = World
    msg_complex = Good morning {0}!

### messages_en.properties
    msg_hello = Hello
    msg_world = World
    msg_complex = Good morning {0}!

### messages_ko.properties
    msg_hello = 안녕
    msg_world = 세계
    msg_complex = 좋은아침 {0}!

### I18nConfiguration.java
```java
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import java.util.Locale;

/**
 * 로케일 처리 순서
 * 1. 웹 요청의 로케일을 확인
 *   1.1) 로케일 리졸버의 방식에 따라 세션 또는 쿠키에서 로케일 확인
 *   1.2) 세션 또는 쿠키에서 로케일 확인이 안될 때(ex.첫 요청등)는 브라우저가 보내는 로케일 확인
 *     1.2.1) 단, Resolver의 DefaultLocale이 설정되어 있을 경우 해당 값으로 덮어쓰기
 * 2. 로케일에 맞는 메세지 파일의 값을 호출
 * 3. 로케일에 맞는 메세지 파일이 없는 경우
 *   3.1) FallBackToSystemLocale이 true(기본값)인 경우
 *     3.1.1) 시스템 로케일에 맞는 메세지 파일의 값을 호출
 *     3.1.2) 못찾았을 경우 기본 메세지 파일(messages.properties)의 값을 호출
 *   3.2) FallBackToSystemLocale이 false인 경우
 *     3.2.1) 기본 메세지 파일(messages.properties)의 값을 호출
 * 4. 로케일에 맞는 메세지 파일이 없거나 값을 못찾았을 경우 예외 발생
...