Reputation: 559
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
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>
.
Upvotes: 1
Reputation: 11815
There's a few problems with java's i18n support. First, ResourceBundle.getBundle() can only look into two places for language support:
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:
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