Introduction
Some time ago I wrote about moving a Teamroom application up to IBM Bluemix. This month the XPages runtime is now general available.
In the post I mentioned I would come back on some design gotchas I saw while analyzing and preparing the Teamroom application for staging it to Bluemix. So here is (at least9 a first post.
What I noticed for example was the usage of the l18n library in SSJS and placeholders in properties files.
i18n formatting
This is a server script library with methods to format messages for localization, display dates in a locale-specific manner and miscellaneous Internationalization utilities.
So how does this works?
Create two or more strings properties file e.g.
- strings.properties
- strings_sv.properties
The strings.properties file content:
compliment=Handsome
hello.world=Hello {0}
The strings_sv.properties file content:
compliment=Snygging
hello.world=Hejsan {0}
Now create an XPage and place e.g. a Computed Field control on it and calculate it’s value:
<xp: text><xp: this.value><![CDATA[#{javascript:compliment = strings.getString(“compliment”);
return i18n.format(strings.getString(“hello.world”), compliment);}]]></xp: this.value></xp: text>
(Do not forget to enable Internationalization for your application in the Application Properties under section International Options)
Placeholders
Notice in the properties file the usage of a placeholder: hello.world=Hello {0} and how it is being referred: strings.getString(“hello.world”), compliment. Here the variable compliment (another string property value) is put in the placeholder.
As a result in the default language I get returned “Hello Handsome” and when I choose Swedish as default language in my browser I get returned “Hello Snygging”.
By wrapping it and formatting it with the L18n library you ensure it is fitted according the active language. This is very handy for dates, amounts etcetera.
Links of interest
More details about JavaScript Internationalization can be found in the IBM Notes Domino Application Development wiki.