NLS Service

Location of resource bundles

The translations used by the PMO NLS service must be located in the project’s resource folder, mirroring the path of the used pmo. For example:

nlsFolderStructure
Figure 1. An example of a nls folder structure

In this example, NLS Strings in org.linkki.samples.binding.pmo.ButtonsSectionPmo that need to be translated must be defined in org.linkki.samples.binding.pmo.linkki-messages.properties.

These .properties files contain messages in text form, each file represents one supported language for the PMOs in the same folder. It’s important that these files share the base name linkki-messages. A file with the base name has to be present in the resource folder and acts as fall back option if no specific .properties file is found for a locale. You can support as many languages as you want by simple adding another .properties file to the resource folder, its name consisting of the base name and the language code separated by _. As shown in the example above, the German translations are represented by the file linkki-messages_de.properties. Note that each of these files have to contain the same items, but translated for the language they represent.

Predefined key structure for linkki PMO

An entry for a translation in the linkki-messages.properties files consists of two parts: The "key" that identifies a localizable aspect of a PMO property and the text, seperated by =. The key is a String that consists of the PMOs class name, the name of the PMO property name and the localizable aspect of the property, seperated by _. The linkki-messages.properties file from the picture above looks like this:

ButtonsSectionPmo_reset_caption=reset
ChildrenSectionPmo_caption=Children
ChildrenSectionPmo_noOfChildren_label=Number of children
ContactSectionPmo_favorite_caption=Add to favorites
ContactSectionPmo_firstname_label=Firstname
ContactSectionPmo_gender_label=Gender
ContactSectionPmo_lastname_label=Lastname
ContactRowPmo__address_label=address
ContactRowPmo__edit_tooltip=edit
ContactRowPmo__name_label=name

The second entry of the above .properties file points to the PMO ContactRowPmo, and provides an English translation for the label of its property name:

    @UITableColumn(expandRatio = 1F)
    @UILabel(position = 10, label = "Name")
    public String getName() {
        return contact.getName();
    }
linkki always tries to retrieve a value from the linkki-messages.properties, if the file exists. That means that the label "Name" that is defined directly in the annotation @UILabel above will not be used in this constellation. The entry ContactRowPmo_name_label=name overrides it as default value if there is no specific .properties file for the user’s locale.

Translatable PMO properties

All aspects containing String values can be translated. Frequently used examples are label, caption and toolip. Section captions can also be translated. Its key does not contain a property name but only the PMOs class name and "_caption". For example:

@UISection(caption = "Children", closeable = true)
public class ChildrenSectionPmo {

With its German translation entry in linkki-messages_de.properties:

ChildrenSectionPmo_caption=Kinder