[英]Java load ResourceBundle inside WAR that contains several jar with their ResourceBundle
I have a java project called API, it has its own ResourceBundle, because it know the language of the user, and the response is written according to its language. 我有一个名为API的Java项目,它具有自己的ResourceBundle,因为它知道用户的语言,并且响应是根据其语言编写的。 The tests are working fine, I see the messages correctly written. 测试工作正常,我看到正确编写的消息。
When I want to use the jar of the API project inside another project, lets call it REST_API, it doesn't find any key from API. 当我想在另一个项目中使用API项目的jar时,将其称为REST_API,它找不到来自API的任何键。
The REST_API has it's own language keys, so the final bundle files should have a merge of the bundles. REST_API具有自己的语言密钥,因此最终的捆绑软件文件应具有捆绑软件的合并。 Right? 对?
I'm using maven to build the jar, wars, etc. Is there any maven plugin that scan the projects, and merge resource bundle files in order to make it work? 我正在使用maven来构建jar,wars等。是否有任何maven插件可以扫描项目,并合并资源束文件以使其工作?
Or should I implement it in a different way? 还是应该以其他方式实施它?
Thanks! 谢谢!
UPDATE 更新
Resources in API project are in: API项目中的资源位于:
src/main/resources/ApplicationMessages_en.properties
src/main/resources/ApplicationMessages_es.properties
The following is an example of how I load the bundles: 以下是如何加载捆绑包的示例:
private static final String DEFAULT_LANG = "en";
private static final Locale DEFAULT_LOCALE = new Locale(DEFAULT_LANG);
private static final ResourceBundle DEFAULT_TRANSL = ResourceBundle.getBundle("ApplicationMessages", DEFAULT_LOCALE, new UTF8Control());
Resource files are placed in a package inside resource folder: 资源文件放置在资源文件夹内的包中:
src/main/resources/my.package.api.lang.ApplicationMessages_en.properties
src/main/resources/my.package.api.lang.ApplicationMessages_es.properties
And in the REST API project: 在REST API项目中:
src/main/resources/my.package.api.rest.lang.ApplicationMessages_en.properties
src/main/resources/my.package.api.rest.lang.ApplicationMessages_es.properties
To load those files: 要加载这些文件:
// lang = "es" || "en"
// bundleName = "my.package.api.lang.ApplicationMessages"
// bundleName = "my.package.api.rest.lang.ApplicationMessages"
final Locale locale = new Locale(lang);
ResourceBundle translator = ResourceBundle.getBundle(bundleName, locale);
thanks! 谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.