Skip to content

Commit 28db3b7

Browse files
committed
Merge branch 'jx/l10n-workflow-change'
A workflow change for translators are being proposed. * jx/l10n-workflow-change: l10n: Document the new l10n workflow Makefile: add "po-init" rule to initialize po/XX.po Makefile: add "po-update" rule to update po/XX.po po/git.pot: don't check in result of "make pot" po/git.pot: this is now a generated file Makefile: remove duplicate and unwanted files in FOUND_SOURCE_FILES i18n CI: stop allowing non-ASCII source messages in po/git.pot Makefile: have "make pot" not "reset --hard" Makefile: generate "po/git.pot" from stable LOCALIZED_C Makefile: sort source files before feeding to xgettext
2 parents 16a0e92 + e2f4045 commit 28db3b7

File tree

8 files changed

+250
-25293
lines changed

8 files changed

+250
-25293
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
*.[aos]
201201
*.o.json
202202
*.py[co]
203+
.build/
203204
.depend/
204205
*.gcda
205206
*.gcno

Makefile

Lines changed: 125 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,9 @@ INSTALL = install
569569
TCL_PATH = tclsh
570570
TCLTK_PATH = wish
571571
XGETTEXT = xgettext
572+
MSGCAT = msgcat
572573
MSGFMT = msgfmt
574+
MSGMERGE = msgmerge
573575
CURL_CONFIG = curl-config
574576
GCOV = gcov
575577
STRIP = strip
@@ -844,7 +846,7 @@ generated-hdrs: $(GENERATED_H)
844846
## Exhaustive lists of our source files, either dynamically generated,
845847
## or hardcoded.
846848
SOURCES_CMD = ( \
847-
git ls-files \
849+
git ls-files --deduplicate \
848850
'*.[hcS]' \
849851
'*.sh' \
850852
':!*[tp][0-9][0-9][0-9][0-9]*' \
@@ -855,12 +857,13 @@ SOURCES_CMD = ( \
855857
-o \( -name '[tp][0-9][0-9][0-9][0-9]*' -prune \) \
856858
-o \( -name contrib -type d -prune \) \
857859
-o \( -name build -type d -prune \) \
860+
-o \( -name .build -type d -prune \) \
858861
-o \( -name 'trash*' -type d -prune \) \
859862
-o \( -name '*.[hcS]' -type f -print \) \
860863
-o \( -name '*.sh' -type f -print \) \
861864
| sed -e 's|^\./||' \
862865
)
863-
FOUND_SOURCE_FILES := $(shell $(SOURCES_CMD))
866+
FOUND_SOURCE_FILES := $(filter-out $(GENERATED_H),$(shell $(SOURCES_CMD)))
864867

865868
FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES))
866869
FOUND_H_SOURCES = $(filter %.h,$(FOUND_SOURCE_FILES))
@@ -2708,56 +2711,148 @@ XGETTEXT_FLAGS = \
27082711
--force-po \
27092712
--add-comments=TRANSLATORS: \
27102713
--msgid-bugs-address="Git Mailing List <[email protected]>" \
2711-
--from-code=UTF-8
2714+
--package-name=Git
27122715
XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --language=C \
27132716
--keyword=_ --keyword=N_ --keyword="Q_:1,2"
27142717
XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
27152718
--keyword=gettextln --keyword=eval_gettextln
27162719
XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --language=Perl \
27172720
--keyword=__ --keyword=N__ --keyword="__n:1,2"
2718-
LOCALIZED_C = $(C_OBJ:o=c) $(LIB_H) $(GENERATED_H)
2719-
LOCALIZED_SH = $(SCRIPT_SH)
2720-
LOCALIZED_SH += git-sh-setup.sh
2721-
LOCALIZED_PERL = $(SCRIPT_PERL)
2721+
MSGMERGE_FLAGS = --add-location --backup=off --update
2722+
LOCALIZED_C = $(sort $(FOUND_C_SOURCES) $(FOUND_H_SOURCES) $(SCALAR_SOURCES) \
2723+
$(GENERATED_H))
2724+
LOCALIZED_SH = $(sort $(SCRIPT_SH) git-sh-setup.sh)
2725+
LOCALIZED_PERL = $(sort $(SCRIPT_PERL))
27222726

27232727
ifdef XGETTEXT_INCLUDE_TESTS
27242728
LOCALIZED_C += t/t0200/test.c
27252729
LOCALIZED_SH += t/t0200/test.sh
27262730
LOCALIZED_PERL += t/t0200/test.perl
27272731
endif
27282732

2729-
## Note that this is meant to be run only by the localization coordinator
2730-
## under a very controlled condition, i.e. (1) it is to be run in a
2731-
## Git repository (not a tarball extract), (2) any local modifications
2732-
## will be lost.
2733+
## We generate intermediate .build/pot/po/%.po files containing a
2734+
## extract of the translations we find in each file in the source
2735+
## tree. We will assemble them using msgcat to create the final
2736+
## "po/git.pot" file.
2737+
LOCALIZED_ALL_GEN_PO =
2738+
2739+
LOCALIZED_C_GEN_PO = $(LOCALIZED_C:%=.build/pot/po/%.po)
2740+
LOCALIZED_ALL_GEN_PO += $(LOCALIZED_C_GEN_PO)
2741+
2742+
LOCALIZED_SH_GEN_PO = $(LOCALIZED_SH:%=.build/pot/po/%.po)
2743+
LOCALIZED_ALL_GEN_PO += $(LOCALIZED_SH_GEN_PO)
2744+
2745+
LOCALIZED_PERL_GEN_PO = $(LOCALIZED_PERL:%=.build/pot/po/%.po)
2746+
LOCALIZED_ALL_GEN_PO += $(LOCALIZED_PERL_GEN_PO)
2747+
27332748
## Gettext tools cannot work with our own custom PRItime type, so
27342749
## we replace PRItime with PRIuMAX. We need to update this to
27352750
## PRIdMAX if we switch to a signed type later.
2751+
$(LOCALIZED_C_GEN_PO): .build/pot/po/%.po: %
2752+
$(call mkdir_p_parent_template)
2753+
$(QUIET_XGETTEXT) \
2754+
if grep -q PRItime $<; then \
2755+
(\
2756+
sed -e 's|PRItime|PRIuMAX|g' <$< \
2757+
>.build/pot/po/$< && \
2758+
cd .build/pot/po && \
2759+
$(XGETTEXT) --omit-header \
2760+
-o $(@:.build/pot/po/%=%) \
2761+
$(XGETTEXT_FLAGS_C) $< && \
2762+
rm $<; \
2763+
); \
2764+
else \
2765+
$(XGETTEXT) --omit-header \
2766+
-o $@ $(XGETTEXT_FLAGS_C) $<; \
2767+
fi
27362768

2737-
po/git.pot: $(GENERATED_H) FORCE
2738-
# All modifications will be reverted at the end, so we do not
2739-
# want to have any local change.
2740-
git diff --quiet HEAD && git diff --quiet --cached
2769+
$(LOCALIZED_SH_GEN_PO): .build/pot/po/%.po: %
2770+
$(call mkdir_p_parent_template)
2771+
$(QUIET_XGETTEXT)$(XGETTEXT) --omit-header \
2772+
-o$@ $(XGETTEXT_FLAGS_SH) $<
27412773

2742-
@for s in $(LOCALIZED_C) $(LOCALIZED_SH) $(LOCALIZED_PERL); \
2743-
do \
2744-
sed -e 's|PRItime|PRIuMAX|g' <"$$s" >"$$s+" && \
2745-
cat "$$s+" >"$$s" && rm "$$s+"; \
2746-
done
2774+
$(LOCALIZED_PERL_GEN_PO): .build/pot/po/%.po: %
2775+
$(call mkdir_p_parent_template)
2776+
$(QUIET_XGETTEXT)$(XGETTEXT) --omit-header \
2777+
-o$@ $(XGETTEXT_FLAGS_PERL) $<
2778+
2779+
define gen_pot_header
2780+
$(XGETTEXT) $(XGETTEXT_FLAGS_C) \
2781+
-o - /dev/null | \
2782+
sed -e 's|charset=CHARSET|charset=UTF-8|' \
2783+
-e 's|\(Last-Translator: \)FULL NAME <.*>|\1make by the Makefile|' \
2784+
-e 's|\(Language-Team: \)LANGUAGE <.*>|\1Git Mailing List <[email protected]>|' \
2785+
>$@ && \
2786+
echo '"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n"' >>$@
2787+
endef
27472788

2748-
$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
2749-
$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
2750-
$(LOCALIZED_SH)
2751-
$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_PERL) \
2752-
$(LOCALIZED_PERL)
2789+
.build/pot/git.header: $(LOCALIZED_ALL_GEN_PO)
2790+
$(call mkdir_p_parent_template)
2791+
$(QUIET_GEN)$(gen_pot_header)
27532792

2754-
# Reverting the munged source, leaving only the updated $@
2755-
git reset --hard
2756-
mv $@+ $@
2793+
po/git.pot: .build/pot/git.header $(LOCALIZED_ALL_GEN_PO)
2794+
$(QUIET_GEN)$(MSGCAT) $^ >$@
27572795

27582796
.PHONY: pot
27592797
pot: po/git.pot
27602798

2799+
define check_po_file_envvar
2800+
$(if $(PO_FILE), \
2801+
$(if $(filter po/%.po,$(PO_FILE)), , \
2802+
$(error PO_FILE should match pattern: "po/%.po")), \
2803+
$(error PO_FILE is not defined))
2804+
endef
2805+
2806+
.PHONY: po-update
2807+
po-update: po/git.pot
2808+
$(check_po_file_envvar)
2809+
@if test ! -e $(PO_FILE); then \
2810+
echo >&2 "error: $(PO_FILE) does not exist"; \
2811+
echo >&2 'To create an initial po file, use: "make po-init PO_FILE=po/XX.po"'; \
2812+
exit 1; \
2813+
fi
2814+
$(QUIET_MSGMERGE)$(MSGMERGE) $(MSGMERGE_FLAGS) $(PO_FILE) po/git.pot
2815+
2816+
.PHONY: check-pot
2817+
check-pot: $(LOCALIZED_ALL_GEN_PO)
2818+
2819+
### TODO FIXME: Translating everything in these files is a bad
2820+
### heuristic for "core", as we'll translate obscure error() messages
2821+
### along with commonly seen i18n messages. A better heuristic would
2822+
### be to e.g. use spatch to first remove error/die/warning
2823+
### etc. messages.
2824+
LOCALIZED_C_CORE =
2825+
LOCALIZED_C_CORE += builtin/checkout.c
2826+
LOCALIZED_C_CORE += builtin/clone.c
2827+
LOCALIZED_C_CORE += builtin/index-pack.c
2828+
LOCALIZED_C_CORE += builtin/push.c
2829+
LOCALIZED_C_CORE += builtin/reset.c
2830+
LOCALIZED_C_CORE += remote.c
2831+
LOCALIZED_C_CORE += wt-status.c
2832+
2833+
LOCALIZED_C_CORE_GEN_PO = $(LOCALIZED_C_CORE:%=.build/pot/po/%.po)
2834+
2835+
.build/pot/git-core.header: $(LOCALIZED_C_CORE_GEN_PO)
2836+
$(call mkdir_p_parent_template)
2837+
$(QUIET_GEN)$(gen_pot_header)
2838+
2839+
po/git-core.pot: .build/pot/git-core.header $(LOCALIZED_C_CORE_GEN_PO)
2840+
$(QUIET_GEN)$(MSGCAT) $^ >$@
2841+
2842+
.PHONY: po-init
2843+
po-init: po/git-core.pot
2844+
$(check_po_file_envvar)
2845+
@if test -e $(PO_FILE); then \
2846+
echo >&2 "error: $(PO_FILE) exists already"; \
2847+
exit 1; \
2848+
fi
2849+
$(QUIET_MSGINIT)msginit \
2850+
--input=$< \
2851+
--output=$(PO_FILE) \
2852+
--no-translator \
2853+
--locale=$(PO_FILE:po/%.po=%)
2854+
2855+
## po/*.po files & their rules
27612856
ifdef NO_GETTEXT
27622857
POFILES :=
27632858
MOFILES :=
@@ -3293,6 +3388,8 @@ cocciclean:
32933388
$(RM) contrib/coccinelle/*.cocci.patch*
32943389

32953390
clean: profile-clean coverage-clean cocciclean
3391+
$(RM) -r .build
3392+
$(RM) po/git.pot po/git-core.pot
32963393
$(RM) *.res
32973394
$(RM) $(OBJECTS)
32983395
$(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3260,7 +3260,7 @@ static int module_add(int argc, const char **argv, const char *prefix)
32603260
N_("reference repository")),
32613261
OPT_BOOL(0, "dissociate", &dissociate, N_("borrow the objects from reference repositories")),
32623262
OPT_STRING(0, "name", &add_data.sm_name, N_("name"),
3263-
N_("sets the submodules name to the given string "
3263+
N_("sets the submodule's name to the given string "
32643264
"instead of defaulting to its path")),
32653265
OPT_INTEGER(0, "depth", &add_data.depth, N_("depth for shallow clones")),
32663266
OPT_END()

ci/run-static-analysis.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ fi
2929
make hdr-check ||
3030
exit 1
3131

32+
make check-pot
33+
3234
save_good_tree

po/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/build
2+
/git.pot
3+
/git-core.pot

0 commit comments

Comments
 (0)