1 # dgit message translation machinery
3 # Translators: there is no need to look at this file. It contains
4 # complicated machinery which you do not need to understand :-).
5 # See po/README instead.
7 # Copyright (C)2018 Ian Jackson
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # ----- metaprogramming (translators, pleaee ignore all this) -----
24 # We present translators with a single file po/messages.pot containing
25 # all the messages for the translated programs in dgit.deb and
26 # git-debrebase.deb. This also includes the messages from the shared
29 # But when we make the .debs, we want to ship in each .deb the
30 # messages for that .deb, only (but including the common parts).
32 # So we generate three intermediate .pots,
33 # .{dgit,git-debrebase,common}.pot
34 # and merge them to make messages.pot.
36 # From the translations we generate two .mo files for each output
37 # language: {dgit,git-debrebase}.mo -- including the common messages.
39 # To avoid dirtying the tree whenever we do `make install',
40 # we honour SUPPRESS_PO_UPDATE, to be used like this
41 # make install prefix=$(prefix) SUPPRESS_PO_UPDATE=1
43 all: messages.pot mofiles
45 include ../i18n-common.make
51 $S $e; find ../Debian -name \*.pm; $f
53 .%.make: .%.potfiles Makefile part.make
55 sed 's/~/$*/g' part.make; \
56 sed "s#^#.$*.pot: #" $<; \
60 -include .git-debrebase.make
63 POFILES := $(wildcard *.po)
64 LANGS := $(basename $(POFILES))
66 MOFILES = $(foreach part,$(filter-out common,$(PARTS)), \
67 $(addprefix mo/$(part)_, $(POFILES:.po=.mo)))
69 messages.pot: $(if $(SUPPRESS_PO_UPDATE),,$(POTS))
70 $S msgcat --to-code=UTF-8 $^ >.messages.0.tmp
71 $S ( ./remove-potcdate <$@ ||: ) >.messages.1.tmp
72 $S ./remove-potcdate <.messages.0.tmp >.messages.2.tmp
73 $S cmp -s .messages.[12].tmp || mv -v .messages.0.tmp $@
79 XGETTEXT_OPTS += -Lperl -k__ -kf_ -ki_
80 XGETTEXT_OPTS += --from-code=UTF-8
81 XGETTEXT_OPTS += --package-name=dgit --package-version=ongoing
82 # The --package-* avoids this error from make check's `msgfmt -c'
83 # warning: header field 'Project-Id-Version' still has the initial default value
86 $S TZ=UTC xgettext $(XGETTEXT_OPTS) $^ -o $@.tmp && $f
89 @echo 'Generated mo/*.mo (binary translated messages) OK.'
92 set -e; for file in $(MOFILES); do \
93 lang=$${file#*_}; lang=$${lang%.mo}; \
94 part=$${file#mo/}; part=$${part%%_*}; \
95 d=$(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES; \
97 install -m 0644 $$file $$d/$$part.mo; \
101 rm -f .*.make .*.potfiles .*.pot .*.tmp
104 %.po: $(if $(SUPPRESS_PO_UPDATE),,messages.pot)
105 @echo -n "Merging messages.pot and $@ "
106 $S if test -f $@; then \
107 msgmerge --previous $@ messages.pot -o $@.new; \
109 msgcat --lang=$* messages.pot >$@.new; \
112 $S msgfmt -o /dev/null --statistics $@
114 .PRECIOUS: .%.potfiles
118 update: pofiles check
120 check: $(if $(SUPPRESS_PO_UPDATE),,pofiles)
121 $S set -e; for file in $(POFILES); do \
122 lang=`echo $$file | sed 's/\.po//'`; \
124 msgfmt -o /dev/null -c -v --statistics $$lang.po;\