You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ralph Wetter <pr...@gmx.ch> on 2004/01/27 19:03:31 UTC

Using ApplicationResources and changing Locale

Hello

I've got a strange behavior when using ApplicationResources:

In web.xml I've defined the following:
<init-param>
            <param-name>application</param-name>
            <param-value>ch.mera.pvs.common.Resource</param-value>
</init-param>

I've got two resource.properties (in both resources are the same
properties):
- Resource.properties (where i've defined all the Constants for
"english-support" - this is the default language, when there's no
standard-language defined in browser)
- Resource_de.properties (where i've defined all the Constants for
"german-support")

For Changing the language, I've got the follwoing action:

public  ActionForward execute(ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response)
            throws IOException, ServletException {

        Logger logger = Logger.getLogger(this.getClass().getName());
        logger.debug("Start ChangeLocaleAction.java");
        String parameter = request.getParameter("parameter");
        String forward = request.getParameter("forward");
        HttpSession session = request.getSession();
        Locale locale = null;

        if ("de".equals(parameter)) {
            locale = new Locale("de", "CH" );
        } else {
            locale = new Locale("en", "US" );
        }
        setLocale(request, locale);
        session.setAttribute(Globals.LOCALE_KEY, locale);
        return mapping.findForward(forward);
    }
}

Now the strange behavior:
When i click on the "change-language" button (the change-language-action is
executed), setLocale() ist not changing all the Language-Constants
correctly. Sometimes ist works, sometimes it doesn't work and somtimes
struts is mixing the Locales (one property in German, the other in
English)...

Now I rearranged my Properties like that:
- Resource_en.properties
- Resource_de.properties
...I changed the name of "Resource.properties" to "Resource_en.properties".

Now changing the Language works fine... BUT why???
Shouldn't it work properly like I've defined my properties the first way?
I thought, Struts is taking the "Resource.properties" (definition in
web.xml) as the standart-property when there's no language defined in the
browser...
In my case, Struts is now taking the Resource_de.properties as
standard-property. Probably because "de" comes before "en" (alphabetically).
How can I define "Resource_en.properties" as standard-property?

Or did I do something completly wrong it programming the "change Language"
Action?

Many Thanks and greetings
Ralph







---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org