bio photo

A feature request</a> made Nifty user lynorics</a> create a patch that solved the issue and it directly point to solve the localization feature request</a> too :)

Every attribute of every Nifty element can now contain a special markup "${...}"</strong> that gets replaced with something else when the xml is loaded.


<text text="your home directory: ${ENV.HOME}" /></pre>
The "${ENV.HOME}" will be replaced with your $HOME environment variable! :D

You have the following options now to use this new feature:

  • ${id.key}</strong> lookup resource bundle with "id" and request "key" from it. This is explained in more detail below.</li>
  • ${ENV.key}</strong> lookup "key" in the environment variables (System.getEnv()) and replace ${ENV.key} with the value received.</li>
  • ${PROP.key}</strong> lookup "key" in the new Nifty.setGlobalProperties(Properties) properties or if the properties are not set this will use System.getProperties() to lookup "key"</li>
  • ${CALL.method()}</strong> call method() at the current ScreenController and it is replaced with the value that method() returns. method() should return a String in this case.</li>
    If for some reason the replacement does not work out then nothing is replaced and you'll get the original ${...} String back.

    Localization Details</strong>

    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.

    hello = Hello World in Default Language
    hello = Hallo Welt in Deutsch
    hello = hello world in english</pre>
    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" /></pre>

    Now that Nifty knows about your resourceBundle you can access it with the method mentioned above:

    <text text="${dialog.hello}" /></pre>
    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! :D