summary refs log tree commit diff
path: root/Makefile.am
diff options
context:
space:
mode:
authorJulien Lepiller <julien@lepiller.eu>2021-04-18 23:56:48 +0200
committerJulien Lepiller <julien@lepiller.eu>2021-05-01 14:16:27 +0200
commit45549e9f31e462d0d1519fd678dd782da6ed5cb9 (patch)
tree1f3a136caa1f90d5293bdf9b1515c81a55dc5ef5 /Makefile.am
parentc04dfb39f62f764b1c3988d9b0fcedc8221afa67 (diff)
downloadguix-45549e9f31e462d0d1519fd678dd782da6ed5cb9.tar.gz
Makefile: Reimplement `download-po` target.
The weblate API rate limit is very close to the number of files we need
to download.  The previous implementation did not add new translations.

* Makefile.am (download-po): Update target.
(make-download-po-rule, make-check-po-rule): Remove functions.
Diffstat (limited to 'Makefile.am')
-rw-r--r--Makefile.am92
1 files changed, 24 insertions, 68 deletions
diff --git a/Makefile.am b/Makefile.am
index 1259d3727b..e6a7b545d8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -966,76 +966,32 @@ cuirass-jobs: $(GOBJECTS)
 
 # Downloading up-to-date PO files.
 
-# make-download-po-rule DOMAIN DIRECTORY [FILE-NAME-PREFIX]
-define make-download-po-rule
-
-download-po.$(1):
-	if [ -f "$(top_srcdir)/$(2)/LINGUAS" ]; then				\
-	  LINGUAS="`grep -v '^[[:blank:]]*#' < $(top_srcdir)/$(2)/LINGUAS`" ;	\
-	else									\
-	  LINGUAS="`(cd $(top_srcdir)/$(2);					\
-	    for i in *.po; do echo $$$$i; done) | cut -d . -f 2`" ;		\
-	fi ;									\
-	for lang in $$$$LINGUAS; do						\
-	  if wget -nv -O "$(top_srcdir)/$(2)/$(3)$$$$lang.po.tmp"		\
-	     "https://translate.fedoraproject.org/api/translations/guix/$(1)/$$$$lang/file/" ; \
-	  then									\
-	    msgfilter --no-wrap -i "$(top_srcdir)/$(2)/$(3)$$$$lang.po.tmp"	\
-	      cat > "$(top_srcdir)/$(2)/$(3)$$$$lang.po.tmp2" ;			\
-	    rm "$(top_srcdir)/$(2)/$(3)$$$$lang.po.tmp" ;			\
-	    mv "$(top_srcdir)/$(2)/$(3)$$$$lang.po"{.tmp2,} ;			\
-	  else									\
-	    rm "$(top_srcdir)/$(2)/$(3)$$$$lang.po.tmp" ;			\
-	  fi ;									\
-	done
-
-.PHONY: download-po.$(1)
-
-endef
-
-# Checking po files for issues.  This is useful to run after downloading new
-# po files.
-
-# make-check-po-rule DOMAIN DIRECTORY [FILE-NAME-PREFIX]
-define make-check-po-rule
-
-check-po.$(1):
-	if [ -f "$(top_srcdir)/$(2)/LINGUAS" ]; then				\
-	  LINGUAS="`grep -v '^[[:blank:]]*#' < $(top_srcdir)/$(2)/LINGUAS`" ;	\
-	else									\
-	  LINGUAS="`(cd $(top_srcdir)/$(2);					\
-	    for i in *.po; do echo $$$$i; done) | cut -d . -f 2`" ;		\
-	fi ;									\
-	for lang in $$$$LINGUAS; do						\
-	  if [ -f "$(top_srcdir)/$(2)/$(3)$$$$lang.po" ];			\
-	  then									\
-	    if ! msgfmt -c "$(top_srcdir)/$(2)/$(3)$$$$lang.po" ;		\
-		then								\
-		  exit 1 ;							\
-	    fi ;								\
-	  fi ;									\
-	done
-
-.PHONY: check-po.$(1)
-
-endef
-
-$(eval $(call make-download-po-rule,documentation-cookbook,po/doc,guix-cookbook.))
-$(eval $(call make-download-po-rule,documentation-manual,po/doc,guix-manual.))
-$(eval $(call make-download-po-rule,guix,po/guix))
-$(eval $(call make-download-po-rule,packages,po/packages))
-
-$(eval $(call make-check-po-rule,documentation-cookbook,po/doc,guix-cookbook.))
-$(eval $(call make-check-po-rule,documentation-manual,po/doc,guix-manual.))
-$(eval $(call make-check-po-rule,guix,po/guix))
-$(eval $(call make-check-po-rule,packages,po/packages))
-
-download-po: $(foreach domain,guix packages documentation-manual documentation-cookbook,download-po.$(domain))
+WEBLATE_REPO = https://framagit.org/tyreunom/guix-translations
+
+# Shallow clone the Git repository behind Weblate and copy files from it if
+# they contain at least one translation, and they are well-formed (Scheme
+# format only), warn otherwise.  Copied files are converted to a canonical
+# form.
+download-po:
+	dir=$$(mktemp -d); \
+	git clone --depth 1 "$(WEBLATE_REPO)" "$$dir/translations"; \
+	for domain in po/doc po/guix po/packages; do \
+	    for po in "$$dir/translations/$$domain"/*.po; do \
+	        translated=$$(LANG=en_US.UTF-8 msgfmt --statistics "$$po" 2>&1 | cut -f1 -d' '); \
+	        target=$$(basename "$$po"); \
+	        target="$$domain/$$target"; \
+	        if msgfmt -c "$$po" && [ "$$translated" != "0" ]; then \
+	            msgfilter --no-wrap -i "$$po" cat > "$$po".tmp; \
+	            mv "$$po".tmp "$$target"; \
+	            echo "copied $$target."; \
+	        else \
+	            echo "WARN: $$target ($$translated translated messages) was not added/updated."; \
+	        fi; \
+	    done; \
+	done; \
+	rm -rf "$$dir"
 .PHONY: download-po
 
-check-po: $(foreach domain,guix packages documentation-manual documentation-cookbook,check-po.$(domain))
-.PHONY: check-po
-
 ## -------------- ##
 ## Silent rules.  ##
 ## -------------- ##