Java i18n:每个软件包使用一个ResourceBundle访问器,还是对整个项目使用一个? [英] Java i18n: use one ResourceBundle accessor per package, or one for whole project?
问题描述
我对国际化一无所知.
我有一个包含多个软件包的项目.我正在使用Eclipse的内置外部字符串"向导将类中的字符串常量提取到属性文件中,并将这些字符串替换为对静态访问器的调用.因此,而不是
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!");
我最终以
System.out.println(Messages.getString("MyKey"));
每个程序包中的
和Messages
实用程序类(提供了一个静态的getString
方法,用于从ResourceBundle [在本例中为.properties
文件]中获取所需的String).最好在每个程序包中都包含一个Messages
类,或者对于整个项目都具有一个Messages
类?
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?
推荐答案
我赞成使用全局本地化文件.您将拥有重复的键(确定",取消"),这将需要重复或嵌套,并且如果整合了资源,则与外部本地化人员的接口将变得更加容易.
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.
这篇关于Java i18n:每个软件包使用一个ResourceBundle访问器,还是对整个项目使用一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!