• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaFx internationalization

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm looking to do some internationalization in my working example of javafx.
I've looked in the internet and i found no valuable information how to do this.
I'm using a resource bundle but i don´t no how to update the rendered elements in the window to the new resource bundle.

Here's my example code:


the bundles are


and



How can i refresh all the elements in my scene to get the new value from bundle
when i press one of the language buttons.

Anyone can help me in that?
Thankx in advance
 
Rancher
Posts: 387
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your components are defined in code rather than fxml you will currently (with JavaFX 2.2) need to create the infrastructure yourself.

Quick algorithm off the top of my head:
1. assign an id to each labeled or text node (setId).
2. use the text key strings in your resource bundle which match your node id.
3. create a resourcebundle property on your scene.
4. attach a resourcebundle property ChangeListener.
5. when the resourcebundle for the scene changes:
a. iterate through all your text keys from the resource bundle.
b. invoke the node.lookup(textKeyId) function for each text key.
c. call node.setText(rb.getString(textKeyId)).

If you use fxml, see here for info on how to hook up resources:
http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html#resource_resolution

If you use SceneBuilder, follow this guide to internationalize your app:
http://docs.oracle.com/javafx/scenebuilder/1/user_guide/i18n-support.htm

Also, see the example in this stackoverflow question (also an fxml variant):
http://stackoverflow.com/questions/10143392/javafx-2-and-internationalization
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic