简体   繁体   中英

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. 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.

The REST_API has it's own language keys, so the final bundle files should have a merge of the bundles. 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?

Or should I implement it in a different way?

Thanks!

UPDATE

Resources in API project are in:

   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:

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM