Differences between revisions 1 and 2
Revision 1 as of 2008-02-20 09:35:17
Size: 1800
Comment:
Revision 2 as of 2010-03-17 13:12:45
Size: 1807
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 9: Line 9:
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 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
Line 24: Line 24:
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 ]. 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 ]].

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 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)