Is it possible to do this operation after the ResourceBundle has already been loaded? I'm working under Tomcat and have tried different code examples but none of them worked for me. Any suggestion?
Dynamically change ResourceBundle Locale in Java
Asked Answered
Why would you want to change the Locale of a ResourceBundle after it has been loaded? –
Neiman
@ChristopherSchultz you would want to do something like that if your application is internationalized. –
Palmore
@Palmore Um... no, you wouldn't. You'd want to change the user's locale and request the text from the appropriate bundle. You don't change the locale of a bundle once it's been loaded. –
Neiman
@ChristopherSchultz, Agreed. I suppose I misunderstood your question. –
Palmore
No, you can't change the locale of a bundle. But you can reload the same bundle base name using another locale:
bundle = ResourceBundle.getBundle("my.base.name", otherLocale);
Call
ResourceBundle.clearCache();
then load your bundle again with the locale you want.
© 2022 - 2024 — McMap. All rights reserved.