Java i18n:每个包使用一个 ResourceBundle 访问器,还是整个项目使用一个 ResourceBundle 访问器?
我对国际化一无所知。
我有一个包含多个包的项目。我正在使用 Eclipse 的内置“Externalize Strings”向导将类中的字符串常量提取到属性文件中,并用对静态访问器的调用替换这些字符串。因此,
System.out.println("Hello, world!");
我最终没有
System.out.println(Messages.getString("MyKey"));
在每个包中得到一个 Messages
实用程序类(它提供了一个静态 getString
方法,用于从 ResourceBundle 获取所需的字符串 [在本例中是 <代码>.properties文件])。最好是在每个包中都有一个 Messages
类,还是在整个项目中都有一个 Messages
类?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我赞成全球本地化文件。您将拥有重复的键(“确定”、“取消”),这需要重复或嵌套,并且如果资源得到整合,与外部本地化人员的交互会更容易。
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.
我会每包保留一个。这样维护/重构/单元测试就容易得多。
此外,单个文件不存在全局依赖性。
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.