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 LOCALE_KEY exists in request then
the value of this parameter is used to set the locale. The value
of the parameters is a language as defined here (ISO 639-1).
- If exists in session, an attribute under key LOCALE_KEY 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 getLocale method of Struts is called.
The first successful step of the previous steps sets the locale and stops the process.
Setting the locale is a multistep process:
- Call Struts method Action.setLocale(request, locale).
- Add a Locale object in HttpSession under key LOCALE_KEY.
- Set a cookie with name jfw_locale and value 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 LANGUAGE_KEY
in the form with name lang_form