Getting started with I18N Manager
This guide explains the minimal steps to integrate I18N Manager in a new application.
Prepare the Application
A new application created on start.vaadin.com can be used as a starting point for this tutorial. Open the site, select an empty project, choose Spring Boot as the framework, and download the generated archive. Extract it, import it into your IDE of choice, and verify the application starts correctly by running the main class.
Add the AppJars Repository
AppJars artifacts are published to the public AppJars Maven repository. Add it to your pom.xml so that Maven can resolve the AppJars dependencies:
<repositories>
<repository>
<id>appjars</id>
<name>AppJars Public Repository</name>
<url>https://maven.appjars.com</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Add the Dependencies
Given that it is a monolithic application, the following dependencies representing the three layers of the appjar must be added:
<dependency>
<groupId>com.appjars</groupId>
<artifactId>appjars-i18n-manager-flow</artifactId>
</dependency>
<dependency>
<groupId>com.appjars</groupId>
<artifactId>appjars-i18n-manager-data-impl</artifactId>
</dependency>
<dependency>
<groupId>com.appjars</groupId>
<artifactId>appjars-i18n-manager-business-impl</artifactId>
</dependency>
After adding them, build the application to confirm that the dependencies are resolved correctly.
Configure the Router Layout
Inject the RouteConfigurer provided by I18N Manager and configure the router layout in a @PostConstruct method so that the appjar views share the same layout as the rest of the application:
@Autowired
@Qualifier("I18nManagerRouteConfigurer")
RouteConfigurer routeConfigurer;
@PostConstruct
public void configure() {
routeConfigurer.setViewsRouterLayout(MainLayout.class);
}
The import for RouteConfigurer is com.appjars.i18nmanager.flow.util.RouteConfigurer.
Add the Views to the Navigation
Add the I18N Manager views to the application's navigation menu. Insert the following snippet at the end of the method createNavigation() in MainLayout, before returning nav:
if (accessChecker.hasAccess(LanguageCrudView.class)) {
nav.addItem(new SideNavItem("Languages", LanguageCrudView.class, LineAwesomeIcon.LANGUAGE_SOLID.create()));
}
if (accessChecker.hasAccess(TranslationItemCrudView.class)) {
nav.addItem(new SideNavItem("Translations", TranslationItemCrudView.class, LineAwesomeIcon.GLOBE_SOLID.create()));
}
The imports for the view classes are:
com.appjars.i18nmanager.flow.view.LanguageCrudViewcom.appjars.i18nmanager.flow.view.TranslationItemCrudView
Configure Application Properties
Add the following properties to application.properties:
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
spring.aop.proxy-target-class=false
vaadin.i18n.provider=com.appjars.utils.i18n.AppjarsI18nProvider
The spring.aop.proxy-target-class=false property is required for the appjar to function correctly.
Note
The bundled messages_<locale>.properties files are decoded as UTF-8 when scanning for missing keys. If your resource bundles use a different charset, set appjars.i18nmanager.properties.encoding (for example, appjars.i18nmanager.properties.encoding=ISO-8859-1).
Finally, add com.flowingcode and com.appjars to the list of whitelisted packages in application.properties:
vaadin.allowed-packages = com.vaadin,org.vaadin,dev.hilla,com.example.application,com.flowingcode,com.appjars
Testing the Application
Start the application by running the main Spring Boot class. After it starts, log in and navigate to Languages in the menu.
Create a new language by clicking the New Language button and filling in the language key (e.g. en) and region (e.g. US). Once the language is saved, navigate to Translations to manage the translation keys and their values for each language.