Internationalisation

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 [http://hera.statsbiblioteket.dk/cgi-bin/viewcvs.cgi/sbutil/src/dk/statsbiblioteket/util/i18n/Translator.java?rev=HEAD&content-type=text/vnd.viewcvs-markup Translator] in [:SBUtil: 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 [http://hera.statsbiblioteket.dk/cgi-bin/viewcvs.cgi/sbutil/test/dk/ example message bundles in the sbutil test directory], and examples of how to use them in the [http://hera.statsbiblioteket.dk/cgi-bin/viewcvs.cgi/sbutil/test/dk/statsbiblioteket/util/I18nTest.java?rev=HEAD&content-type=text/vnd.viewcvs-markupunit 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.