# $Id$ # # common rules for gettext handling. # # Defines the 'update-po' target for updating the translations and # the 'install-mo' target, which installs the translations into # $(prefix)/share/locale # # Creating an initial po/$(ARTIFACT).pot file is enabled by the target 'pot', # i.e. in some build directory call # # make pot # # Building a translation package is possible by calling # # make install-mo DESTDIR=`pwd`/debian/my-pkg-i18n # # Building a translation package for an individual language is possible by calling # # make install-mo LANGUAGES="de de_AT" DESTDIR=`pwd`/debian/my-pkg-i18n-de # # Variables: # # srcdir ... source directory. # SOURCES ... list of source packages to compile. # ARTIFACT ... name of the build artifact. # I18N_PFX ... prefix for $(I18N_PFX)_i18n and $(I18N_PFX)_i18n_n functions. Defaults to ARTIFACT, if not specified. # LANGUAGES ... list of languages for which a po/$(ARTIFACT)_$lang.po file exists. # # This snippet assumes, that your code translates messages using these functions: # # const char *$(I18N_PFX)_i18n(const char *msg) # const char *$(I18N_PFX)_i18n_c(const char *msg) // contextualized, everything up to the first '|' is interpreted as context # const char *$(I18N_PFX)_i18n_n(const char *msg, const char *plural_msg, long n) # QString qs_$(I18N_PFX)_i18n(const char *msg) # QString qs_$(I18N_PFX)_i18n_c(const char *msg) // contextualized, everything up to the first '|' is interpreted as context # POTFILE=$(srcdir)/po/$(ARTIFACT).pot POFILES=$(addprefix $(srcdir)/po/$(ARTIFACT)_, $(addsuffix .po, $(LANGUAGES))) UICSOURCES=$(addsuffix _uic.cpp,$(basename $(UICFILES))) POSOURCES=$(addprefix $(srcdir)/, $(SOURCES)) $(UICSOURCES) ifeq ($(I18N_PFX),) I18N_PFX=$(ARTIFACT) endif $(POTFILE): $(POSOURCES) mkdir -p $(srcdir)/po && xgettext --from-code=UTF-8 --keyword=$(I18N_PFX)_i18n --keyword=$(I18N_PFX)_i18n_c:1g --keyword=$(I18N_PFX)_i18n_n:1,2 --keyword=qs_$(I18N_PFX)_i18n --keyword=qs_$(I18N_PFX)_i18n_c:1g -D $(srcdir) -D . -o $(POTFILE) $(SOURCES) $(UICSOURCES) $(srcdir)/po/$(ARTIFACT)_%.po: $(POTFILE) if test -f $@; then msgmerge -U $@ $<; else msginit -l $*.UTF-8 -i $< -o $@; fi pot:: $(POTFILE) ifneq ($(LANGUAGES),) update-po:: $(POFILES) install-mo:: for lang in $(LANGUAGES); do mkdir -p $(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES; msgfmt -o $(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES/$(ARTIFACT).mo $(srcdir)/po/$(ARTIFACT)_$$lang.po; done endif