diff mbox series

[v2,7/9] Makefile: add "po-update" rule to update po/XX.po

Message ID 20220519081548.3380-8-worldhello.net@gmail.com (mailing list archive)
State New, archived
Headers show
Series None | expand

Commit Message

Jiang Xin May 19, 2022, 8:15 a.m. UTC
From: Jiang Xin <zhiyou.jx@alibaba-inc.com>

Since there is no longer a "po/git.pot" file in tree, a l10n team leader
has to run several commands to update their "po/XX.po" file:

    $ make pot
    $ msgmerge --add-location --backup=off -U po/XX.po po/git.pot

To make this process easier, add a new rule so that l10n team leaders
can update their "po/XX.po" with one command. E.g.:

    $ make po-update PO_FILE=po/zh_CN.po

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Makefile   | 18 ++++++++++++++++++
 shared.mak |  1 +
 2 files changed, 19 insertions(+)

Comments

Ævar Arnfjörð Bjarmason May 19, 2022, 10:07 a.m. UTC | #1
On Thu, May 19 2022, Jiang Xin wrote:

> From: Jiang Xin <zhiyou.jx@alibaba-inc.com>
>
> Since there is no longer a "po/git.pot" file in tree, a l10n team leader
> has to run several commands to update their "po/XX.po" file:
>
>     $ make pot
>     $ msgmerge --add-location --backup=off -U po/XX.po po/git.pot
>
> To make this process easier, add a new rule so that l10n team leaders
> can update their "po/XX.po" with one command. E.g.:
>
>     $ make po-update PO_FILE=po/zh_CN.po
>
> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  Makefile   | 18 ++++++++++++++++++
>  shared.mak |  1 +
>  2 files changed, 19 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index 34904b90d2..edebd44d5c 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -571,6 +571,7 @@ TCLTK_PATH = wish
>  XGETTEXT = xgettext
>  MSGCAT = msgcat
>  MSGFMT = msgfmt
> +MSGMERGE = msgmerge
>  CURL_CONFIG = curl-config
>  GCOV = gcov
>  STRIP = strip
> @@ -2716,6 +2717,7 @@ XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
>  XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --language=Perl \
>  	--keyword=__ --keyword=N__ --keyword="__n:1,2"
>  MSGCAT_FLAGS = --sort-by-file
> +MSGMERGE_FLAGS = --add-location --backup=off --update

Ok, we'd like to have the location in the po/*.po files still. We're
just getting rid of po/git.pot.

I had some patches to also do it for the po/XX.po files, thinking that
we'd only check in the "meaningful" data. We'd then offer translators
some targets to add the locations to the file for working on them, and
then flip back before they did a "git commit" etc. etc.

But none of that needs to happen now, and this series is already quite
large, so just leaving things here seems like a good stopping point.

I also tested with --no-location (updated all to have no location), and
a subsequent --add-location run repairs it. It also fixes a manually
edited nonsense location for a valid msgid. So this all seems OK to me.

>  LOCALIZED_C = $(FOUND_C_SOURCES) $(SCALAR_SOURCES) \
>  	      $(FOUND_H_SOURCES) $(GENERATED_H)
>  LOCALIZED_SH = $(SCRIPT_SH)
> @@ -2787,6 +2789,22 @@ po/git.pot: .build/pot/git.header $(LOCALIZED_ALL_GEN_PO)
>  .PHONY: pot
>  pot: po/git.pot
>  
> +define check_po_file_envvar
> +	$(if $(PO_FILE), \
> +		$(if $(filter po/%.po,$(PO_FILE)), , \
> +			$(error PO_FILE should match pattern: "po/%.po")), \
> +		$(error PO_FILE is not defined))
> +endef
> +
> +.PHONY: po-update
> +po-update: po/git.pot
> +	$(check_po_file_envvar)
> +	@if test ! -e $(PO_FILE); then \
> +		echo >&2 "error: $(PO_FILE) does not exist"; \
> +		exit 1; \
> +	fi
> +	$(QUIET_MSGMERGE)$(MSGMERGE) $(MSGMERGE_FLAGS) $(PO_FILE) po/git.pot

Nit: better to put the $(QUIET_MSGMERGE) in place of that @, i.e. V=1
will give you the full debug dump.

This is fine too I suppose, but we tend to use $(QUIET_*) like that
elsewhere...

>  .PHONY: check-pot
>  check-pot: $(LOCALIZED_ALL_GEN_PO)
>  
> diff --git a/shared.mak b/shared.mak
> index 50d4596f0d..8cd170a7e7 100644
> --- a/shared.mak
> +++ b/shared.mak
> @@ -63,6 +63,7 @@ ifndef V
>  	QUIET_LNCP     = @echo '   ' LN/CP $@;
>  	QUIET_XGETTEXT = @echo '   ' XGETTEXT $@;
>  	QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
> +	QUIET_MSGMERGE = @echo '   ' MSGMERGE $@;
>  	QUIET_GCOV     = @echo '   ' GCOV $@;
>  	QUIET_SP       = @echo '   ' SP $<;
>  	QUIET_HDR      = @echo '   ' HDR $(<:hcc=h);
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 34904b90d2..edebd44d5c 100644
--- a/Makefile
+++ b/Makefile
@@ -571,6 +571,7 @@  TCLTK_PATH = wish
 XGETTEXT = xgettext
 MSGCAT = msgcat
 MSGFMT = msgfmt
+MSGMERGE = msgmerge
 CURL_CONFIG = curl-config
 GCOV = gcov
 STRIP = strip
@@ -2716,6 +2717,7 @@  XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
 XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --language=Perl \
 	--keyword=__ --keyword=N__ --keyword="__n:1,2"
 MSGCAT_FLAGS = --sort-by-file
+MSGMERGE_FLAGS = --add-location --backup=off --update
 LOCALIZED_C = $(FOUND_C_SOURCES) $(SCALAR_SOURCES) \
 	      $(FOUND_H_SOURCES) $(GENERATED_H)
 LOCALIZED_SH = $(SCRIPT_SH)
@@ -2787,6 +2789,22 @@  po/git.pot: .build/pot/git.header $(LOCALIZED_ALL_GEN_PO)
 .PHONY: pot
 pot: po/git.pot
 
+define check_po_file_envvar
+	$(if $(PO_FILE), \
+		$(if $(filter po/%.po,$(PO_FILE)), , \
+			$(error PO_FILE should match pattern: "po/%.po")), \
+		$(error PO_FILE is not defined))
+endef
+
+.PHONY: po-update
+po-update: po/git.pot
+	$(check_po_file_envvar)
+	@if test ! -e $(PO_FILE); then \
+		echo >&2 "error: $(PO_FILE) does not exist"; \
+		exit 1; \
+	fi
+	$(QUIET_MSGMERGE)$(MSGMERGE) $(MSGMERGE_FLAGS) $(PO_FILE) po/git.pot
+
 .PHONY: check-pot
 check-pot: $(LOCALIZED_ALL_GEN_PO)
 
diff --git a/shared.mak b/shared.mak
index 50d4596f0d..8cd170a7e7 100644
--- a/shared.mak
+++ b/shared.mak
@@ -63,6 +63,7 @@  ifndef V
 	QUIET_LNCP     = @echo '   ' LN/CP $@;
 	QUIET_XGETTEXT = @echo '   ' XGETTEXT $@;
 	QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
+	QUIET_MSGMERGE = @echo '   ' MSGMERGE $@;
 	QUIET_GCOV     = @echo '   ' GCOV $@;
 	QUIET_SP       = @echo '   ' SP $<;
 	QUIET_HDR      = @echo '   ' HDR $(<:hcc=h);