简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM