Wednesday February 04, 2009 Someone asked me to write step-by-step instructions on how to internationalize a JavaFX sample using NetBeans IDE, so I decided to also post it here.
For this exercise, we are going to use Fading Transparent Window sample, as it is simple and it has some text in it. Most of the samples are very visual, and there are no messages to localize.
Setup
1. We will use NetBeans, so download NetBeans 6.5 with JavaFX support from here. Follow the instructions to install it on your system.
2. Let's grab the source code for Fading Transparent Window. Click on Download Source Code button to download the zip file. Extract the zip file into a directory of your choice. It contains a NetBeans project called TransparentWindow.
3. Open this project in NetBeans.

4. Now run it. You can simply click on the green triangle at the top. Move the mouse cursor in and out of the application see the visual effect.


Internationalization
OK, time to internationalize this application. I have outlined the steps required to internationalize a JavaFX application in my previous entry, JavaFX Localization. Steps are almost identical here, except that in this scenario, we will programmatically set the default locale to Japanese per the requester.
1. Change the application to use string literal translation notation.
You can either embed it or declare it as a variable.
Embedded:
====================================================

====================================================
Declared:
====================================================

====================================================
2. Let's create Main_ja.fxproperties. Place this file in the same directory as Main.fx in the NetBeans project.

3. The application should run just fine in a Japanese environment now, but since I am testing it on a system with English locale set as default, I am going to programmatically set my default locale to Japanese.
====================================================

====================================================
Of course we can also simply do
====================================================

====================================================
but I wanted to show the other way just in case if the locale of your choice is not defined in the Locale class.
4. Now it's all set, ready to be run. Simply click on the triangle to execute it.


That's it. Very simple and straight forward!
Posted by naoko ( Feb 04 2009, 04:33:13 PM PST ) Permalink Comments [2]Today's Page Hits: 5