Internationalization

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 has to contain the same items, but translated for the language they represent.

Translatable PMO Properties

All aspects containing String values can be translated. Frequently used examples are label, caption and tooltip. Section captions can also be translated. For example:

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

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

ChildrenSectionPmo_caption=Kinder

String valued aspects such as placeholder or caption do not have a property name. In this case, the pattern for the key would be PmoClassName__aspectName. For convenience, the second underscore can be omitted, i.e. the pattern PmoClassName_aspectName can also be used. If both keys happen to be present, the pattern with two underscores has a higher precedence.

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 PMO’s class name, the name of the PMO property and the localizable aspect of the property, separated 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
ChildrenSectionPmo_firstname_label=Firstname
ChildrenSectionPmo_lastname_label=Lastname
ChildrenSectionPmo_note_label=Note
ContactSectionPmo_favorite_caption=Add to favorites
ContactSectionPmo_firstname_label=Firstname
ContactSectionPmo_gender_label=Gender
ContactSectionPmo_countryOfBirth_label=Country of Birth
ContactSectionPmo_lastname_label=Lastname
ContactRowPmo_address_label=address
ContactRowPmo_edit_tooltip=edit
ContactRowPmo_name_label=name

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

    @UITableColumn(flexGrow = 10)
    @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. It is useful to include the default label in the annotation to avoid having to look it up in the properties file when viewing the source code.

linkki will also look up NLS Strings of the superclasses of a class as well as implemented interfaces. This lookup prioritizes the current class, followed by all of its superclasses, followed by implemented interfaces and their superinterfaces.