J F W

making web application programming easier is possible

HOW TO : CORE

Multi language support

All Struts modules are compatible with a multi language project. JFW offers a little more to make the use of the various locales simpler in actions .

The method used for managing the locales is initLocale. This method sets the locale based on this logic:

  1. If a parameter with name request_locale exists in the request, then the value of this parameter is used for setting the locale. The value of the parameter is a language as defined here (ISO 639-1).
  2. If exist in session, an attribute under key request_locale then the locale is already set and nothing more must be done.
  3. If cookie jfw_locale exists in request, then the value in the cookie is used.
  4. If key default_language is defined in jfw.properties then this value is used. To get the default application locale, the method getLocale of class com.jfw.util.JFWLocale is used.
  5. If all other methods failed, the Locale.getDefault() method is called.
The first successful step of the previous steps sets the locale and stops the process. Setting the locale is a multistep process:
  1. Add a Locale object in HttpSession under key request_locale.
  2. Add a Locale object in HttpSession under key WW_TRANS_I18N_LOCALE.
  3. Set a cookie with name jfw_locale and value with the locale data.
So, when the get locale methods ( getLocale or getLocaleLanguage ) are used, the locale already set in HttpSession is returned.

You can see an example of how to change the locale in file home.jsp; see how the parameter request_locale in the form with name lang_form is valorized.