chiark / gitweb /
i18n: Machinery in po/
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Sep 2018 00:28:16 +0000 (01:28 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Sep 2018 11:41:03 +0000 (12:41 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
po/.gitignore [new file with mode: 0644]
po/Makefile
po/README [new file with mode: 0644]
po/part.make [new file with mode: 0644]
po/remove-potcdate [moved from po/remove-potcdate.pl with 100% similarity]

diff --git a/po/.gitignore b/po/.gitignore
new file mode 100644 (file)
index 0000000..9b9048d
--- /dev/null
@@ -0,0 +1,6 @@
+.*.make
+.*.potfiles
+.*.pot
+.*.tmp
+.*.new
+mo
index e5b4bc8447e9ed98bf7bf8af322b18bdeb43dcc3..4e043eb320c8079b26c2a892a9d94559b8a74193 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
+
+e=set -e; exec >$@.tmp
+f=mv -f $@.tmp $@
+o= >$@.tmp && $f
+
+S=@
+# Set S='' to see commands being run
+
+.%.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
+
+#       echo 'MOS_$$(addsuffix'
+#       find -name $*.mo |sed ; $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__ -k___
+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 $@
+all-po: $(POFILES)
 
-check:
-       @for file in $(POFILES); do \
+check: $(if $(SUPPRESS_PO_UPDATE),,all-po)
+       $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;\
diff --git a/po/README b/po/README
new file mode 100644 (file)
index 0000000..bb3824b
--- /dev/null
+++ b/po/README
@@ -0,0 +1,26 @@
+The dgit source package contains dgit and git-debrebase.
+
+Translation organisation:
+
+  po/messages.pot      all messages from both dgit and git-debrebase
+  po/LANG.po           translations of those
+  po/mo                        output directory, do not look here
+
+  po4a/                        documentation (TBD)
+
+Important make targets for translators.
+NB all of these are after "cd po/".
+
+  make <LANGUAGE>.po   Create <LANGUAGE>.po so you can start translating,
+                       or update messages.pot <LANGUAGE>.po.
+
+  make all-po          Updates messages.pot from all the sources,
+                       with new messages, and merges them into
+                       all the language-specific .po files
+
+  make check           Update everything and then check everything
+                       and print translation statistics.
+
+The en_US translation is slightly special.  It is used for testing the
+translation machinery, and since the source native language is en_GB,
+there is not much other need for the en_US translation.
diff --git a/po/part.make b/po/part.make
new file mode 100644 (file)
index 0000000..551c454
--- /dev/null
@@ -0,0 +1,16 @@
+PARTS += ~
+POTS += .~.pot
+
+mo/~.pot: .~.pot .common.pot
+       $S mkdir -p mo
+       $S msgcat $^ $o
+
+mo/~_%.po: %.po mo/~.pot
+       $S cp $*.po $@.tmp
+       $S msgmerge --quiet --previous $@.tmp mo/~.pot -o $@.tmp
+       $S $f
+
+.PRECIOUS: mo/~.pot mo/~_%.po
+
+# (end of part.make)
+# dependencies of .~.pot will follow (from sed)
similarity index 100%
rename from po/remove-potcdate.pl
rename to po/remove-potcdate