Hi guys,
I got a question regarding internationalization in Vaadin applications and would like to know if there’s somewhat of a best practice for what I want to achieve.
Some background:
I’m working on an application with a modular approach for its components. Everything that is specific to a particular component (e.q. a special view) is contained in a single “module” and thus results in a separate *.jar
file. So in the end there are multiple *.jar
files, one for every component.
My goal:
I would like to use Vaadin’s internationalization mechanism (I18NProvider
) in conjunction with ResourceBundle
s, similar to [this]
(https://vaadin.com/docs/v13/flow/advanced/tutorial-i18n-localization.html) section/example in the Vaadin documentation. Additionally, every component (or *.jar
) should come with its own ResourceBundle
.
I already implemented and tested that and it works without any problems but I have mixed feelings about my approach. Since there can only be one I18NProvider
defined for a servlet, my implementation basically maps the supported locales to respective collections of resource bundles. When looking up a translation the collection for the respective locale is iterated.
As I said, everything works as expected but I do have some concerns/questions:
- Since everything is handled by a single instance, property keys across all resource bundles must be unique. (This would not necessarily be the case if every component would, for example, load its resource bundle itself.)
- Why can there only be on
I18NProvider
per servlet? Doesn’t it prevent a modular approach regarding internationalization? - Is there maybe another or a better way of doing this? Or is
I18NProvider
even intended to be used in another way? - Is there a particular advantage of using
I18NProvider
overResourceBundle
the traditional way? (Or is there a drawback of using the latter?)
Hope someone can share their experience/thoughts.