Servoy provides internationalization (i18n) tools that allow developers to conveniently convert their applications into multiple languages. Developers can use i18n keys instead of hardcoded text to call the appropriate language from an i18n database table. This chapter gives an overview of the Servoy tools provided to create internationalized solutions.
Note: In addition to the tools discussed below, Servoy provides a scripting API for commonly used functions, accessible via the i18n node towards the bottom of Solution Explorer (separate from the Resources project). This feature is discussed in the Programming Guide.
I18n databases and tables
The data for internationalization is saved in the workspace under the Resources project. The table is then exported with the solution when the solution is deployed to the application server.
To view and edit an i18n table:
- In Solution Explorer, under the Resources project, click on the i18n files node.
- Double-click on the i18n file you wish to access in the contextual list at the bottom of the Solution Explorer. It will open in Table Editor view.
- Along the top of this view is a filter that enables users to quickly find a i18n key. The next two items at the top are the Language and Country drop-downs. To edit an i18n key:
- Select the key and the language/country you wish to edit.
- Click on the desired i18n key from the list.
- Enter the reference text (which is the default language text) and the locale text appropriate to that language/country.
- To add a new i18n key:
- Type in a name for the new key in the Key text box.
- Enter the reference text and the locale text in their respective boxes.
- Click Add.
Defining an i18n Table for a Solution
To add internationalization to your solution, an i18n table needs to be associated with the solution. You will be prompted to do this when you first add internationalization to a solution using either of two available methods: (1) externalizing all the available text in a solution or (2) adding i18n messages one by one to your forms/scripts (see image below of i18n buttons in main toolbar).
- Externalize – This option creates a list of all the items in your solution that are available for internationalization and automatically creates corresponding i18n keys and messages.
- Edit i18n messages – This option opens the defined i18n table for you to individually add i18n keys and their associated text. You can then add the keys to the appropriate objects in a form or script.
- Click on either button to add internationalization to your solution. The following window will appear, if an i18n table has not been defined
- Click Yes to continue. A list of available databases/tables will be displayed in a select window.
- Choose the appropriate i18n table or create a new i18n table, as applicable. The selected i18n table will open in Table Editor view. If you chose to create a new table, it will also open a new table containing default i18n keys that ship with Servoy.
Note: Changes made to i18n entries are locally saved to the workspace during development. The defined i18n table will then be added to the application server upon deployment of the solution.
Tip: To change a solution's assigned i18n table at any time, select the solution in Solution Explorer to show the solution's Properties view. Then, double-click on the i18nDataSource line item in the Properties view and select the desired table from the pop-up browser that appears.
Externalizing a Solution
As mentioned previously, the Externalize function adds internationalization to a solution by creating a list of all the items in your solution that are available for internationalization. It then generates i18n keys and messages from all the text properties in the solution (form objects such as button lables, column titles) and replaces the hardcoded text with the i18n keys, with the default text being the original text property that was assigned to the item.
To externalize a solution:
- Click on the Externalize (1) button. The i18n externalize dialog box will open, showing the following three columns (from left to right):
- The text property to be externalized
- The hardcoded text that will become the default text
- The i18n key name to be assigned to the property
- Customize/edit the keys by double-clicking on a desired key, if desired.
- Deselect any items you do not wish to be externalized, if applicable.
- Click Externalize. An externalize dialog will appear, showing the status of the externalize process. Once completed, this dialog disappears and all item properties will be converted to i18n keys.
Editing i18n keys
Internationalization can be added one by one to a solution by editing i18n keys using the Table Editor_._
- To quickly access the editor, click on the Edit i18n messages button on the toolbar.
- I18n messages can be added to objects in both the Form Editor and the Script Editor:
- In the Form Editor, simply type in the i18n key where you would normally type in the hardcoded text (for example, inside a text box or label, or via the Properties view in text, toolTipText, or titleText properties.
- In the Script Editor, type in the i18n key inside the string in place of hardcoded text.