1
votes

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

1 Answers

1
votes

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}">