Announcement Announcement Module
No announcement yet.
[PROBLEM] Spring Internationalization Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • [PROBLEM] Spring Internationalization

    I'm making a simple aplication to do some login to administrative pages and add some internationalization.
    I'm reading from several tutorials how to do that (internationalization) but i'm unable to load the messages from file.

    In attach is my project without libs. I'm using most recent spring framework and spring security libs and jstl 1.2.

    Can anyone help me on internationalization?

  • #2
    Using property files and interceptor

    Here's how we're doing localization:

    in the xml config:
    	<!-- declare the interceptor -->
    	<bean id="localeChangeInterceptor"
    		class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
    	<!-- declare the resolver -->
    	<bean id="localeResolver"
    		class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
    <bean id="urlMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    		<property name="interceptors">
    				<!-- adding locale interceptor bean -->
    				<ref local="localeChangeInterceptor" />
    Then we created a custom tag lib for our JSPs which extend org.springframework.web.servlet.tags.RequestContex tAwareTag and have a key to a property file as the parameter.

    We then pull property files from our res source folder (getting the local from the request and selecting the proper package structure from that) in that class and replace the tags with the appropriate text (english or spanish) using the key.

    We've set up our tag library so that we can set variables with the value in the property file and then use that variable as ${variableName} in fields like title, for the tooltip to be localized.

    There may be an easier way, but this approach has been very dynamic and we've yet to run into a problem we can't fix.


    • #3
      Actually, there's an even easier solution.

      Set up the LocaleResolver and LocaleChangeInterceptor as you described above, but also define a Spring MessageSource like so:

      <bean id="messageSource" 
          <property name="basenames">
                  <!-- etc -->
      and the files with the appropriate suffixes (messages/, messages/ will be loaded and referenced without any other effort on your part. This integrates seamlessly with the JSTL fmt:message tag as well, so you can use the "standard" approach to access your internationalized strings.

      <fmt:message key=""/>
      Hope this helps
      - Don