프로젝트 & TIL/일별 공부 기록 (백엔드 스쿨)
53일차 - 국제화
yurison
2023. 5. 8. 11:31
국제화(Internationalization)
File > Settings > Editor - File Encodings > Project Encoding : UTF-8로 변경
resources > messages.properties(디폴트 파일) 생성 후 내용 입력
hello=Hello There.
messages_ko.properties
hello=안녕하세요.
html 파일에서 아래와 같이 사용 가능
<span th:text="#{hello}"></span>
* 요청 헤더 중 Accept-Language 가 en, ko 순일 때(== 크롬 기본 언어가 영어일 때) messages_en.properties가 존재하지 않아서 ko 파일을 읽게 된다. 이 때 messages_en.properties를 생성하고 빈 내용으로 저장해두면 디폴트 파일(messages.properties)을 이차적으로 읽어서 영어 문장이 보이게 된다.
내용 치환하여 중복 제거
messages_ko.properties
hello=안녕하세요. 저는 {0}입니다.
name=유리
main.html
<span th:text="#{hello("유리")}"></span> <!-- 안녕하세요. 저는 유리입니다. -->
<span th:text="#{hello(#{name})}"></span> <!-- 안녕하세요. 저는 유리입니다. -->