09.04.2018 Views

tornadofx-guide

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Internationalization<br />

You can add a global set of messages with the base name Messages (for example<br />

Messages_en.properties ) at the root of the class path.<br />

Automatic lookup in parent bundle<br />

When a key is not found in the component bundle, or when there is no bundle for the<br />

currrent component, the global resource bundle is consulted. As such, you might use the<br />

global bundle for all resources, and place overrides in the per component bundle.<br />

Friendly error messages<br />

In stead of throwing an exception when a key is not available in your bundle, the value will<br />

simply be [key] . This makes it easy to spot your errors, and your UI is still fully functional<br />

while you add the missing keys.<br />

Configuring the locale<br />

The default locale is the one retrieved from Locale.getDefault() . You can configure a<br />

different locale by issuing:<br />

FX.locale = Locale("my-locale")<br />

The global bundle will automatically be changed to the bundle corresponding to the new<br />

locale, and all subsequently loaded components will get their bundle in the new locale as<br />

well.<br />

Overriding resource bundles<br />

If you want to change the bundle for a component after it's been initialized, or if you simply<br />

want to load a spesific bundle without relying on the conventions, simply assign the new<br />

bundle to the messages property of the component.<br />

If you want to use the overriden resource bundle to load FXML , make sure you change the<br />

bundle before you load the root view:<br />

class MyView: View() {<br />

init { messages = ResourceBundle.getBundle("MyCustomBundle") }<br />

override val root = HBox by fxml()<br />

}<br />

251

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!