Difference between revisions of "GettextForWesnothDevelopers"

From The Battle for Wesnoth Wiki
(Some pre-mutilation cleanup)
(General design of gettext use)
Line 25: Line 25:
 
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.
 
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^"'')
+
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^"'')
  
 
== See Also ==
 
== See Also ==

Revision as of 20:55, 6 July 2012

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

Warning: this page still contains a couple of outdated items to be removed.

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

See Also