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 :)</p>

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

Example:

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

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>
    </ul>
    If for some reason the replacement does not work out then nothing is replaced and you'll get the original ${...} String back.</p>

    Localization Details</strong></p>

    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</p>

    dialog_de.properties:
    hello = Hallo Welt in Deutsch

    dialog_en.properties:
    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></p>
    
    </pre></p>
    

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

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

    Nifty stuff and Kudos goes out to lynorics! :D

    void