Dashboard > Struts University > Home > MailReader Training Course > Topics > Localize-Notes
Added by Ted Husted, last edited by Ted Husted on Jul 13, 2007  (view change)

To reach the broadest audience, some applications support more than one language. Even if your application supports a single language, message resources are an effective tool for managing shared phrases throughout the application.

Presentation - Localizing Content

How can we internationalize applications? Which Struts tags are message-aware? Can we localize dates and numbers?

We overview the localization features, which are considered a fundamental part of the framework.

  • Resource Bundles
  • Struts Message Tags
  • Formatting Messages

Workshop - Localize

Story: In addition to English, MailReader must support other languages, including Japanese and Russian.

  • Localize the MailReader application using a standard Resource Bundle


  • text tag
  • getText method
  • <s:message key="" /> idiom


  • Copy the resources*.property files from "localize" on the CD


  • Localize the MailReader page by replacing static strings with references to an entry in the message resources.
    • <s:text name="index.title"/>
    • <s:textfield key="username"/>


  • Localize the MailReader classes by calling getText with a message key, instead of passing a static string.


  • Localize the validation configuration files by changing the message elements to use a key
    • <message key="error.username.required"/>

Hint Code

  • On each page, use this markup before the <head> section
<%@ page contentType="text/html; charset=UTF-8" %>
    <%@ taglib uri="/struts2" prefix="s" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  • On the Welcome page, use code like this to switch between each language.
    • The code for Russian is "ru". Japan is "ja".
    <s:url id="en" action="Welcome">
    <s:param name="request_locale">en</s:param>
    <s:a href="%{en}">English</s:a>

Here, we are appending the parameter "request_locale=en" to tell the framework which language to use.

The Japanese locale may not work under Tomcat 5.5


  • Localized the MailReader application using a standard Resource Bundle

Extra Credit

  • Create a Selenium test that switches from English to French and back.

Site running on a free Atlassian Confluence Open Source Project License granted to OSS. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators