Due to my project's requirements, I have implemented a custom java ResouceBundle class to take resource data from a directory configured in web.xml. My intention is to have only one ResourceBundle class in the project, and whatever resource and language added in the future can be done without redeploying the whole project. For example: MainBundle.java
public MainBundle() {
super();
this.locale = ADFContext.getCurrent().getLocale();
readBundle();
}
public MainBundle(Locale locale) {
super();
this.locale = locale;
readBundle();
}
private void readBundle() {
bundleFileName = baseBundleName + "_" + locale.toString();
// do some file reading here
}
I have implemented the ResourceBundle class to load the correct language according to the current locale. However, if I have only one ResourceBundle class, when a user login, all other concurrent users' locales are changed into that user's locale, thus changing their languages. For example: an English user is using my website. A French user logs in, and the English user is suddenly forced to use the website in French.
In order to solve this, I had to create a class for every locale, that extends the MainBundle class, such as MainBundle_en_US, MainBundle_fr, etc. These classes just contain super() calls in their constructors, nothing more. However this defeats the purpose of not having to modify the project when a new language is added.
My question is:
How can I get around this and just have only ONE resource bundle class?
Is there anyway to achieve what I want, which not having to modify the project when a new language is added?