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
This method sets the locale based on this logic:
- 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).
- If exist in session, an attribute under key request_locale then the locale is already set
and nothing more must be done.
- If cookie jfw_locale exists in request, then the value in
the cookie is used.
- 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.
- 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:
- Add a Locale object in HttpSession under key request_locale.
- Add a Locale object in HttpSession under key WW_TRANS_I18N_LOCALE.
- Set a cookie with name jfw_locale and value with the locale data.
So, when the get locale methods (
) 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