@@ -200,6 +200,7 @@
*.[aos]
*.o.json
*.py[co]
+.build/
.depend/
*.gcda
*.gcno
@@ -569,6 +569,7 @@ INSTALL = install
TCL_PATH = tclsh
TCLTK_PATH = wish
XGETTEXT = xgettext
+MSGCAT = msgcat
MSGFMT = msgfmt
CURL_CONFIG = curl-config
GCOV = gcov
@@ -2706,6 +2707,7 @@ XGETTEXT_FLAGS = \
--force-po \
--add-comments=TRANSLATORS: \
--msgid-bugs-address="Git Mailing List <git@vger.kernel.org>" \
+ --package-name=Git \
--sort-by-file \
--from-code=UTF-8
XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --language=C \
@@ -2714,6 +2716,7 @@ XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
--keyword=gettextln --keyword=eval_gettextln
XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --language=Perl \
--keyword=__ --keyword=N__ --keyword="__n:1,2"
+MSGCAT_FLAGS = --sort-by-file
LOCALIZED_C = $(FOUND_C_SOURCES) $(SCALAR_SOURCES) \
$(FOUND_H_SOURCES) $(GENERATED_H)
LOCALIZED_SH = $(SCRIPT_SH)
@@ -2726,34 +2729,61 @@ LOCALIZED_SH += t/t0200/test.sh
LOCALIZED_PERL += t/t0200/test.perl
endif
-## Note that this is meant to be run only by the localization coordinator
-## under a very controlled condition, i.e. (1) it is to be run in a
-## Git repository (not a tarball extract), (2) any local modifications
-## will be lost.
+## We generate intermediate .build/pot/po/%.po files containing a
+## extract of the translations we find in each file in the source
+## tree. We will assemble them using msgcat to create the final
+## "po/git.pot" file.
+LOCALIZED_ALL_GEN_PO =
+
+LOCALIZED_C_GEN_PO = $(LOCALIZED_C:%=.build/pot/po/%.po)
+LOCALIZED_ALL_GEN_PO += $(LOCALIZED_C_GEN_PO)
+
+LOCALIZED_SH_GEN_PO = $(LOCALIZED_SH:%=.build/pot/po/%.po)
+LOCALIZED_ALL_GEN_PO += $(LOCALIZED_SH_GEN_PO)
+
+LOCALIZED_PERL_GEN_PO = $(LOCALIZED_PERL:%=.build/pot/po/%.po)
+LOCALIZED_ALL_GEN_PO += $(LOCALIZED_PERL_GEN_PO)
+
## Gettext tools cannot work with our own custom PRItime type, so
## we replace PRItime with PRIuMAX. We need to update this to
## PRIdMAX if we switch to a signed type later.
+$(LOCALIZED_C_GEN_PO): .build/pot/po/%.po: %
+ $(call mkdir_p_parent_template)
+ $(QUIET_XGETTEXT) \
+ if grep -q PRItime $<; then \
+ (\
+ sed -e 's|PRItime|PRIuMAX|g' <$< \
+ >.build/pot/po/$< && \
+ cd .build/pot/po && \
+ $(XGETTEXT) --omit-header \
+ -o $(@:.build/pot/po/%=%) \
+ $(XGETTEXT_FLAGS_C) $< && \
+ rm $<; \
+ ); \
+ else \
+ $(XGETTEXT) --omit-header \
+ -o $@ $(XGETTEXT_FLAGS_C) $<; \
+ fi
-po/git.pot: $(GENERATED_H) FORCE
- # All modifications will be reverted at the end, so we do not
- # want to have any local change.
- git diff --quiet HEAD && git diff --quiet --cached
+$(LOCALIZED_SH_GEN_PO): .build/pot/po/%.po: %
+ $(call mkdir_p_parent_template)
+ $(QUIET_XGETTEXT)$(XGETTEXT) --omit-header \
+ -o$@ $(XGETTEXT_FLAGS_SH) $<
- @for s in $(LOCALIZED_C) $(LOCALIZED_SH) $(LOCALIZED_PERL); \
- do \
- sed -e 's|PRItime|PRIuMAX|g' <"$$s" >"$$s+" && \
- cat "$$s+" >"$$s" && rm "$$s+"; \
- done
+$(LOCALIZED_PERL_GEN_PO): .build/pot/po/%.po: %
+ $(call mkdir_p_parent_template)
+ $(QUIET_XGETTEXT)$(XGETTEXT) --omit-header \
+ -o$@ $(XGETTEXT_FLAGS_PERL) $<
- $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
- $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
- $(LOCALIZED_SH)
- $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_PERL) \
- $(LOCALIZED_PERL)
+.build/pot/git.header: $(LOCALIZED_ALL_GEN_PO)
+ $(call mkdir_p_parent_template)
+ $(QUIET_XGETTEXT)$(XGETTEXT) $(XGETTEXT_FLAGS_C) \
+ -o - /dev/null | \
+ sed -e 's|charset=CHARSET|charset=UTF-8|g' >$@ && \
+ echo '"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n"' >>$@
- # Reverting the munged source, leaving only the updated $@
- git reset --hard
- mv $@+ $@
+po/git.pot: .build/pot/git.header $(LOCALIZED_ALL_GEN_PO)
+ $(QUIET_GEN)$(MSGCAT) $(MSGCAT_FLAGS) $^ >$@
.PHONY: pot
pot: po/git.pot
@@ -3292,6 +3322,7 @@ cocciclean:
$(RM) contrib/coccinelle/*.cocci.patch*
clean: profile-clean coverage-clean cocciclean
+ $(RM) -r .build
$(RM) *.res
$(RM) $(OBJECTS)
$(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)