GettextForWesnothDevelopers

From The Battle for Wesnoth Wiki
Revision as of 14:35, 22 February 2017 by GunChleoc (talk | contribs) (Cleanup)

This page is used to help Wesnoth developers to work with the internationalization (i18n) system, based on GNU gettext.

Warning: some parts of this page are outdated.

How to move strings from one textdomain to another

  • run make -C po update-po and commit, to be sure to only commit your own changes
  • move the file into the corect po/*/POTFILES.in
  • add or change #define GETTEXT_DOMAIN "wesnoth-lib" at top of the file, before the includes
  • update the target POT file to include the new strings in its template (eg. make -C po/wesnoth-editor

wesnoth-editor.pot-update)

  • copy the translations using utils/po2po (eg. ./utils/po2po wesnoth wesnoth-editor)
  • update the source POT file to get rid of the old strings (eg. make -C po/wesnoth update-po), then preferably

remove the translation from obsolete strings in all languages, to make sure, in case the strings have to move back, that any translation update gets used instead of the current one)

  • check cvs diff and commit

General design of gettext use

Gettextized programs usually contain the English strings within the source code, with calls like printf (_("Hello world."));, so that the binary can work (in English) when the system does not support i18n. However, in Wesnoth, all strings were moved into translations/english.cfg, and fetched using a label, like in translate_string("hello_world");.

So we will need to put such strings (mostly GUI material) back into the C++ files. That part will be quite easy, except we'll have to deal with importing existing translations. We will use the wesnoth text domain for this (that is, a single wesnoth.po file for each language).

The general idea for strings in WML files is to use distinct text domains for each campaign, so that campaign writers can easily ship translations together with their campaigns. It will require WML files to declare which text domain they belong to.

If some strings look the same in English but should not necessarily look identical in translations (eg. all those prefix/suffix strings, many of which are empty in English). To hande this, those strings can be prefixed with any descriptive string and a ^ character, thanks to the sgettext implementation partly stolen from the gettext manual (eg. foo_prefix = _ "foo prefix^")

For i18n and Translation Managers

How to prepare translation updates for being committed

To ensure that the diffs the version-control system generates are usable and that the po files are actually compilable, it is recommended that i18n and translation managers follow these steps before committing translation updates.

Note that this guide assumes that you are using a Unix-like system and the CMake build system.

1. Run dos2unix on all of the updated po files.

2. Run "make po-update-<locale>" to ensure the updated po files are in sync with their corresponding pot files and to fix the line wrapping.

3. Run "make mo-update-<locale>" to ensure that the updated po files are compilable.

How to update the translation catalogs

Running a .pot update with CMake is documented in Releasing Wesnoth -> General Maintenance.

If you are using scons, run scons pot-update instead.

See Also