Usage
Generating an I18N class from an I18N resource file
The generate
goal of the I18N plugin is bound to the generate-sources
phase in the build lifecycle. As a result generated classes are available at compile time.
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>com.github.robtimus</groupId>
<artifactId>i18n-maven-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<bundleName>com.foo.bar.i18n</bundleName>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
This snippet will create class com.foo.bar.I18n
from resource file i18n.properties
in folder src/main/resources/com/foo/bar
. Assuming the resource bundle contains key error.message
, this can be accessed as follows:
String message = I18n.error.message();
If the message contains any place holders, these will be required in the method call:
String message = I18n.error.message("arg1", "arg2");