views:

101

answers:

1

Hi all,

My application supports internationalization and localization, each user can choose his preference language and the application will reflect it perfectly. the issue is when the first user selects English and the second one selects French the resource bundle for the first user will read from the French resource after refreshing his page.

I am using the following code to change between the two languages:

public void changeToEnglish()
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Locale currentLocale = context.getViewRoot().getLocale();
        String locale = "en_US";
        Locale newLocale = new Locale(locale);
        if(!currentLocale.equals(newLocale)) 
           context.getViewRoot().setLocale(newLocale);
    }

I have the following in my faces_config.xml:

<locale-config> <default-locale>en</default-locale> <supported-locale>fr</supported-locale> </locale-config>

the application respond very well to changing languages but I think when setting the locale from the FacesContext it reflects all the users locales.

Please help me on this....

+1  A: 

The given code doesn't do that. The problem lies somewhere else or has been misinterpreted.

However, a more common practice is to store the locale in a session scoped bean and make use of the locale attribute of <f:view>.

<f:view locale="#{user.locale}">
BalusC
thx for your reply, actually I do save the locale in the user bean (session scoped bean). I'll try to put <f:view locale="#{user.locale}"> in the template and see what will happen.
Ahmad
Thank you very much BalusC it is working fine right now :)
Ahmad
You're welcome.
BalusC