FrontEND/Jsp

IntelliJ Java 11 환경에서 JSP 국제화(i18n) 적용 가이드

mingmingIT 2025. 4. 16. 10:23

웹 서비스가 글로벌 사용자 또는 다양한 언어권을 대상으로 한다면, 국제화(i18n: Internationalization)는 필수적인 기능입니다. 이 포스트에서는 JSP 기반의 Spring Boot 프로젝트에서 국제화를 적용하는 방법을 IntelliJ + Java 11 환경 기준으로 단계별로 안내합니다.


1. 국제화 기본 개념 정리

  • 국제화(i18n): 애플리케이션을 다양한 언어와 지역에서 사용할 수 있도록 설계
  • 지역화(l10n): 각 국가, 언어, 문화에 맞춰 실제 번역된 메시지를 적용

2. 기본 구조 및 메시지 파일 작성

1) messages.properties 생성

  • resources 폴더 하위에 다국어 메시지 파일 생성:
src/main/resources/messages.properties             # 기본 (영문)
src/main/resources/messages_ko.properties          # 한국어
src/main/resources/messages_ja.properties          # 일본어

2) 메시지 키/값 작성 예시 (messages_ko.properties)

page.title=홈페이지
page.welcome=환영합니다!
user.login=로그인

3. Spring Boot 국제화 설정 (WebConfig)

1) LocaleResolver 설정

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Bean
    public LocaleResolver localeResolver() {
        SessionLocaleResolver slr = new SessionLocaleResolver();
        slr.setDefaultLocale(Locale.KOREA); // 기본 언어 설정
        return slr;
    }

    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
        lci.setParamName("lang"); // 언어 변경 파라미터명
        return lci;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localeChangeInterceptor());
    }

    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("classpath:messages");
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }
}

이 설정을 통해 URL 파라미터 ?lang=ko, ?lang=en 등으로 언어 변경 가능


4. JSP에서 메시지 출력하기

1) JSTL 태그 라이브러리 선언

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

2) 리소스 바인딩 설정

<fmt:setLocale value="${param.lang}" />
<fmt:setBundle basename="messages" />

3) 메시지 출력 예제

<title><fmt:message key="page.title" /></title>
<h1><fmt:message key="page.welcome" /></h1>
<a href="/login"><fmt:message key="user.login" /></a>

5. 언어 선택 링크 구현 예시

<a href="?lang=ko">한국어</a>
<a href="?lang=en">English</a>
<a href="?lang=ja">日本語</a>

 

📌 선택한 언어는 SessionLocaleResolver에 의해 세션에 저장되므로 페이지 이동 시 유지됩니다.


6. IntelliJ 설정 팁

  • messages_*.properties 파일은 IntelliJ에서 Resource Bundle로 자동 인식됨
  • Key 이름 자동완성, 다국어 비교 뷰 제공 (Ctrl + Enter → Show All Translations)

7. 테스트 시 체크 포인트

  • 한글 메시지 깨짐 → UTF-8 설정 여부 확인
    • application.properties 또는 WebConfig의 messageSource 인코딩 확인
  • 언어가 변경되지 않음 →
    • ?lang=xx 파라미터 존재 여부
    • SessionLocaleResolver 적용 확인
  • JSTL <fmt:message>가 동작하지 않음 →
    • <fmt:setBundle> 선언 여부 확인
    • 메시지 키 존재 여부 확인

결론

Spring Boot + JSP 환경에서도 국제화를 적용하는 것은 어렵지 않습니다. 다만 JSP는 동적 페이지 구성 방식이기 때문에 세션 기반 Locale 처리, JSTL 설정, message properties 구성 등 여러 요소가 함께 작동해야 합니다.

이 포스팅을 참고하여 프로젝트 초기부터 국제화 구조를 잡아두면, 다국어 대응이 필요한 시점에서도 큰 리팩토링 없이 확장 가능해집니다.