Friday December 12, 2008
JavaFX localization is easy and simple. If you know Java, it's very similar, but even better
Here I am going to walk you through some basic steps required to localize a very simple JavaFX application.
1. Create an application.
Here is my simple JavaFX GUI application in English. Note that the messages are externalized.
=================================================== import javafx.stage.Stage; import javafx.scene.*; import javafx.scene.text.Font;
import javafx.ext.swing.*; import javafx.scene.layout.VBox; var v1 = ##"My Label"; var v2 = ##"Your Label"; var v3 = ##"Our Label"; var v4 = ##"Hello Button"; var v5 = ##"Goodbye Button"; Stage { title: "JavaFX Localization Test" width: 300 height: 300 visible: true scene: Scene { content: VBox { spacing:5 content: [ SwingLabel {height: 30 width: 250 text: v1}, SwingLabel {height: 30 width: 250 text: v2}, SwingLabel {height: 30 width: 250 text: v3}, SwingButton {height: 30 width: 250 text: v4}, SwingButton {height: 30 width: 250 text: v5} ] } } } ===================================================
2. Compile and execute it.
# javafxc test.fx # javafx test
OK, everything looks good so far.
3. Create an fxproperty file.
Let's localize the strings. Here you can see my test_ja.fxproperties. Note that I can embed Japanese characters directly in the file - no more encrypted escape sequences!
=================================================== "My Label" = "私のラベル" "Your Label" = "あなたのラベル" "Our Label" = "私たちのラベル" "Hello Button" = "こんにちはボタン" "Goodbye Button" = "さようならボタン" ===================================================
4. Execute it.
Wow, the application is already localized! However, the fonts are kind of ugly here...
I will cover how I can fix this problem in my next blog. Stay tuned
Posted by naoko
( Dec 12 2008, 05:30:45 PM PST )
Permalink
Comments [6]
Today's Page Hits: 25