2013-10-31 8 views
0

나는 국제화를 추가 할 필요가있는 기존의 Spring/GWT Application을 가지고있다. 필자는 Spring의 "ResourceBundleMessageSource"를 사용하여 사용자 위치에 따라 적절한 messages_ * 파일을 자동으로 선택할 수 있다는 것을 알고 있습니다. 나는 this tutorial 다음을 시도했지만 프랑스어로 내 문자열을 표시하는 응용 프로그램을 가져올 수 없습니다.Spring을 사용한 국제화

<bean id="messageSource" 
    class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basename"> 
     <value>classpath:i18n/messages</value> 
    </property> 
</bean> 

<bean id="localeChangeInterceptor" 
    class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
    <property name="paramName" value="lang" /> 
</bean> 

<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" > 
    <property name="interceptors"> 
     <list> 
     <ref bean="localeChangeInterceptor" /> 
     </list> 
    </property> 
</bean> 

그냥 궁금 1) 나는 경우 : 약자로, 나는하여 applicationContext.XML에 다음 내 SRC/메인/자원/국제화 폴더에이 파일 messages_en_US.properties 및 messages_fr_FR.properties를 추가하고 추가 한 추가 구성/글루 코드가 필요하며 2) Redhat Server에서 언어/로켈을 프랑스어로 설정하지 않고도 쉽게 테스트 할 수 있습니까?

답변

0

브라우저가 Accept-Header에 "fr"언어 태그 만 보내는 것 같습니다. Spring은 폴백 (fall-back) 문제로 악명이 높으므로 messages_fr_pro.properties를 messages_fr.properties로 복사해야 할 수도 있습니다.

폴백 (fall-back)을 구성하는 몇 가지 방법이 있어야하므로 messages_en.properties (다른 영어 로켈과 함께 응용 프로그램을 사용해보십시오 ...)를 사용하고 싶다면 messages.properties 만하면되지만, 순간적으로 해결책을 찾기에는 너무 게으르고/피곤합니다.

0

여기 spring.xml에서 bean을 지정해야합니다. 당신은 쿼리 문자열에서 랭 = 말이지을 통과 할 때

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basename" value="classpath:messages" /> 
     <property name="defaultEncoding" value="UTF-8" /> 
    </bean> 


    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"> 
     <property name="defaultLocale" value="en"/> 
    </bean> 

    <mvc:interceptors> 
    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
     <property name="paramName" value="lang" /> 
    </bean> 

    </mvc:interceptors> 

이 완벽하게 잘 작동합니다. 여전히 문제가 남아있는 경우 작업 예제 Here을 확인할 수 있습니다.