Provides classes for internationalization (i18n).
To make use of internationalization a programmer should follow these basic steps:
Wrap all text messages intended for translation with one of the tr* methods provided in the class I18n. Make sure the arguments to tr* only contain pure text messages and no String variables or the string concatenation operator +.
Add a rule to your build environment in order to extract the text
messages using xgettext
. For Makefiles this could look like
this:
extract-keys: xgettext --from-code=UTF-8 -ktrc -ktr -kmarktr \ `find . -name "*.java"` -o po/keys.pot
Give the generated keys.pot
to your translators and store
the translated files as [country code].po
in the
po
directory alongside the
keys.pot
file.
If there are already translated po files, use xgettext's
msgmerge
facility
to update the translated files with the new keys and give those to the
tranlators. A sample Makefile rule for merging:
merge-keys: extract-keys for i in `find po -type f -name "*.po"`; do \ msgmerge --backup=numbered -U $$i po/keys.pot; \ done
Java properties files can be generated using a rule like:
i18n-dist: for i in `find po -type f -name "*.po"`; do \ f=src/resources/programname_`basename $$i | sed -e 's/po/properties/'`; \ msgcat -p $$i -o $$f || true; \ done