Dynamically change ResourceBundle Locale in Java
Asked Answered
E

2

2

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?

Enedina answered 11/6, 2012 at 13:55 Comment(4)
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
A
5

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);
Auriscope answered 11/6, 2012 at 14:3 Comment(0)
M
2

Call

ResourceBundle.clearCache();

then load your bundle again with the locale you want.

Marketable answered 11/6, 2012 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.