Internationalization in Java Stack

This training will cover the basics of internationalization in the Java Stack, including resource bundles, Spring message sources, locale resolvers, locale change interceptors, ...


Slide deck

Example code

Lab 1 Internationalize a Page

Project setup

  • Download the lab code and import the project into your favorite IDE.
  • Get your application deployed and running in Tomcat.
  • Go to http://localhost: 8080/spring-i18n-labs ( you should get an exception about "No message found under code 'hello'...")
  • Configure the MessageSource so that internationalization in the lab.jsp page works.
    • Notice the file in src/main/bundles and the lab.jsp in src/main/webapp/WEB-INF/views where those resources are utilized.
    • Add the appropriate basename property for this bundle to the messageSource definition in src/main/webapp/WEB-INF/spring-i18n-labs-servlet.xml
<property name="basenames">
    • Verify that you can hit the page (http://localhost: 8080/spring-i18n-labs) and have English text displayed.

Lab 2 Configure Locale Change and Resolution

    • Add a new properties file for a locale other than English (say es)
    • Verify that appending something like ?locale=es to the url does not change the locale
    • Add the locale-resolver and localeChangeInterceptor definitions in your *-servlet.xml file
<stack-web:locale-resolver />

<!-- this one goes inside the mvc:interceptors tag -->
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
    • Verify that appending ?locale=es does now change the locale
This page was last modified on 12 November 2012, at 08:50.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.