techie2k
techie2k

Reputation: 559

Multiple language support in JSF application

I'm trying to add multiple language support to the application. Is it possible to add languages at runtime, by creating new property file at runtime, pulling all the english text and calling google translator api to create the equivalent values and using native2ascii converter to change the values and put it in the property file?

Any better approach available to add languages at runtime??

Thanks

Upvotes: 0

Views: 1117

Answers (2)

BalusC
BalusC

Reputation: 1109725

You can do that with a custom ResourceBundle implementation wherein you in turn provide a custom ResourceBundle.Control wherein you manage the loading and providing the values yourself. You can even provide them from the DB.

Then, to use it, just specify the FQN of the custom ResourceBundle instead in the <resource-bundle><base-name> or <f:loadBundle baseName>.

See also:

Upvotes: 1

Matt
Matt

Reputation: 11815

There's a few problems with java's i18n support. First, ResourceBundle.getBundle() can only look into two places for language support:

  1. Properties files in the classpath
  2. Class on the classpath

In either case, if you wanted to dynamically provide different languages on the fly (as they are requested), you'd most likely either have to:

  1. Create a custom classloader so that loadClass and getResource could create these on the fly.
  2. Use aspectJ to intercept the getBundle() method call and put some before advice on it to do what you want.

In contrast, spring's MessageSource framework is much more extensible, as MessageSource is an interface, and you can supply your own implementations and register them with the spring context, or nest them in other message sources, etc....

Upvotes: 0

Related Questions