问题
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