Search code examples
javainternationalizationstruts

Struts internationalization


I'm working on one portal product. I'm facing problem in making it internationalized. I'm using following code

Locale locale = new Locale(languageHashMap.get(preferredLanguageId));
ActionContext.getContext().setLocale(locale);
session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, locale);

for setting the locale.

For one time it is working fine but when I change the langauge again the change the language again, the change is not reflecting in all the pages. Still get the changes made by the last language only. Any help will be appreciated


Solution

  • I guess the locale is not setting properly. Try out the following code :

    create one map

    private static Map<Locale, ResourceBundle> messageBundles = new Hashtable<Locale, ResourceBundle>();
    

    and then use the following:

    Locale requestLocale = ActionContext.getContext().getLocale();
    ResourceBundle rb = messageBundles.get(requestLocale);
    

    and then put that resource bundle in the request scope.