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.

Maven

<dependency>
  <groupId>com.codepulsar.nils</groupId>
  <artifactId>nils4spring-spring-boot-starter</artifactId>
  <version>1.1.0</version>
</dependency>

Gradle

implementation group: 'com.codepulsar.nils', name: 'nils4spring-spring-boot-starter', version: '1.1.0'

Configuration

The NILS4Spring starter works if one of the following requirements are met:

  1. A translation.yml is your classpath (like Spring’s application.properties).

  2. A translation.properties is your classpath (like Spring’s application.properties).

  3. The configuration property nils.base-file-name in the application.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:

  1. Directly using the bean NilsFactory, providing the known functionalitities of NILS, like context based NLS.

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