Open flysoftsystems opened 8 years ago
Hello, I can't understand how can I set the locale of resourceBundle used by the views, and if it's possible to change it at runtime. Can you suggest me a way to do it pleese?
Thanks in advance for your help, Matteo
Hi Matteo,
until now I haven't gotten a reply from Adem Bien. But Peter Rogge who is responsible for the Netbeans AfterburnerFX plugin gave me a good hint how to implement this. You have to understand that currently AfterburnerFX doesn't support customized Locale inserts during the creation of a view. Instead the view fetches the Locale from Locale.getDefault() automatically during instantiation.
Consequently you need to Locale.setDefault(Locale.setDefault(customLocale);
MyView view = new MyView();
Locale.setDefault(standardLocale);
Moreover with FXML loading of resourceBundles switching resourceBundle on the flyis not possible. If you want your Scene to be shown with a different Locale then you have to recreate the view based on the new Locale like this:
public void showMyView() {
// first initiation
if (myStage == null) {
myStage = new Stage();
Locale.setDefault(userLocale);
view = new MyView();
Locale.setDefault(standardLocale);
Scene scene = new Scene(view.getView());
myStage.setScene(scene);
// after first time init checking whether Locale has changed
} else {
if (view.getRealPresenter().getLocale() != view.getResourceBundle().getLocale()) {
System.out.println("Locale has changed");
System.out.println("Old Locale is: " + view.getResourceBundle().getLocale());
System.out.println("New Locale is: " + view.getRealPresenter().getLocale());
// recreating view after Locale has changed
Locale.setDefault(view.getRealPresenter().getLocale());
view = new MyView();
Locale.setDefault(standardLocale);
Scene scene = new Scene(view.getView());
myStage.setScene(scene);
}
}
myStage.showAndWait();
}
Hi, I'm having trouble to implement the internationalization system in an efficient way with the afterburner. My application has multiple views, and i want to put
language_en.properties
and
language_it.properties
files in Other sources Package. Anyone can provide an exemple ?
hi there. For afterburnerFX one has to keep View, Presenter and all its language property files within the same package. Since afterburnerFX runs as "Convention over Configuration", one has to follow its naming conventions. For example:
So if you want to create a new view called "home", then you need to create a package called "home", presenter called "HomePresenter", view called "HomeView", fxml called home.fxml etc. In case your IDE is Netbeans you can make use of an excellent plugin by Peter Rogge called Netbeans Afterburnerfx plugin, to be found here: link; it will help you create these files automatically once you.
Be advised that all files related to transfer must be located within the transfer package! Cheers, Mate
Hi Adam,
I really appreciate your work with this small but very relevant DI plugin. I am working with internationalized strings both with Netbeans 8.1 and SceneBuilder. My app has many users and each user would want the Views display in his native language, but I don't know how to attach user-specific Locales to ResourceBundles which in turn can be injected into the Views.
With the standard javafx, I could change the language like this:
Is there an option to set resources within the View or any other solution would be greatly appreciated!
Thank you for your time, Cheng