In general, internationalisation of the DOMS is to be done only for GUI's and feedback meant for non-programmers. The path of least resistance has been chosen.

Internationalisation is done with resource bundles in standard translation syntax. This method use key-value pairs for lookup.

Calling code

We a wrapper class called Translator in sbutil, so an internationalised piece of code might look like

        Translator i18n;
        return i18n.translate("found.0.birds", records.size());

and might return the Strings "Found 87 birds" and "87 fugle fundet", depending on locale.

If the phrase is not defined in the bundle, a warning is logged and the key is returned in a more readable form. In the example above, this would be "Found 0 birds", which demonstrates that this is just a last resort.

Keys are named roughly as the phrase in english, with only a-z, 0-9, dashes and dots. Spaces are replaced by dots, values by 0.

Implementing I18n in Projects

You can find example message bundles in the sbutil test directory, and examples of how to use them in the tests of the i18n package.

Note: One difference compared to the sbutil test cases is that it is encouraged to write the translation keys explicitly in the code, like in the example above. This makes for a more readable program.

i18n (last edited 2010-03-17 13:12:45 by localhost)