Tutorial of an application using Nuiton I18n and a library using Nuiton I18n itself (use Maven)

In this tutorial, we will create an application that will display a message to the user and will call the unique method of the library we created in the previous tutorial. We suppose in this tutorial, that you followed the two previous tutorials in order not to start all over again.

I18n plugin configuration

In the I18n plugin configuration, we will add the bundle goal. This goal gathers all the application and its library i18n strings in order to create a unique bundle.

<goal>bundle</goal>

The application code

In the previous examples, we used Nuiton I18n default values, but in order to optimise loading, in a final application, it is necessary to change the initializer before. The default initializer, ClassPathI18nInitializer, looks for all the I18n bundles in the classpath in order to load them, but as our plugin creates a unique bundle gathering all I18n strings, we can use DefaultI18nInitializer, that takes into parameter the bundle name created by the plugin, it will then load only the said bundle. This can make you gain up to 10 secondes at load time, following the classpath size.

package org.myOrganisation.myApplication;

import org.myOrganisation.myLibrary.myLibrary;
import org.nuiton.i18n.I18n;
import org.nuiton.i18n.init.DefaultI18nInitializer;
import java.util.Locale;

public class myApplication {

    public static void main(String[] args){

        I18n.init(new DefaultI18nInitializer("myApplication-i18n"), Locale.FRANCE);

        System.out.println(I18n._("String to translate in my application"));
        myLibrary.myMethod();
    }
}

Configuration

Do not forget to precise the classpath and main class in maven jar plugin.

Tutorial sources