diff --git a/build-aux/minimize-po.pl b/build-aux/minimize-po.pl new file mode 100755 index 0000000..497533a --- /dev/null +++ b/build-aux/minimize-po.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl + +my @block; +my $msgstr = 0; +my $empty = 0; +my $unused = 0; +my $fuzzy = 0; +while (<>) { + if (/^$/) { + if (!$empty && !$unused && !$fuzzy) { + print @block; + } + @block = (); + $msgstr = 0; + $fuzzy = 0; + push @block, $_; + } else { + if (/^msgstr/) { + $msgstr = 1; + $empty = 1; + } + if (/^#.*fuzzy/) { + $fuzzy = 1; + } + if (/^#~ msgstr/) { + $unused = 1; + } + if ($msgstr && /".+"/) { + $empty = 0; + } + push @block, $_; + } +} + +if (@block && !$empty && !$unused) { + print @block; +} diff --git a/po/Makefile.am b/po/Makefile.am index 77a383e..0361de6 100644 --- a/po/Makefile.am +++ b/po/Makefile.am @@ -2,7 +2,7 @@ COPYRIGHT_HOLDER = The Virt Viewer authors MSGID_BUGS_ADDRESS = https://virt-manager.org/bugs/ -MAINTAINERCLEANFILES = $(GMOFILES) $(POTFILE) +MAINTAINERCLEANFILES = $(GMOFILES) $(POTFILE) $(POFILES) LANGS := \ af am anp ar as ast bal be bg \ @@ -48,27 +48,28 @@ -e "s|Copyright (C) YEAR|Copyright (C) $$(date +'%Y')|" \ $(NULL) - -# Although they're in EXTRA_DIST, we still need to -# copy these again, because update-gmo will change - -# their content, and dist-hook runs after the -# things in EXTRA_DIST are copied. -dist-hook: $(GMOFILES) - cp -f $(POTFILE) $(distdir)/ - cp -f $(POFILES) $(distdir)/ - cp -f $(GMOFILES) $(distdir)/ +all: update-po update-po: $(POFILES) update-gmo: $(GMOFILES) + +update-mini-po: $(POTFILE) + for lang in $(LANGS); do \ + echo "Minimizing $$lang content" && \ + $(MSGMERGE) --no-location --no-fuzzy-matching --sort-output \ + $(srcdir)/$$lang.po $(POTFILE) | \ + $(SED) $(SED_PO_FIXUP_ARGS) | \ + $(PERL) $(top_srcdir)/build-aux/minimize-po.pl > \ + $(srcdir)/$$lang.mini.po ; \ + done push-pot: $(POTFILE) zanata push --push-type=source pull-po: $(POTFILE) zanata pull --create-skeletons - $(MAKE) update-po + $(MAKE) update-mini-po $(MAKE) update-gmo $(POTFILE): POTFILES $(POTFILE_DEPS) @@ -77,8 +78,9 @@ $(SED) $(SED_PO_FIXUP_ARGS) < $@-t > $@ rm -f $@-t -$(srcdir)/%.po: $(POTFILE) - $(MSGMERGE) --backup=off --no-fuzzy-matching --update $@ $(POTFILE) +$(srcdir)/%.po: $(srcdir)/%.mini.po $(POTFILE) + $(MSGMERGE) --no-fuzzy-matching $< $(POTFILE) | \ + $(SED) $(SED_PO_FIXUP_ARGS) > $@ $(srcdir)/%.gmo: $(srcdir)/%.po rm -f $@ $@-t diff --git a/po/README.md b/po/README.md index 20ebf83..a9c8e94 100644 --- a/po/README.md +++ b/po/README.md @@ -7,18 +7,39 @@ Source repository ================= -The virt-viewer GIT repository stores the master "virt-viewer.pot" file and -full "po" files for translations. The master "virt-viewer.pot" file can be -re-generated using +The virt-viewer GIT repository does NOT store the master "virt-viewer.pot" +file, nor does it store full "po" files for translations. The master +"virt-viewer.pot" file can be generated at any time using make virt-viewer.pot -The full po files can have their source locations and msgids updated using +The translations are kept in minimized files that are the same file format +as normal po files but with all redundant information stripped and messages +re-ordered. The key differences between the ".mini.po" files in GIT and the +full ".po" files are + + - msgids with no current translation are omitted + - msgids are sorted in alphabetical order not source file order + - msgids with a msgstr marked "fuzzy" are discarded + - source file locations are omitted + +The full po files can be created at any time using make update-po -Normally these updates are only done when either refreshing translations from -Zanata, or when creating a new release. +This merges the "virt-viewer.pot" with the "$LANG.mini.po" for each language, +to create the "$LANG.po" files. These are included in the release archives +created by "make dist". + +When a full po file is updated, changes can be propagated back into the +minimized po files using + + make update-mini-po + +Note, however, that this is generally not something that should be run by +developers normally, as it is triggered by 'make pull-po' when refreshing +content from Zanata. + Zanata web service ================== @@ -30,9 +51,26 @@ As such, changes to translations will generally NOT be accepted as patches directly to virt-viewer GIT. Any changes made to "$LANG.mini.po" files in -virt-viewer GIT will be overwritten and lost the next time content is imported -from Zanata. +virt-viewer GIT will be overwritten and lost the next time content is +imported from Zanata. The master "virt-viewer.pot" file is periodically pushed to Zanata to provide -the translation team with content changes. New translated text is then -periodically pulled down from Zanata to update the po files. +the translation team with content changes, using + + make push-pot + +New translated text is then periodically pulled down from Zanata to update the +minimized po files, using + + make pull-po + +Sometimes the translators make mistakes, most commonly with handling printf +format specifiers. The "pull-po" command re-generates the .gmo files to try to +identify such mistakes. If a mistake is made, the broken msgstr should be +deleted in the local "$LANG.mini.po" file, and the Zanata web interface used +to reject the translation so that the broken msgstr isn't pulled down next time. + +After pulling down new content the diff should be examined to look for any +obvious mistakes that are not caught automatically. There have been bugs in +Zanata tools which caused messges to go missing, so pay particular attention to +diffs showing deletions where the msgid still exists in virt-viewer.pot