I want to load multiple property files from various packages as ResourceBundle. Can I achieve that in Java
ResourceBundle.Control() controls the list of files for the ResourceBundle. You can overwrite getCandidateLocales and toBundleName. toBundleName converts locale to the "file name" and the list of locales you can control in getCandidateLocales. For example like
final String[] variants = new String[]{"your names"};
ResourceBundle.getBundle(baseName, locale,
new ResourceBundle.Control() {
public List getCandidateLocales(String baseName, Locale locale) {
List out = new ArrayList();
String language = locale.getLanguage();
String country = locale.getCountry();
for (String variant : variants) {
out.add(new Locale(language, country, variant));
}
out.addAll(super.getCandidateLocales(baseName, locale));
return out;
}
public String toBundleName(String baseName, Locale locale) {
Locale l = new Locale(locale.getLanguage(), locale.getCountry());
return locale.getVariant() + "." + super.toBundleName(baseName, l);
}
});
It works only in Java 1.6