Natural Language Support¶
BOUT++ uses GNU gettext. to
provide translations of output strings. Configuration is described in
Natural Language Support and running in Natural language support. Currently
only fr
, zh_TW
, and zh_CN
have been added, but it is quite
easy to add more. See locale/README.md
or below.
Marking strings for translation¶
In the code strings are wrapped with _()
e.g. "hello world"
becomes _("hello world")
. Find a string you want to replace (which
can include formatting like %d
), surround it with _()
. Then in
the locale directory:
make libbout.pot
will update the template file libbout.pot
under
BOUT_TOP/locale
. The template file should not be edited, but is
used to generate language-specific files (libbout.po
).
To update these language files see the next section.
Adding translations¶
Adding support for a new language, or improving the translations in the existing files can be done by:
Going to the
locale
BOUT++ subdirectory and running:make locale-ll
where
ll
is the language code e.g.make locale-zh_TW
ormake locale-de
. This will create a filelibbout.po
under alocale/ll
subdirectory.Edit the
locale/ll/libbout.po
file. Edit the .po file in de subdirectory (not the .pot file!), adding the translations. Eachmsgid
entry should have a translatedmsgstr
entry. If you don’t want to translate them all, just delete the ones you don’t translate. Any missing will just revert to the version in the code. If you’re adding UTF-8 characters, change the content line in the .po file to have charset=UTF-8.In the
locale
directory runmake
. This should output something like:Building language: fr Building language: zh_CN Building language: zh_TW
The new language should now be available (no need to recompile BOUT++).