chiark / gitweb /
i18n: po: Rename `all-po' target to `pofiles'
[dgit.git] / po / Makefile
index e5b4bc8447e9ed98bf7bf8af322b18bdeb43dcc3..0053f522275b254eb2d17e22fd3ffacbd5aea118 100644 (file)
-# List here all source files with translatable strings.
-POTFILES=$(sort $(shell find ../Debconf -type f -name \*.pm)) \
-       ../dpkg-* ../debconf-* ../debconf
+# dgit message translation machinery
+#
+# Translators: there is no need to look at this file.  It contains
+# complicated machinery which you do not need to understand :-).
+# See po/README instead.
 
-POFILES=$(wildcard *.po)
-MOFILES=$(POFILES:.po=.mo)
+# Copyright (C)2018 Ian Jackson
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-all: debconf.pot $(MOFILES)
+# ----- metaprogramming (translators, pleaee ignore all this) -----
+#
+# We present translators with a single file po/messages.pot containing
+# all the messages for the translated programs in dgit.deb and
+# git-debrebase.deb.  This also includes the messages from the shared
+# perl modules.
+#
+# But when we make the .debs, we want to ship in each .deb the
+# messages for that .deb, only (but including the common parts).
+#
+# So we generate three intermediate .pots,
+#   .{dgit,git-debrebase,common}.pot
+# and merge them to make messages.pot.
+#
+# From the translations we generate two .mo files for each output
+# language: {dgit,git-debrebase}.mo -- including the common messages.
+#
+# To avoid dirtying the tree whenever we do `make install',
+# we honour SUPPRESS_PO_UPDATE, to be used like this
+#   make install prefix=$(prefix) SUPPRESS_PO_UPDATE=1
+
+all: messages.pot mofiles
+
+include ../i18n-common.make
+
+.%.potfiles:
+       $S $e; echo ../$*; $f
+
+.common.potfiles:
+       $S $e; find ../Debian -name \*.pm; $f
+
+.%.make: .%.potfiles Makefile part.make
+       $S $e; \
+        sed 's/~/$*/g' part.make; \
+        sed "s#^#.$*.pot: #" $<; \
+       $f
+
+-include .dgit.make
+-include .git-debrebase.make
+-include .common.make
+
+POFILES := $(wildcard *.po)
+LANGS := $(basename $(POFILES))
+
+MOFILES = $(foreach part,$(filter-out common,$(PARTS)), \
+       $(addprefix mo/$(part)_, $(POFILES:.po=.mo)))
+
+messages.pot: $(if $(SUPPRESS_PO_UPDATE),,$(POTS))
+       $S msgcat --to-code=UTF-8 $^            >.messages.0.tmp
+       $S ( ./remove-potcdate <$@ ||: )        >.messages.1.tmp
+       $S ./remove-potcdate <.messages.0.tmp   >.messages.2.tmp
+       $S cmp -s .messages.[12].tmp || mv -v .messages.0.tmp $@
+       @echo 'Updated $@.'
+
+%.mo: %.po
+       $S msgfmt -o $@ $<
+
+XGETTEXT_OPTS += -Lperl -k__ -kf_ -ki_
+XGETTEXT_OPTS += --from-code=UTF-8
+XGETTEXT_OPTS += --package-name=dgit --package-version=ongoing
+# The --package-* avoids this error from make check's `msgfmt -c'
+#  warning: header field 'Project-Id-Version' still has the initial default value
+
+%.pot:
+       $S TZ=UTC xgettext $(XGETTEXT_OPTS) $^ -o $@.tmp && $f
+
+mofiles: $(MOFILES)
+       @echo 'Generated mo/*.mo (binary translated messages) OK.'
 
 install: all
-       for file in $(MOFILES); do \
-               lang=`echo $$file | sed 's/\.mo//'`; \
-               install -d $(prefix)/usr/share/locale/$$lang/LC_MESSAGES/; \
-               install -m 0644 $$file $(prefix)/usr/share/locale/$$lang/LC_MESSAGES/debconf.mo; \
+       set -e; for file in $(MOFILES); do \
+               lang=$${file#*_}; lang=$${lang%.mo}; \
+               part=$${file#mo/}; part=$${part%%_*}; \
+               d=$(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES; \
+               install -d $$d; \
+               install -m 0644 $$file $$d/$$part.mo; \
        done
 
-debconf.pot: $(POTFILES)
-       @echo "Rebuilding the pot file"
-       TZ=UTC xgettext $(POTFILES) -o debconf.pot.new -Lperl
-       if [ -f debconf.pot ]; then \
-               ./remove-potcdate.pl < debconf.pot > debconf.1po && \
-               ./remove-potcdate.pl < debconf.pot.new > debconf.2po && \
-               if cmp debconf.1po debconf.2po >/dev/null 2>&1; then \
-                       rm -f debconf.1po debconf.2po debconf.pot.new; \
-               else \
-                       rm -f debconf.1po debconf.2po && \
-                       mv debconf.pot.new debconf.pot; \
-               fi; \
+clean:
+       rm -f .*.make .*.potfiles .*.pot .*.tmp
+       rm -rf mo
+
+%.po: $(if $(SUPPRESS_PO_UPDATE),,messages.pot)
+       @echo -n "Merging messages.pot and $@ "
+       $S if test -f $@; then \
+               msgmerge --previous $@ messages.pot -o $@.new; \
        else \
-               mv debconf.pot.new debconf.pot; \
+               msgcat --lang=$* messages.pot >$@.new; \
        fi
+       $S mv -f $@.new $@
+       $S msgfmt -o /dev/null --statistics $@
 
-clean:
-       rm -f $(MOFILES) debconf.pot.new messages messages.mo
-
-%.mo: %.po
-       msgfmt -o $@ $<
+.PRECIOUS: .%.potfiles
 
-%.po: debconf.pot
-       @echo -n "Merging debconf.pot and $@"
-       @msgmerge --previous $@ debconf.pot -o $@.new
-       @mv -f $@.new $@
-       @msgfmt --statistics $@
+pofiles: $(POFILES)
 
-check:
-       @for file in $(POFILES); do \
+check: $(if $(SUPPRESS_PO_UPDATE),,pofiles)
+       $S set -e; for file in $(POFILES); do \
                lang=`echo $$file | sed 's/\.po//'`; \
                printf "$$lang: "; \
                msgfmt -o /dev/null -c -v --statistics $$lang.po;\