Introduction
NILS 4 Spring is the integration of NILS into the Spring Framework.
Requirements
The library requires
-
Java 17 or higher (required)
-
Spring Boot 3.x or (suggested)
-
Spring Framework 6.x (suggested)
The library is also compatible with older versions of Spring Boot and Spring Framework.
Getting started
Add to your project
The easiest way to include NILS4Spring is by using the NILS4Spring starter dependency.
It configures NILS Adapters to use with YAML or . properties
files.
You can find the current versions in the Maven central repository.
If you want to use another translation source (like JSON or JDBC) take a look at the chapter Auto configuration to find a more suitable NILS Adapter.
If you want to use NILS4Spring without a starter dependency see here for more information.
Configuration
The NILS4Spring starter works if one of the following requirements are met:
-
A
translation.yml
is your classpath (like Spring’sapplication.properties
). -
A
translation.properties
is your classpath (like Spring’sapplication.properties
). -
The configuration property
nils.base-file-name
in theapplication.properties
refers to a YAML or properties file.
For more information see Configuration properties.
Using
Once configured the are the following possibilities to use NILS in your application:
-
Directly using the bean
NilsFactory
, providing the known functionalitities of NILS, like context based NLS. -
In-directly using the bean
messageSource
from Spring, wherever a "messageSource" is used within the Spring application.
@RestController
public class DemoRestController {
private MessageSource messageSource;
private NilsFactory nilsFactory;
public DemoRestController(MessageSource msgSource, NilsFactory nilsFactory) {
this.messageSource = msgSource;
this.nilsFactory = nilsFactory;
}
// ...
Please visit the documentation of NILS for further information how to use NILS.