chiark / gitweb /
i18n: Break out i18n-common.make (nfc)
[dgit.git] / po / Makefile
1 # dgit message translation machinery
2 #
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.
6
7 # Copyright (C)2018 Ian Jackson
8 #
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.
13 #
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.
18 #
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/>.
21
22 # ----- metaprogramming (translators, pleaee ignore all this) -----
23 #
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
27 # perl modules.
28 #
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).
31 #
32 # So we generate three intermediate .pots,
33 #   .{dgit,git-debrebase,common}.pot
34 # and merge them to make messages.pot.
35 #
36 # From the translations we generate two .mo files for each output
37 # language: {dgit,git-debrebase}.mo -- including the common messages.
38 #
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
42
43 all: messages.pot mofiles
44
45 include ../i18n-common.make
46
47 .%.potfiles:
48         $S $e; echo ../$*; $f
49
50 .common.potfiles:
51         $S $e; find ../Debian -name \*.pm; $f
52
53 .%.make: .%.potfiles Makefile part.make
54         $S $e; \
55          sed 's/~/$*/g' part.make; \
56          sed "s#^#.$*.pot: #" $<; \
57         $f
58
59 #        echo 'MOS_$$(addsuffix'
60 #        find -name $*.mo |sed ; $f
61
62 -include .dgit.make
63 -include .git-debrebase.make
64 -include .common.make
65
66 POFILES := $(wildcard *.po)
67 LANGS := $(basename $(POFILES))
68
69 MOFILES = $(foreach part,$(filter-out common,$(PARTS)), \
70         $(addprefix mo/$(part)_, $(POFILES:.po=.mo)))
71
72 messages.pot: $(if $(SUPPRESS_PO_UPDATE),,$(POTS))
73         $S msgcat --to-code=UTF-8 $^            >.messages.0.tmp
74         $S ( ./remove-potcdate <$@ ||: )        >.messages.1.tmp
75         $S ./remove-potcdate <.messages.0.tmp   >.messages.2.tmp
76         $S cmp -s .messages.[12].tmp || mv -v .messages.0.tmp $@
77         @echo 'Updated $@.'
78
79 %.mo: %.po
80         $S msgfmt -o $@ $<
81
82 XGETTEXT_OPTS += -Lperl -k__ -kf_ -ki_
83 XGETTEXT_OPTS += --from-code=UTF-8
84 XGETTEXT_OPTS += --package-name=dgit --package-version=ongoing
85 # The --package-* avoids this error from make check's `msgfmt -c'
86 #  warning: header field 'Project-Id-Version' still has the initial default value
87
88 %.pot:
89         $S TZ=UTC xgettext $(XGETTEXT_OPTS) $^ -o $@.tmp && $f
90
91 mofiles: $(MOFILES)
92         @echo 'Generated mo/*.mo (binary translated messages) OK.'
93
94 install: all
95         set -e; for file in $(MOFILES); do \
96                 lang=$${file#*_}; lang=$${lang%.mo}; \
97                 part=$${file#mo/}; part=$${part%%_*}; \
98                 d=$(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES; \
99                 install -d $$d; \
100                 install -m 0644 $$file $$d/$$part.mo; \
101         done
102
103 clean:
104         rm -f .*.make .*.potfiles .*.pot .*.tmp
105         rm -rf mo
106
107 %.po: $(if $(SUPPRESS_PO_UPDATE),,messages.pot)
108         @echo -n "Merging messages.pot and $@ "
109         $S if test -f $@; then \
110                 msgmerge --previous $@ messages.pot -o $@.new; \
111         else \
112                 msgcat --lang=$* messages.pot >$@.new; \
113         fi
114         $S mv -f $@.new $@
115         $S msgfmt -o /dev/null --statistics $@
116
117 .PRECIOUS: .%.potfiles
118
119 all-po: $(POFILES)
120
121 check: $(if $(SUPPRESS_PO_UPDATE),,all-po)
122         $S set -e; for file in $(POFILES); do \
123                 lang=`echo $$file | sed 's/\.po//'`; \
124                 printf "$$lang: "; \
125                 msgfmt -o /dev/null -c -v --statistics $$lang.po;\
126         done