I have a small application that I develop and I am distributing; now I would like to add i18n support to it with gettext. I see that gettext requires running several commands and generating various files (and updating them when new strings are included in the source code).
What is the usual way to have gettext interact with a typical git workflow? Should I generate my .pot
file myself and include it in the repository, or should it be generated automatically at build time by my Makefile? What about .mo
files? Similarly, do I need to include msgmerge
in my build script, or do I just add its result to the version-controlled files?
I am using C++, a hand-written Makefile (no automake) and github, in case it matters.
Three types of files are involved here, and all of them are generated, at least kind of.
The .pot
PO Template file that contains the master message catalog. This is under version control in every project I know although it is strictly spoken generated and redundant.
The .po
files with the individual translations. They are sometimes generated, sometimes not. When you merge in new strings with msgmerge
, they are generated. But when your translators send back a new translation, they are not. You have to put them under version control because they contain the translations.
The .mo
files that the .po
files compile to. Do not put them under version control but ship them with releases (source and binary).
More important is the logic in your Makefile. None of the above mentioned files should be generated automatically but only on demand. Otherwise your po/
directory will be dirty, whenever you edit a source file.
IMHO it is best practice to ensure that a git clone can be built without having the gettext tools (xgettext, msgmerge, msgfmt) installed. Make sure that they are only invoked on demand.
The Perl binding for gettext libint-perl (disclaimer: I am the author) contains a sample po directory with a complete Makefile: https://github.com/gflohr/libintl-perl/tree/master/sample/simplecal/po. You can probably use that Makefile directly in your project. You only have to modify the xgettext
invocation for the programming language of your choice.