I create a locale, and try to create a ResourceBundle using said locale. If I use a finnish locale, ResourceBundle doesn’t seem to accept/understand it – instead it gets a null locale. When using an english locale, it seems to work just fine.
Locale obj = new Locale("en");
ResourceBundle resource = ResourceBundle.getBundle("web_resources", obj);
log.debug(resource.getLocale());
log.debug(obj);
Logs “en”, “en”.
Locale obj = new Locale("fi");
ResourceBundle resource = ResourceBundle.getBundle("web_resources", obj);
log.debug(resource.getLocale());
log.debug(obj);
Logs “”, “fi”.
I’ve also tested fr (french) and german (de) locales – they don’t work either. Adding country codes didn’t seem to help. What am I missing?
I found the problem a month or so ago. The resource file had the wrong character encoding. If I remember correctly, the file is supposed to be in UTF-8, but at some point the encoding had changed to ISO 8859-4.
A silly mistake, but nevertheless a valuable lesson learned.