Skip to content

Commit fc0fd5b

Browse files
committed
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 <[email protected]> Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cac25fc commit fc0fd5b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,12 +2216,33 @@ LOCALIZED_SH += t/t0200/test.sh
22162216
LOCALIZED_PERL += t/t0200/test.perl
22172217
endif
22182218

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+
22192227
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+
22202238
$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
22212239
$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
22222240
$(LOCALIZED_SH)
22232241
$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_PERL) \
22242242
$(LOCALIZED_PERL)
2243+
2244+
# Reverting the munged source, leaving only the updated $@
2245+
git reset --hard
22252246
mv $@+ $@
22262247

22272248
.PHONY: pot

0 commit comments

Comments
 (0)