Tuesday February 12, 2008 | Just my 2¢ Naoto Sato's Weblog |
|
All Languages |
English Only |
日本語のみ *Easier* localization in JavaFX Script In the last blog entry, I explained the proposal for an easy way to localize string literals in JavaFX Script language. Now the implementation for it is in the OpenJFX Compiler's repository, let's take a look at this feature in action. As an example, I localized the JavaFXBalls demo into Japanese (it's in the repository as well):
You see the text in the button at the bottom left corner reading "ストップ", which means "Stop". In this button's object literal creation, the source code looks like:
text: bind if (not test._is_running) then ##"Start" else ##"Stop" And it's JavaFX properties file entry is simply:
"Stop" = "ストップ" Now, we are planning to extend this string literal localization proposal into a generic string localization runtime library function. Suppose that there is a JavaFX runtime library class, e.g., javafx.util.StringLocalizer, and it has the following APIs:
package javafx.util;
public class StringLocalizer {
public attribute key: String;
public attribute locale: java.util.Locale;
public attribute packageName: String;
public attribute propertiesName: String;
public attribute defaultString: String;
// this is lazily bound to the above attributes.
public function localizedString(): String;
public static function associate(packageName: String,
scriptFileName: String,
properties: String): Void;
}
With these utility APIs, you could do something like:
// Object creation
var localizer = StringLocalizer{ key: "Hello, World!" };
// This prints localized text for "Hello, World!" for the default locale
System.out.println(localizer.localizedString());
// This prints localized text for "Duke" for the default locale
localizer.key = "Duke";
System.out.println(localizer.localizedString());
// This prints localized text for "Duke" for the French locale
localizer.locale = Locale.FRENCH;
System.out.println(localizer.localizedString());
// This prints localized text for "Duke", from
// the FX properties file "foo/bar/MyBundle_fr.fxproperties
localizer.packageName = "foo.bar";
localizer.propertiesName = "MyBundle";
System.out.println(localizer.localizedString());
Also, with the "associate()" static function, you could associate a JavaFX Script source file (or a javafx package) to a JavaFX properties file so that the string literal localization consults the associated JavaFX properties file for searching the localized text. (By default, the JavaFX properties file with the same name/location as the source file is searched). This static function would provide developers with the granularity of how the JavaFX properties files are packaged. You could provide one single JavaFX properties for your entire application, or one properties file for each source script file, or in between. This is still a rough idea and needs to be refined. But I'd hope this would contribute to an *easier* localization in JavaFX. (2008-02-12 12:13:39.0) Permalink Comments [2] |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||