Naoko Hamamoto's Weblog

« Localized JavaFX... | Main | JavaFX.com is Renewe... »

20090204 Wednesday February 04, 2009

How to Internationalize a JavaFX Sample using NetBeans IDE

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]

Trackback URL: http://blogs.sun.com/naoko/entry/how_to_internationalize_a_javafx
Comments:

I notice that the API has marked javafx.util.StringLocalizer as desktop only. Does that mean that this method of localisation will not work on Mobile? How can we localise our apps on mobile and desktop without duplicating effort?

Posted by Sharebear on April 23, 2009 at 04:24 PM PDT #

Hi Sharebear,

Thank you for your question.

I was informed that the current implementation is only for desktop and there are plans to create a more compact localization mechanism for the common profile in the future release.

Hope this helps.

Posted by naoko on April 27, 2009 at 04:22 PM PDT #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.