Commands

Kilt provides the following commands:

export-xls

Exports the translations in Java i18n resource bundle files into an XLS(X) file.

import-xls

Imports the translations from an XLS(X) file back into the Java i18n resource bundle files.

create-facade

Creates the I18n enum facades for type safe access to localized messages.

reformat

Reformat resource bundle files (and actually any .properties files) to a defined format.

reorder

Reorder the entries in resource bundle files (and actually any .properties files) by a certain criterion.

Those commands are described in more detail in the following sections.

export-xls

Kilt can generate Excel sheets as either XLS or XLSX and is able to modify both of them. To do this Kilt reads the given Java i18n resource bundles and writes their contents to an existing XLS(X) file or creates a new one. Each row in the generated XLS(X) sheet corresponds to a key in a resource bundle. The actual translations are added as columns to that rows.

Example of an XLS file generated by Kilt

It's recommended to let Kilt generate the first XLS(X) sheet, since Kilt makes certain assumptions about the structure of that files. Afterwards that file may be prettified to be better readable for the translators. Kilt will only modify the actual translation contents in subsequent generation steps.

The generation of an XLS(X) sheet for Java i18n resource bundles works closely together with the reimport of that sheet to provide a common translation workflow. Please see the next section on how to import the translation sheet back into the Java i18n resource bundles.

import-xsl

An XLS(X) file with updated translations can be reimported back into the Java i18n resource bundles with Kilt.

Kilt will only update values that actually have changed and it will not reorder the resource bundle files (although translated keys that are missing in the resources bundles will be added to the end of the file).

Kilt also allows removing keys from the resource bundles that are missing in the translated XLS(X), but does not do so by default.

create-facade

Kilt allows the generation of a Java facade for accessing the available resource bundle entries in a type safe manner. It provides an additional accessor class for easier access to the values of the resource bundle entries.

The accessor class can even be used for resource bundles without a generated facade.

Usage of the Java facade

Kilt provides the class I18n for accessing the resource bundles keys of the generated enum facades as well as keys of resource bundles without a generated facade. See the Javadoc for details of using this accessor class.

A typical usage is:

1// create an accessor class for the default locale
2final I18n i18n= new I18n();
3// get the value for the key "MESSAGE_HELLO" from the generated enum
4// facade "Messages"
5final String translatedValue= i18n.get(Messages.MESSAGES_HELLO);
6// get the value for the key "otherKey" from the bundle "otherBundle"
7// for which no facade was generated
8final String valueFromOtherBundle= I18n.get("otherBundle", "otherKey");

The accessor class allows marking missing translations instead of throwing a MissingResourceException. This allows to easily spot missing translations without breaking the functionality of the application.

Translations are marked only after no fallback translation can be found.

For example if you have the following bundles:

messages_de_DE.properties
messages_de_AT.properties
messages_de.properties
messages.properties

and your current locale is de_AT the translation for a resource entry will be searched in the following files in this order:

  1. messages_de_AT.properties
  2. messages_de.properties
  3. messages.properties

Only if the key is not found in any of the above files the resource will be marked as missing. This is no special behaviour of Kilt, but the normal strategy of Java for finding translations.

Missing translations are marked by default. If you want the normal Java behaviour of throwing a MissingResourceException instead, configure the I18n accessor accordingly.

To use the accessor class you need to import the kilt-runtime jar. Either download it from the Download section or add it to your project via the maven coordinates:

1    <dependencies>
2      <dependency>
3        <groupId>de.poiu.kilt</groupId>
4        <artifactId>kilt-runtime</artifactId>
5        <version>1.0.2</version>
6      </dependency>
7    </dependencies>

reformat

Kilt allows reformatting the entries in resource bundles and other .properties files to a specified format. By default it uses the format <key> = <value>\n. The format allow specifying possible leading whitespace, the separator char, whitespace around the separator char and the character(s) to use for line breaks (separating the entries).

By default, the actual keys and values are not modified at all. By giving the parameter reformatKeyAndWhitespace keys and values will also be reformatted by removing insignificant whitespace, newline and escape characters.

reorder

Kilt allow reordering the entries in resource bundles and other .properties files either alphabetically or by the order given in the specified template file. The handling of comments and empty lines can be specified via parameter attachCommentsTo.