Nifty ResourceBundle

Hi there,



I’ve some problems using the ResourceBundle and nifty gui.

I included the resourceBundle-tag ([xml]<resourceBundle id="" filename="" />[/xml]) into my nifty-xml-file, but I cannot change the ResourceBundle-Content at runtime.

Actually I did not find out whats behind the usage of ResourceBundle in the nifty class. The field resourceBundleSource in the class Nifty seems not to be used at all. There is a setLocale and a addResourceBundle method, please what ?



Maybe someone has any experience with that and can help me :slight_smile:

It should be covered in:

http://freefr.dl.sourceforge.net/project/nifty-gui/nifty-gui/nifty-gui-the-manual-v1.0.pdf

Thanks for the hint but the manual was no help.



My modest solution looks as follows:



[java]@NiftyEventSubscriber(id="language_selection")

public void onRadioGroup1Changed(final String id, final RadioButtonGroupStateChangedEvent event) {

nifty.setLocale(new Locale(event.getSelectedId()));

nifty.addResourceBundle("lang", "Interface/languages/lang");



for (String screenID : nifty.getAllScreensName()) {

Screen screen = nifty.getScreen(screenID);

updateTextElements(screen.getRootElement(), "lang");

screen.layoutLayers();

}

}[/java]



I set a new locale and resource bundle to the nifty instance.

The id of the selected button is the corresponding locale.



Unfortunately I found no other possibility than going through all elements and setting the corresponding bundle command after setting the new bundle.



[java]private void updateTextElements(Element element, String bundleSelector) {

if (element == null)

return;



String id = element.getId();

TextRenderer renderer = element.getRenderer(TextRenderer.class);



// all text elements we want to be changed start with the § symbol followed by the resource bundle key

if (id != null && id.startsWith("§") && renderer != null) {

renderer.setText("${" + bundleSelector + "." + id.substring(1, id.length()) + "}");

}



// update all child elements

for (Element child : element.getElements()) {

updateTextElements(child, bundleSelector);

}

}[/java]

This isn’t actually something I’ve tried, @void256 might be able to help more.