JavaFX Scene Builder User Guide
9 Internationalizing Your FXML Layout
This chapter discusses the internationalization support that is provided with JavaFX Scene Builder.
The JavaFX Scene Builder tool enables you to adapt your FXML layout to various languages and regions through the use of resource bundle files. When you add a new element to the Content panel, the element's visible property values are set to default values. For example, a button element has a default Text property value of Button. This default value can be changed with an internationalized string by hovering your mouse cursor over the right of the Text property text field, clicking the round cog icon that appears, and then selecting Replace with Internationalized String, as shown in Figure 9-1. Notice that the default value is then replaced by %key.unspecified, which you need to replace with the appropriate resource key name that is defined in your resource file. The percent sign (%) prefix is a visible indicator that the Text property value following it is a resource key name. You can still use the percent sign as a first character for the Text property value. If you have not selected the Replace with Internationalized String setting, then in the FXML file, the percent sign will appear as \%. This indicates that the rest of the property value has no link with internationalization and that it is not a key name.
Figure 9-1 Internationalizing a Button Element
Description of "Figure 9-1 Internationalizing a Button Element"
The HelloI18N sample can help show the internationalization support. The sample is included with the JavaFX Scene Builder samples bundle. Its
Main class shows how to load the resource bundle. The sample includes the Bundle.properties and Bundle_fr_FR.properties files. When you open the <javafx-scenebuilder-samples-1_0-beta-install-dir>/HelloI18N/src/helloi18n/HelloI18N.fxml file, the FXML file is opened in its own instance of the JavaFX Scene Builder window and you see a button that is labeled HelloI18N. Figure 9-2 shows that the button element's Text property value was set to use the button.text resource key, which is defined in the Bundle.properties file as having the value of HelloI18N. The percent sign in front of the Text property's text field is a visible indicator that the value in the text field is a resource name. If you replace the value assigned to button.text in the Bundles.properties file and save the change, the new value is immediately reflected in the button displayed on the Content panel. You can define additional resource keys in your resource bundle files and use them in the FXML layout you are building.
Select the Preview from the Main menu, then Internationalization command, and then Set Resource. In the Choose Internationalization Resource File dialog box, choose the Bundle_fr_FR.properties file to see how the HelloI18N sample application appears when using the French resource file. Notice that the text displayed on the button is now Bonjour. Changes you make and save to the resource file are reflected in the FXML layout you are working on in the JavaFX Scene Builder tool.
Figure 9-2 Using Resource Key Value to Internationalize the Text Property Value
Description of "Figure 9-2 Using Resource Key Value to Internationalize the Text Property Value"