-# 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://translationproject.org/latest/$(1)/$$$$lang.po" ; \
- then \
- mv "$(top_srcdir)/$(2)/$(3)$$$$lang.po"{.tmp,} ; \
- else \
- rm "$(top_srcdir)/$(2)/$(3)$$$$lang.po.tmp" ; \
- fi ; \
- done
-
-.PHONY: download-po.$(1)
-
-endef
-
-$(eval $(call make-download-po-rule,guix,po/guix))
-$(eval $(call make-download-po-rule,guix-packages,po/packages))
-$(eval $(call make-download-po-rule,guix-manual,po/doc,guix-manual.))
-
-download-po: $(foreach domain,guix guix-packages guix-manual,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"