From: David Woodhouse Date: Fri, 15 Apr 2022 12:25:46 +0000 (+0100) Subject: Reduce the 'bus factor' for translation sync a bit X-Git-Tag: v9.00~40 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3235d24e38b5171e7cc6ffa5af17e4214a409d51;p=users%2Fdwmw2%2Fopenconnect.git Reduce the 'bus factor' for translation sync a bit This is mostly just what NMo's import-strings.sh does, but now it's a bit more obvious and accessible for other OpenConnect developers. Signed-off-by: David Woodhouse --- diff --git a/Makefile.am b/Makefile.am index e2ff4cd0..e0b4c723 100644 --- a/Makefile.am +++ b/Makefile.am @@ -245,6 +245,94 @@ tag: uncommitted-check @git tag v$(VERSION) @cd $(srcdir) && ./autogen.sh + +########################################################################### +# +# Translations are handled in the NetworkManager-openconnect repository by +# GNOME translation teams. We export all our translatable strings to a file +# 'openconnect-strings.txt' which is included in their set of files to be +# translated. +# +# We have an 'import-strings' make target which, for each translation, does +# a merge of their file with ours and compares with a canonicalised version +# of ours to see if there are any substantive changes. The strings from +# NetworkManager-openconnect take precedence over ours, so if there are +# any *corrections* to translations they need to be applied there first, +# because changes in openconnect to a string which is already translated +# in NetworkManager-openconnect will get overwritten on the next sync. +# +# Given that precedence, the 'export-strings' target is mostly only useful +# when we add *new* strings which already have translations, which happens +# occasionally when we change a non-translated part of a string (e.g. when +# we recently replaced URLs and email addresses with '%s' and could do that +# without 'losing' the existing translations by changing those too). +# +# A decent guess at where NetworkManager-openconnect might be checked out... +NMO_DIR := $(srcdir)/../NetworkManager-openconnect +NMO_POT := $(NMO_DIR)/po/NetworkManager-openconnect.pot +NMO_STRINGS := $(NMO_DIR)/openconnect-strings.txt + +NMO_LINGUAS = $(wildcard $(NMO_DIR)/po/*.po) +OC_LINGUAS = $(shell grep -v ^\# $(srcdir)/po/LINGUAS) + +# Generate the openconnect-strings.txt file in the NetworkManager-openconnect +# repository, which 'injects' our strings there to be translated. +$(NMO_STRINGS): po/$(PACKAGE).pot uncommitted-check + $(srcdir)/export-strings.sh $@ $< + +.PHONY: $(NMO_POT) +$(NMO_POT): $(NMO_STRINGS) + make -C $(NMO_DIR)/po NetworkManager-openconnect.pot + +# Sync translations from our own po/ directory to NetworkManager-openconnect, +# with theirs taking precedence. Use a strange path with extra 'po/..' to +# avoid circular dependencies. +$(NMO_DIR)/po/../po/%.po: $(srcdir)/po/%.po $(NMO_POT) po/$(PACKAGE).pot + @msgattrib -F --no-fuzzy $< > $@.openconnect +# Merge using local strings as additional compendium + @msgmerge -q -N -F $@ -C $@.openconnect ${NMO_POT} > $@.merged +# Dummy merge (cleanup) for comparison. + @msgmerge -q -N -F $@ ${NMO_POT} > $@.unmerged +# If the result is different, update the NM version. + @if ! cmp $@.merged $@.unmerged; then \ + echo "New changes for NetworkManager-openconnect $(notdir $@)"; \ + mv $@.merged $@; \ + else \ + echo "No changes for NetworkManager-openconnect $(notdir $@)"; \ + fi + @rm -f $@.openconnect $@.merged $@.unmerged + +# Sync translations from NetworkManager-openconnect, with theirs taking +# precedence. +$(srcdir)/po/../po/%.po: $(NMO_DIR)/po/%.po $(NMO_POT) po/$(PACKAGE).pot + @msgattrib -F --no-fuzzy $< > $@.nmo +# Merge NM against openconnect.pot, using local strings as additional compendium + @msgmerge -q -N -C $@ -F $@.nmo po/$(PACKAGE).pot > $@.merged1 +# Remove fuzzy and obsolete translations + @msgattrib -F --no-fuzzy --no-obsolete $@.merged1 > $@.merged2 +# Unmerged, clean up for simple comparison + @msgmerge -q -N -F $@ po/$(PACKAGE).pot > $@.unmerged + @if ! cmp $@.merged2 $@.unmerged; then \ + echo "New changes for $(notdir $@)"; \ + mv $@.merged2 $@; \ + else \ + echo "No changes for $(notdir $@)"; \ + fi + @rm -f $@.nmo $@.merged1 $@.merged2 $@.unmerged + +# Import translated strings from NetworkManager-openconnect +import-strings: $(patsubst $(NMO_DIR)/%,$(srcdir)/po/../%,$(NMO_LINGUAS)) + if ! git update-index -q --refresh --unmerged || \ + ! git diff-index --name-only --exit-code HEAD -- $(srcdir)/po/ >/dev/null; then \ + git commit -s -m "Import translations from GNOME" -- $(srcdir)/po/ ; \ + else \ + echo No changes to commit ; \ + fi + +# Export our translatable strings to NetworkManager-openconnect +export-strings: $(patsubst $(NMO_DIR)/%,$(NMO_DIR)/po/../%,$(NMO_LINGUAS)) + +# Just resync the translation comments to reflect accurate line numbers, etc. update-po: po/$(PACKAGE).pot @cd $(top_srcdir); if ! git diff-index --name-only --exit-code HEAD -- po/; then \ echo "*** ERROR: Uncommitted changes in above files"; exit 1; \