< Index | XML : internationalize dynamic content

XML : internationalize dynamic content

XML screen have many ways to display dynamic content with properties. We will start to briefly present you them and show you an advanced example on how internationalize dynamic content.

Basics

Internationalisation Property

In your XML files, every %I18N_KEY% will be replace by their i18n corresponding value located in /i18n/message.properties or /i18n/message.XX.properties, where XX corresponds to the selected language.

For more information, please take a look at Tutorial 4 - internationalisation.

Data Binding property

${myProperty} and @{myProperty} do basicly the same thing : extract a value from a DataProvider given while calling Kuix.loadScreen() or Kuix.loadXml() methods by invoking myDataProvider.getValue("myProperty"). The main difference reside in the life time of the linkage between the widget where to put the value and the DataProvider.

${propertyName} is converted to its value only at parse time. No linkage between the Widget and the DataProvider is kept.

@{propertyName} is converted to its value at parse time and a the widget is binded to the DataProvider if not null. The main goal of this feature is to be able to change the value directly in the DataProvider and it generate automaticaly the update on all binded widgets. The concept go forward because you can mix more than one property in an attribute definition.

For more information, please take a look at Tutorial 5 - dynamic data display.

Advanced Example

Let's do a Kuix application which locate someone.
We start with I18n:

messages.properties:
MY_I18N_KEY=Where is {0}? He is in {1}!

 

mainscreen.xml:
<screen title="I18n + dynamic data exemple">
    <textarea>%MY_I18N_KEY(Brian, the kitchen)%</textarea>
</screen>

 

It produces the following message on start:

"Where is Brian? He is in the kitchen!"  

 

Now you can make this application being used to locate someone else than Brian and in differnt place.
You can specify dynamic data directly into i18n key as parameter:

mainscreen.xml:
<screen title="I18n + dynamic data exemple">
    <textarea>%MY_I18N_KEY(${human}, @{location})%</textarea>
</screen>

 

The ${human} property will only be converted at parse time. It's not usefull to keep linkage.
The @{location} property will be provided and linked to DataProvider.

public class HumanLocatorDataProvider extends DataProvider {

    private static final String HUMAN_PROPERTY = "human";

    private static final String LOCATION_PROPERTY = "location";
    private String location = "the garden";

    public void setLocation(String location) {
        this.location = location;
        dispatchUpdateEvent(HUMAN_PROPERTY);
    }

    protected Object getUserDefinedValue(String property) {
        if (LOCATION_PROPERTY.equals(property)) {
            return location;
        }
        if (HUMAN_PROPERTY.equals(property)) {
            return "John";
        }
        return null;
    }

}

 

Each time you will call the setLocation() method, the text will be updated.
And it could gives the following result:

"Where is John? He is in the garden!"