I have three resource files in class path:
labels.properties:
language = Default
labels_en.properties:
language = English
labels_fr.properties:
language = French
Is there a way to get a ResourceBundle
object that always loads labels.properties
NO MATTER what my default Locale
is?
ResourceBundle.getBundle("labels")
returns the one corresponding to the current default locale (as expected).
The only way I can find is to set the default locale to a non-existing locale, but this may break other modules.
Thank you!
Locale.setDefault( Locale.ENGLISH);
Assert.assertEquals( "English", ResourceBundle.getBundle( "labels").getString( "language"));
Locale.setDefault( Locale.FRENCH);
Assert.assertEquals( "French", ResourceBundle.getBundle( "labels").getString( "language"));
Assert.assertEquals( "French", ResourceBundle.getBundle( "labels", new Locale( "do-not-exist")).getString( "language"));
Locale.setDefault( new Locale( "do-not-exist"));
Assert.assertEquals( "Default", ResourceBundle.getBundle( "labels").getString( "language"));
ResourceBundle.clearCache()
before trying:ResourceBundle.getBundle( "labels", new Locale( "do-not-exist")).getString( "language"));
. (From this question). – Handymannew Locale("do-not-exist")
(I should have named it "does-not-exist"...) is not found,ResourceBundle
tries to load one withLocale.getDefault()
instead, not the default version of the bundle. – Martino