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 e=set -e; exec >$@.tmp
50 # Set S='' to see commands being run
56 $S $e; find ../Debian -name \*.pm; $f
58 .%.make: .%.potfiles Makefile part.make
60 sed 's/~/$*/g' part.make; \
61 sed "s#^#.$*.pot: #" $<; \
64 # echo 'MOS_$$(addsuffix'
65 # find -name $*.mo |sed ; $f
68 -include .git-debrebase.make
71 POFILES := $(wildcard *.po)
72 LANGS := $(basename $(POFILES))
74 MOFILES = $(foreach part,$(filter-out common,$(PARTS)), \
75 $(addprefix mo/$(part)_, $(POFILES:.po=.mo)))
77 messages.pot: $(if $(SUPPRESS_PO_UPDATE),,$(POTS))
78 $S msgcat --to-code=UTF-8 $^ >.messages.0.tmp
79 $S ( ./remove-potcdate <$@ ||: ) >.messages.1.tmp
80 $S ./remove-potcdate <.messages.0.tmp >.messages.2.tmp
81 $S cmp -s .messages.[12].tmp || mv -v .messages.0.tmp $@
87 XGETTEXT_OPTS += -Lperl -k__ -kf_
88 XGETTEXT_OPTS += --from-code=UTF-8
89 XGETTEXT_OPTS += --package-name=dgit --package-version=ongoing
90 # The --package-* avoids this error from make check's `msgfmt -c'
91 # warning: header field 'Project-Id-Version' still has the initial default value
94 $S TZ=UTC xgettext $(XGETTEXT_OPTS) $^ -o $@.tmp && $f
97 @echo 'Generated mo/*.mo (binary translated messages) OK.'
100 set -e; for file in $(MOFILES); do \
101 lang=$${file#*_}; lang=$${lang%.mo}; \
102 part=$${file#mo/}; part=$${part%%_*}; \
103 d=$(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES; \
105 install -m 0644 $$file $$d/$$part.mo; \
109 rm -f .*.make .*.potfiles .*.pot .*.tmp
112 %.po: $(if $(SUPPRESS_PO_UPDATE),,messages.pot)
113 @echo -n "Merging messages.pot and $@ "
114 $S if test -f $@; then \
115 msgmerge --previous $@ messages.pot -o $@.new; \
117 msgcat --lang=$* messages.pot >$@.new; \
120 $S msgfmt -o /dev/null --statistics $@
122 .PRECIOUS: .%.potfiles
126 check: $(if $(SUPPRESS_PO_UPDATE),,all-po)
127 $S set -e; for file in $(POFILES); do \
128 lang=`echo $$file | sed 's/\.po//'`; \
130 msgfmt -o /dev/null -c -v --statistics $$lang.po;\