Java i18n: use one ResourceBundle accessor per package, or one for whole project?

烈酒焚心 提交于 2019-12-02 04:04:06

问题


I don't know anything about internationalization.

I have a project with several packages. I am using Eclipse's built-in "Externalize Strings" wizard to extract String constants in my classes to a properties file and replace those Strings with calls to a static accessor. So instead of

System.out.println("Hello, world!");

I end up with

System.out.println(Messages.getString("MyKey"));

and a Messages utility class in every package (which provides a static getString method for getting the desired String from a ResourceBundle [in this case a .properties file]). Is it best to have a Messages class in every package, or have a single Messages class for the entire project?


回答1:


I'm in favor of a global localization file. You will have duplicate keys ("OK", "Cancel") which would require duplication or nesting, and interfacing with outside localization people is easier if the resources are consolidated.




回答2:


I would keep one-per-package. This way maintenance/refactoring/unit-testing is much easier.

Also, there are no global dependencies on a single file.



来源:https://stackoverflow.com/questions/2067336/java-i18n-use-one-resourcebundle-accessor-per-package-or-one-for-whole-project

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