Example Using a Localization Properties File Defined Outside the Form
A localized properties file can be used within a form. In the example, a button is created that changes the label for a text field. The value for the label is localized using properties files external to the form’s own properties files.
Procedure
- Add a text field and a button to a form.
-
In the Properties view for the form, go to the Resources tab. Click the plus sign to add a resource, locate the new properties file you created in the Presentation Resources folder, and add it as a resource for the form.
Note: You will add the new properties file as a form resource using the base name. The various localized versions, with the locale code appended to the file name (preceding the .properties extension) will be inferred from the base name, based on the user’s locale, at runtime.
The properties file now appears as a resource in the Resources tab, identified by a name and path (URI). The Localized button is automatically selected for the properties file, indicating that the run time should search for localized copies to match the user’s locale.
- In the Properties view for the text control, give the control a name in the Name field on the General tab, for instance localizedText.
- Go to the Rules tab in the Properties view for the button. Click the button to Define a new rule for the button that will be triggered when the button is clicked.
- Leave the values unchanged in the Rule Details dialog, and click Next.
- Leave the values unchanged in the Rule: Pick Events dialog and click Next. This simply means the rule we create will be triggered when the button is clicked, which is the default event for buttons.
- In the Define Actions dialog, click the plus sign to define a new action.
- In the Add Action dialog, select the radio button Create a new action, and leave the radio button Script Action selected. Click Next to specify a script that defines the action.
-
Using the content assist pop-ups to ensure correct values, type the following line of script (assuming there is an item in your properties file whose key is mykey1 and whose value is My Key One):
control.localizedText.setLabel(resource. MyLocalizedResourceFile.mykey1);
- Preview the form in the GWT Preview tab. Click the button on the form, and the text field’s label should say My Key One.
- While still in preview mode, scroll down to the area immediately below the form and change the locale used for the preview from Default Locale to French - France.
- Click the button on the form again, and the text field’s label should now show the localized French text for the button’s label.
Copyright © Cloud Software Group, Inc. All rights reserved.