I am localizing a web application using a java.util.ResourceBundle class and property files.
I have two locales, fr_FR and en_US, and I want to use en_US as the default, so I wrote the following files :
messages_fr_FR.properties with fr_FR messagesmessages.properties with en_US messagesMy problem is that the ResourceBundle.getBundle(BUNDLE_NAME, locale) method fall back Locale.getDefault() before using the default property file, which means if the JVM Locale is set to fr_FR,
ResourceBundle.getBundle("name", new Locale("en", "US")) returns the fr_FR bundle.
I could rename the messages.properties file, but this could returns a MissingResourceException with other desired and default locales.
How can I ignore the System Locale, without duplicating the property file or calling Locale.setDefault ?
You can do that by using a custom ResourceBundle.Control, either by overloading the getFallbackLocaleexplicitly, or by using :
ResourceBundle.getBundle("name", new Locale("en", "US"), ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With