0

We are currently adding support for a 2nd language in our application, and we load the message bundle in a Session Scoped bean like so

bundle = ResourceBundle.getBundle(languageSetting.getLanguage().getPropertiesFileName(), new OurCustomBundleControl());

This allows us to retrieve messages like so:

public String get(final String key) {
    return bundle.getString(key);
}

The languageSetting variable is a class that we use to switch the language, which is done via a control on the page.

We are doing things this way for two reasons, firstly we need to use non-UTF-8 characters by overriding the Control class (as suggested here), and we are also using CDI to manage scopes.

Our assumption is that the message bundle class can only be Session scoped because different users will need to have different languages selected, but we are concerned that performance wise it may be preferable to have it Application scoped.

Is is possible to have a custom resource bundle with an Application scope? is it recommended?

I'm thinking it may be possible to somehow specify the message bundle in faces-config which is the usual way, but we would still need to override the Control class. And then we could switch the language by switching the locale with UIViewRoot#setLocale().

Another option might be to have two message bundles, then have a conditional statement in the get method?

Community
  • 1
  • 1
Continuity8
  • 2,403
  • 4
  • 19
  • 34
  • Are you aware of http://stackoverflow.com/q/3645491? No need for manual resource bundle management in beans anymore. – BalusC Sep 17 '15 at 09:20
  • Yes thanks, I actually came across that same post here: http://jdevelopment.nl/internationalization-jsf-utf8-encoded-properties-files/ later in the day and it's working like a dream, thanks. – Continuity8 Sep 17 '15 at 22:06

0 Answers0