Reputation: 425
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?
Upvotes: 0
Views: 1073
Reputation: 425
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.
Upvotes: 1
Reputation: 692281
Do you have a web_resources_fi.class of web_resources_fi.properties in the root of your classpath? If not, then ResourceBundle.getBundle looks for web_resources.class or web_resources.properties (after looking for such files with the default locale appended to the base name).
See http://download.oracle.com/javase/6/docs/api/java/util/ResourceBundle.html#getBundle%28java.lang.String,%20java.util.Locale,%20java.lang.ClassLoader%29 for details about how this method works.
Upvotes: 1