Myrdivar
Myrdivar

Reputation: 145

Dynamically change ResourceBundle Locale in Java

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?

Upvotes: 2

Views: 4884

Answers (2)

JB Nizet
JB Nizet

Reputation: 691825

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);

Upvotes: 5

inancsevinc
inancsevinc

Reputation: 2700

Call

ResourceBundle.clearCache();

then load your bundle again with the locale you want.

Upvotes: 2

Related Questions