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.

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.

...

  • tableName_id  (primary key, integer)
  • message_key (i18n key, string)
  • message_language (i18n language, string)
  • message_value (i18n value, string)

Usage

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.

Image Added

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_worldWhich , 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:

Code Block
i18n.getMessage("i18n-key")

The i18n key has to be provided as a string.

Example This is an example of how to use the i18n function

Code Block
var message = i18n.getMessage("servoy.general.clickOk");

The method will return the value of the language selected in the client. If the selected language has no entry, it will return the default value/reference text: 'Click OK to continue'.

It is also possible to use dynamic values. There can be an array provided with the values that have to be replaced. To use dynamic values, the i18n value should contain tags like {0}, {1}, ... , {n}. The tags will be replaced by the values provided in the same order.

Code Block
var company_name = "Servoy";
var amount = 15
var type = "developers";
var message = i18n.getMessage("servoy.license.registered",[company_name, amount, type]);

For example, if the key servoy.license.registered has the value 'Registerd to {0} with {1} {2}' the outcome will be 'Registered to Servoy with 15 developers'.

When using i18n in a dialog, depending on the language of the user, the 'Yes' button can be 'Si', 'Ja' , 'Oui', 'Hai', etc.
To solve this, get the translation in a variable and use that to check which button is clicked.

Example This is an example of how to use i18n in dialogs

Code Block
function question() {
	var yes = i18n.getI18NMessage("servoy.lbl.yes");
	var no = i18n.getI18NMessage("servoy.lbl.no");
	var cancel = i18n.getI18NMessage("servoy.lbl.cancel");
	var answer = plugins.dialogs.showQuestionDialog("i18n:servoy.lbl.title", "i18n:servoy.lbl.message", yes, no, cancel);
	if(answer == yes) {
		application.output("yes is pressed");
		//execute code.
	}
}

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

I18N Configuration

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.

...