For localization, you can change any text fields to i18n labels by using the small gear icon:
For example, let's look at the following two i18n files:
#demo_en.properties
label.text=LABEL
tf1.text=HELLO
#demo_fr.properties
label.text=étiqueter
tf1.text=bonjour
Let's apply them to our small UI. First, we change all text values to i18n variables:
And now, we can select English and French versions and preview the application without even compiling any code!
Here is the English version:
Here is the French version:
This way, you can be sure that your UI looks good in all supported localizations.
In Java code, you can set the resource bundle used for a specific FXML localization in the Loader API:
// for current system locale
loader.setResources(ResourceBundle.getBundle("chapter4.demo"));
// for specific locale
loader.setResources(ResourceBundle.getBundle("chapter4.demo", new Locale("fr", "FR"));
Here, chapter4 is a package name and demo is the first part of the filename (demo_fr.properties).