Localization support and some more cool stuff!
// June 19th, 2010 // Uncategorized
A feature request made Nifty user lynorics create a patch that solved the issue and it directly point to solve the localization feature request too
Every attribute of every Nifty element can now contain a special markup “${…}” that gets replaced with something else when the xml is loaded.
Example:
<text text="your home directory: ${ENV.HOME}" />
The “${ENV.HOME}” will be replaced with your $HOME environment variable!
You have the following options now to use this new feature:
- ${id.key} lookup resource bundle with “id” and request “key” from it. This is explained in more detail below.
- ${ENV.key} lookup “key” in the environment variables (System.getEnv()) and replace ${ENV.key} with the value received.
- ${PROP.key} lookup “key” in the new Nifty.setGlobalProperties(Properties) properties or if the properties are not set this will use System.getProperties() to lookup “key”
- ${CALL.method()} call method() at the current ScreenController and it is replaced with the value that method() returns. method() should return a String in this case.
If for some reason the replacement does not work out then nothing is replaced and you’ll get the original ${…} String back.
Localization Details
Currently Nifty Localization is using standard Property file based Resourcebundles. This simply means you can create a property file containing keys that are referenced from the xml files.
Example:
dialog.properties: hello = Hello World in Default Language dialog_de.properties: hello = Hallo Welt in Deutsch dialog_en.properties: hello = hello world in english
Once you have created these files you need to register the resourceBundle “dialog” with Nifty so that Nifty knows that it exists. You can do that with the new “resourceBundle” tag:
<resourceBundle id="dialog" filename="src/main/resources/dialog" />
Now that Nifty knows about your resourceBundle you can access it with the method mentioned above:
<text text="${dialog.hello}" />
Now Nifty will use the current set default locale to access the ResourceBundle with the id “dialog” and looks up the value for “hello”. If you don’t like that Nifty uses the default Locale you can set the Locale that Nifty should use with the “nifty.setLocale(Locale)” method.
Nifty stuff and Kudos goes out to lynorics!
void




Good work.
I am going to rework my multi-lang menu to be done in proper way.
Grrr. Hurray!
Very nice!
I just started converting our game to use Nifty instead of GBUI and having done some Android work lately, this was just what I was looking for!
Thank you very much!
Unfortunately, Nifty GUI do not support Chinese.
why? why is this?
ever tried a chinese font?
I try to use Chinese in Nifty but there are many problems to show Chinese rightly.
I generate a Chinese font for myself by using BMFont tool
Can you post some screenshots or describe the problems you had in the sf.net help forum for nifty: https://sourceforge.net/projects/nifty-gui/forums/forum/807893
I’d like to know the problems you’ve encountered. Not sure if I could help but I’d like to know the problems at least =)
Nifty GUI with Chinese problems
1) When the font of text field is Chinese, then you cannot input for the text field.
2) When integrate with jME, cannot show Chinese rightly, just can show the words in the first page of the font.