Skip to main content

Localized Reaction Time

Posted by malenkov on July 9, 2010 at 7:31 AM PDT

Last half a year I was quite busy. My personal priority was to get a driving license. Among many exercises in my car driving school there was a psychological test consisting of different tasks to check your reaction. I developed one of them by using JavaFX. It examines how fast you can click.

I would like us to consider some localization issues by using my application as an example (see the main script and its russian properties). If a double hash sign ## is prefixed to a string literal, JavaFX substitutes the string literal with a localized one during running the application. It means that the localized strings will be selected from the fxproperties files for the current locale.

For example, for the following JavaFX string literal:

##"Average time"

an fxproperties file could contain the following declaration:

"Average time"="Среднее время"

It is very convenient and reminds me the gettext library. However, if these string literals are too long, then the fxproperties files become difficult to maintain. JavaFX solves this problem by using shortcuts.

For example, for the following JavaFX string literal:

##[ABOUT]"Click and wait.\nClick again when color is changed"

an fxproperties file could contain the following declaration:

"ABOUT" = "Кликните и ждите.\nПри изменении цвета кликните снова"

These shortcuts could be used for more complex parameterized strings as well.

For example, for the following JavaFX string literal:

##[FAILED]"{prefix}:"
"\n{%5d model.misses} misses;"
"\n{%5d model.passes} passes."

an fxproperties file could contain the following declaration:

"FAILED" = "%s:\n%5d раз пропустил;\n%5d раз прошёл."

Note that variable names are not used in localization. It is important only to declare their types. You can reorder variables using the following notation: %[index$]type.

And the most important feature! While in Java SE you had to use native2ascii converter, JavaFX enables you to change the charset using the following command:

@charset "windows-1251";

It allows to create the fxproperties files in your favorite editor, even if it does not support UTF. This feature is very relevant for me.

JavaFX fxproperties files are much more convenient and more powerful than Java SE properties files. For more information, see the tutorial and the language reference.

original post

Related Topics >>