From 4b7f6d2e8015f6a3cad748066ed487809381f952 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 15 Oct 2020 11:42:44 +0200 Subject: [PATCH] Bug 26547: *DONT PUSH* Script for updating existing pref PO files The script will convert pref PO files to the new format, with proper msgctxt, reference set, and with a clean msgid It will be needed only once before running `gulp po:update` for the first time after applying patches of bug 26547, so this patch should not be pushed. This step is needed to not lose any translation. Test plan: 1. git checkout master 2. cd misc/translator && ./translate update fr-FR 3. cp po/fr-FR-pref.po /tmp/fr-FR-pref-master.po 4. cp /tmp/fr-FR-pref-master.po /tmp/fr-FR-pref-master-updated.po 5. cd ../.. && misc/devel/update-pref-po-file.pl /tmp/fr-FR-pref-master-updated.po 6. msgcat -s /tmp/fr-FR-pref-master-updated.po > /tmp/fr-FR-pref-master-updated-sorted.po 7. cp /tmp/fr-FR-pref-master-updated.po misc/translator/po/fr-FR-pref.po 8. gulp po:update --lang fr-FR 9. msgcomm -u /tmp/fr-FR-pref-master-updated.po misc/translator/po/fr-FR-pref.po This should print nothing, meaning the result of `gulp:update` is the same as the result of update-pref-po-file.pl 10. diff -U3 /tmp/fr-FR-pref-master-updated-sorted.po misc/translator/po/fr-FR-pref.po The diff should be really small (empty messages removed, differences in line wrapping, but that's all) 11. msgattrib --only-fuzzy /tmp/fr-FR-pref-master.po msgattrib --only-fuzzy /tmp/fr-FR-pref-master-updated.po The output of those two commands should be the same (can be empty if there are no fuzzy messages) 12. cd misc/translator && ./translate install fr-FR Check that preferences are correctly translated in the staff interface For the Release Manager and/or Translation Manager: Once this patchset is pushed, all pref PO files should be updated. This can be done immediately, with updated PO files committed directly in master, or just before sending PO files to Pootle, and they will be committed only before release. It is up to RM/TM. Whatever they choose, the process is the same: 1. Apply this patch 2. Run `misc/devel/update-pref-po-file.pl misc/translator/po/*-pref.po` 3. Run `gulp po:update` 4. Discard this patch 5. Commit or send to pootle --- misc/devel/update-pref-po-file.pl | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 misc/devel/update-pref-po-file.pl diff --git a/misc/devel/update-pref-po-file.pl b/misc/devel/update-pref-po-file.pl new file mode 100755 index 0000000000..378903a0a6 --- /dev/null +++ b/misc/devel/update-pref-po-file.pl @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Locale::PO; + +foreach my $filename (@ARGV) { + my $pos = Locale::PO->load_file_asarray($filename); + + foreach my $po (@$pos) { + my $msgid = $po->dequote($po->msgid); + + if ($msgid =~ /^([^#]+)#([^#]*)# (.*)$/) { + my ($file, $pref, $message) = ($1, $2, $3); + my @comments = split /\n/, $po->comment; + my $comment = $comments[0]; + my $context = $pref ? sprintf('%s > %s', $comment, $pref) : $comment; + $po->msgctxt($context); + $po->comment($context); + $po->msgid($message); + $po->reference(sprintf('koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/%s', $file)); + } elsif ($msgid =~ /^(\w+\.pref)$/) { + my $file = $1; + $po->msgid($po->comment); + $po->comment(undef); + $po->reference(sprintf('koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/%s', $file)); + } elsif ($msgid =~ /^(\w+\.pref) (.*)$/) { + my ($file, $message) = ($1, $2); + my $context = $po->comment =~ s/^([^>]+) >.*/$1/r; + $po->msgctxt($context); + $po->comment($context); + $po->msgid($message); + $po->reference(sprintf('koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/%s', $file)); + } elsif ($msgid eq '') { + # This is the PO header, nothing to do here + } else { + warn sprintf("WARN: The PO entry at %s:%d has not been updated\n", $filename, $po->loaded_line_number); + } + } + + Locale::PO->save_file_fromarray($filename, $pos); +} -- 2.20.1