Child pages
  • Internationalization - I18N

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note that only the i18n table set on the main solution is taken into account. All i18n messages of the solution, including its modules, will be stored into that table. It is not possible to use a different i18n table in a module than the one used in the main solution.

Tip

The ideal time to start with i18n is at the beginning of building a solution, so the developer can enter the i18n keys when building forms and methods. It is also possible to enter i18n after finishing the solution by using the Externalize Strings feature.

Definition 

Inside Servoy Developer the message files are stored as property files in the workspace, under resources > messages. At runtime though, they are stored in the database. Thus, at some point before deploying to the server, the data in the workspace needs to be transferred to the database table. This can be done either at solution export, by checking the Export i18n data checkbox in the Export Wizard, or during design by right clicking the I18N files node under Resources in Solution Explorer, and choosing Write to DB option from the context menu.

...

On Servoy elements, it is possible to use a text reference, which is a key linked to a messages file. Which is replaced at runtime with the localized text from the messages file.

Labels, Buttons, Tabpanels, FieldTitles

In design, i18n can be set for such items in their text or titleText property.

...

On the text property, select the browse button. This will open a dialog. The first tab is to enter text, but in the second tab the i18nkey can be selected. When selecting a key, it will replace the text with i18n: + the keyname.
An example of an element text reference is: i18n:hello_world, which is looked up in the messages file and produces the text in a locale like 'hello world' in English or 'hola mundo' in Spanish.

Dialogs, Calculations, Methods

To use i18n in scripting, use the function:

...

Note that in dialogs it is not necessary to use the function i18n.getI18Nmessage() but only i18n:key is enough.

I18N Key Names

The developer is free to create and use their own i18n key names. Nevertheless, it is a good idea to have a naming convention for this.

...

Panel

Sample naming convention:
Labels : lbl.ok
Dialogs: dlg.ok

Or using the company name as prefix:
Labels: servoy.lbl.ok
Dialogs: servoy.dlg.ok

Date Format

In case of a date format, one can use for example: 'dd-MM-yyyy'. This would be a nice formatted date in the Netherlands, but it might not in other countries. That's why it is a good idea to use i18n instead of a hard coded format. Instead of setting the string in the format, do set an i18n key in the format. For example: i18n:servoy.lbl.date. In that i18n value, one can set for Dutch 'dd-MM-yyyy' and for English (US) 'MM/dd/yyyy'.
Image Added

Overwriting i18n

An i18n message can be overwritten with the function i18n.setI18NMessage().

Example When using i18n keys for date formats, let the users enter in the system how they prefer their date separator. Then when the user starts the system, use i18n.setI18NMessage() to replace the default separator with the user-defined separator. For example, in the i18n message the separator used is '/', but the user wants a '-' to separate the date. In the onOpen method the following code can be entered:

Code Block
i18n.setI18NMessage('servoy.lbl.date', utils.stringReplace(i18n.getI18NMessage('servoy.lbl.date'),'/','-'))

Seperators

Formatting defaults need to be specified. In the English(US) format, the dot ('.') is decimal separator (and comma is 1000 separator). Decimal values within code need to be specified in English format as well. This will automatically be translated to the end users format when they run the code.

Example In Dutch, for instance, the separator for decimals is a ','. In the format property of a field, the English format will be entered for a number (for example '#.00'). When a user with the locale 'Nederlands(Nederland)' uses the solution and enters '23' into the field, it will display '23,00'.

I18N Configuration

Problem Markers

Servoy provides support in Developer to enable problem markers on non-externalized strings found in scripting. By default, these type of problems is ignored, but this can be changed from Preferences page.

...

Servoy provides a Quick Fix option for the Externalized strings problem markers, with the options of adding the @SuppressWarnings annotation at function level, inserting the //$NON-NLS-<n>$ tag at the end of the individual code line, or opening the Externalize strings wizard.

 Save Action

Servoy offers a clean up option for automatically removing unnecessary Non-nls comments from code on saving a JavaScript file.

To enable this option, go to: Window > Preferences > JavaScript > Editor > Externalize Strings and check the Remove unused $NON-NLS$ tags on save option.