setText won't apply localization

I’m changing a button’s behavior depending on certain factors and when I try to set its localization it’s not working.

If I use:

[java]this.screen.findControl(“mnuGenGalaxy”, ButtonControl.class).setText("${dialog.resumeGame}");[/java]

I get the button but its text is → ${dialog.resumeGame} ← instead of the localized resumeGame. To test it, I copy/pasted the ${dialog.resumeGame} value in a button that isn’t changed and it is correctly localized (the localization does work), making me come to the conclusion that if the localization is not there at creation, it won’t be correctly localized if changed after the fact.

I had the same result when creating a button dynamically. Either using set(“label”, “${dialog.resumeGame}”) or setText(…) yielded the same result.

Anyone can confirm?

Why exactly do you expect the text to be replaced? This isnot a form of localization thats familiar to me, but maybe I am missing something here…

When the game starts, that button is used to generate a galaxy but once the game is started I recycle it this way: When in-game, if you hit ESC, it’ll bring back the same menu at the start, except I use the “Generate a galaxy”, change it’s name to “Resume Game” and assign it a different method.

Now, everything works as it should, that’s no problem. It’s only the localization that doesn’t work.

As you might know, by using ${xxxxx.yyyyy} (where xxxxx is a file name and yyyyy is a key), nifty will “translate” the key found in the file. In my case, there’s no “translation” at all. As I said above, all that is on the button is ${dialog.resumeGame}.

The special mark up is currently only applied when the XML is loaded. There is no automatic translation happening when changeing text.

You could use SpecialValuesReplace.replace() as a workaround and give this method all registered ResourceBundles that Nifty keeps: nifty.getResourceBundles().

@Normen: It’s described in the Nifty wiki under Markup.

1 Like

Ah thanks for the reply void!

Any plan to have that “fixed” in 1.3?

Added as a feature request to the Nifty Feature tracker and scheduled for Nifty 1.3 :wink:

1 Like

Thank you kind sir! :wink:

It’s much appreciated!