aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2020-05-05 10:34:57 +0200
committerMatthias Andree <matthias.andree@gmx.de>2020-05-05 10:34:57 +0200
commit356c3d245d6a6c0ec53fbed6b0c47dc7b8ddff4c (patch)
treec9955bdbac397da66088bf1754611e92693e1a1f
parent2317d188d15dc7829dc6dd8e0dd309290480abdc (diff)
downloadfetchmail-356c3d245d6a6c0ec53fbed6b0c47dc7b8ddff4c.tar.gz
fetchmail-356c3d245d6a6c0ec53fbed6b0c47dc7b8ddff4c.tar.bz2
fetchmail-356c3d245d6a6c0ec53fbed6b0c47dc7b8ddff4c.zip
Permit committing revised translations, and require -c or -n.
Also consider PO-Revision-Date: for committed updates. Add a new mode "-c" for commit, and enforce that either that, or "-n" (dry-run) is given in any case. Rename $trl to $translator for clarity.
-rwxr-xr-xdist-tools/git-commit-po-updates.sh36
1 files changed, 23 insertions, 13 deletions
diff --git a/dist-tools/git-commit-po-updates.sh b/dist-tools/git-commit-po-updates.sh
index 8f633d88..dcbc3965 100755
--- a/dist-tools/git-commit-po-updates.sh
+++ b/dist-tools/git-commit-po-updates.sh
@@ -4,12 +4,13 @@
# Assumes translation updates are visible to git,
# and one directory above.
#
-# © Copyright 2019 by Matthias Andree.
+# © Copyright 2019 - 2020 by Matthias Andree.
# Licensed under the GNU General Public License V2 or,
# at your choice, any later version.
#
-# Supported options:
+# Supported modes:
# -n: dry-run, only print commands, but do not run them.
+# -c: commit, print commands and run them.
set -eu
@@ -19,45 +20,54 @@ cd "$(realpath $(dirname $0))/.."
# and implicitly fail (set -e) if it hasn't.
perl -MCarp::Always -e ''
+usage() {
+ printf 'Usage: %s {-n|-c}\n-n: dry-run; -c: commit\n' "$0"
+ exit $1
+}
+
dryrun_pfx=
-while getopts 'n' opt ; do
+docommit=
+while getopts 'nc' opt ; do
case $opt in
n) dryrun_pfx=: ;;
- ?) printf 'Usage: %s [-n]\n' "$0" ;
- exit 2 ;
+ c) docommit=y ;;
+ ?)
+ usage 2 ;
esac
done
-git diff -G ^.Project-Id-Version --name-only po/*.po \
-| while read pofile ; do
+if [ -z "$dryrun_pfx" -a -z "$docommit" ] ; then usage 2 ; fi
+
+git diff -G '^"(Project-Id-Version|PO-Revision-Date):' --name-only po/*.po \
+| while read pofile ; do
if ! cmd="$(perl -WT - "$pofile" <<'_EOF'
use Encode::Locale;
use Encode;
use strict;
use Carp::Always ();
use warnings FATAL => 'uninitialized';
-my ($ver, $dat, $trl, $lang, $lcod, $cset, $found);
+my ($ver, $dat, $translator, $lang, $lcod, $cset, $found);
while(<>)
{
if (/^"Project-Id-Version: (.+)\\n"/) { $ver=$1; };
if (/^"PO-Revision-Date: (.+)\\n"/) { $dat=$1; };
- if (/^"Last-Translator: (.+)\\n"/) { $trl=$1; };
+ if (/^"Last-Translator: (.+)\\n"/) { $translator=$1; };
if (/^"Language-Team: ([^<]+?)\s+<.*>\\n"/)
{ $lang=$1; };
if (/^"Language: (.+)\\n"/) { $lcod=$1; };
if (/^"Content-Type: text\/plain; charset=(.+)\\n"/)
{ $cset = $1; };
- if ($ver and $dat and $trl and $lang and $lcod and $cset) {
+ if ($ver and $dat and $translator and $lang and $lcod and $cset) {
$found = 1;
- last;
+ last;
}
}
-$trl = Encode::decode($cset, $trl);
+$translator = Encode::decode($cset, $translator);
if ($found) {
- print Encode::encode(locale => "git commit --author '$trl' --date '$dat' -m 'Update <$lcod> $lang translation to $ver'", Encode::FB_CROAK);
+ print Encode::encode(locale => "git commit --author '$translator' --date '$dat' -m 'Update <$lcod> $lang translation to $ver'", Encode::FB_CROAK);
} else {
exit(1);
}