Makefile: help gettext tools to cope with our custom PRItime format

We started using our own timestamp_t type and PRItime format specifier to go along with it, so that we can later change the underlying type and output format more easily, but this does not play well with gettext tools. Because gettext tools need to keep the *.po file portable across platforms, they have to special-case the format specifiers like PRIuMAX that are known types in inttypes.h, instead of letting CPP handle strings like "%" PRIuMAX " seconds ago" as an ordinary string concatenation. They fundamentally cannot do the same for our own custom type/format. Given that po/git.pot needs to be generated only once every release and by only one person, i.e. the l10n coordinator, let's update the Makefile rule to generate po/git.pot so that gettext tools are run on a munged set of sources in which all mentions of PRItime are replaced with PRIuMAX, which is what we happen to use right now. This way, developers do not have to care that PRItime does not play well with gettext, and translators do not have to care that we use our own PRItime. The credit for the idea to munge the source files goes to Dscho. Possible bugs are mine. Helped-by: Jiang Xin <worldhello.net@gmail.com> Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 20, 2017 at 11:57 UTC fc0fd5b23bc84c517eff409b7cbc78cc2473a071
1 file changed +21
Makefile
+21
@@ -2216,12 +2216,33 @@ LOCALIZED_SH += t/t0200/test.sh
2216 LOCALIZED_PERL += t/t0200/test.perl
2217 endif
2218
2219 +## Note that this is meant to be run only by the localization coordinator
2220 +## under a very controlled condition, i.e. (1) it is to be run in a
2221 +## Git repository (not a tarball extract), (2) any local modifications
2222 +## will be lost.
2223 +## Gettext tools cannot work with our own custom PRItime type, so
2224 +## we replace PRItime with PRIuMAX. We need to update this to
2225 +## PRIdMAX if we switch to a signed type later.
2226 +
2227 po/git.pot: $(GENERATED_H) FORCE
2228 + # All modifications will be reverted at the end, so we do not
2229 + # want to have any local change.
2230 + git diff --quiet HEAD && git diff --quiet --cached
2231 +
2232 + @for s in $(LOCALIZED_C) $(LOCALIZED_SH) $(LOCALIZED_PERL); \
2233 + do \
2234 + sed -e 's|PRItime|PRIuMAX|g' <"$$s" >"$$s+" && \
2235 + cat "$$s+" >"$$s" && rm "$$s+"; \
2236 + done
2237 +
2238 $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
2239 $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
2240 $(LOCALIZED_SH)
2241 $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_PERL) \
2242 $(LOCALIZED_PERL)
2243 +
2244 + # Reverting the munged source, leaving only the updated $@
2245 + git reset --hard
2246 mv $@+ $@
2247
2248 .PHONY: pot