Hints / hacks

NILS and Java’s module-info.java

If you use NILS with a module based application and want to use the resource bundles or other files for the translations of your application you must give access to the folder containing the resource bundles using the opens keyword.

module my.xyz {
  exports my.package;
  requires com.codepulsar.nils.core;
  opens my.package;
}

In the example the package/folder containig the translation files is my/package.

It is recommended to limit the access of the opened package to the NILS module. In the next example the access is granted only for the NILS Jackson Adapter:

module my.xyz {
  exports my.package;
  requires com.codepulsar.nils.core;
  opens my.package to to com.codepulsar.nils.adapter.jackson;
}

NilsFactory in a multimodule project

If you want to use NILS in a project contains different modules there are two main approaches using NILS:

  • Use one NilsFactory for all modules

  • Use one NilsFactory per module

One NilsFactory for all modules

This could be a solution if your project has a kind of "commons" module with classes shared between different other modules.

That you can provide one class using the NilsFactory to provide access to all other modules. This approach is useful if you want all translation at one place.

One NilsFactory per module

In this case each module has its own translation files with its own NilsFactory.

This approach is recommended.