Dynamically change ResourceBundle Locale in Java

♀尐吖头ヾ 提交于 2019-12-08 02:56:18

问题


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?


回答1:


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



回答2:


Call

ResourceBundle.clearCache();

then load your bundle again with the locale you want.



来源:https://stackoverflow.com/questions/10981521/dynamically-change-resourcebundle-locale-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!