gnucash stable: New script to update translator-credits.

John Ralls jralls at code.gnucash.org
Mon Dec 9 16:25:04 EST 2024


Updated	 via  https://github.com/Gnucash/gnucash/commit/0ae6a202 (commit)
	from  https://github.com/Gnucash/gnucash/commit/5483f21e (commit)



commit 0ae6a202bedf1ac3e9d991f4ad248216355f1668
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Dec 9 13:23:55 2024 -0800

    New script to update translator-credits.
    
    See POD for usage instructions.

diff --git a/util/extract-translators.pl b/util/extract-translators.pl
new file mode 100644
index 0000000000..0a0a595fdc
--- /dev/null
+++ b/util/extract-translators.pl
@@ -0,0 +1,71 @@
+use strict;
+use warnings;
+use utf8;
+
+my $start = 0;
+my $credits = 0;
+my $extract_re = qr{^# ([-[:alpha:]\d_., ]+)(?: [(<].*[)>])*, ([-\d, ]+)};
+my $credits_re = qr(^msgid "translator-credits"$);
+my %translators = ();
+my $infile = shift;
+my $outfile = $infile . ".new";
+open(my $INFILE, "<", $infile);
+open(my $OUTFILE, ">", $outfile);
+
+while (<$INFILE>) {
+    if ($_ =~ $extract_re && $start < 1) {
+        $start++;
+    }
+    if ($start == 1 && $_ !~ $extract_re) {
+        $start++;
+    }
+
+    if ($start == 1) {
+        my $input = $_;
+        utf8::decode($input);
+        $input =~ $extract_re;
+        unless ($1) {
+            print $OUTFILE $_;
+            next;
+        }
+        my $name = $1;
+        utf8::encode($name);
+        if (exists ($translators{$name})) {
+            push @{$translators{$name}}, split(", ", $2);
+        } else {
+            my @years =  split(", ", $2);
+            $translators{$name} = \@years;
+        }
+    }
+    if ($_ =~ $credits_re && %translators) {
+        my $translators_str;
+        $credits++;
+        print $OUTFILE $_;
+        print $OUTFILE "msgstr \"\"\n";
+        foreach my $translator (sort(keys(%translators))) {
+            my $dates = join(", ", sort(@{$translators{$translator}}));
+            $translators_str .= "$translator: $dates; ";
+        }
+        if (defined $translators_str) {
+            print $OUTFILE "\"$_;\"\n" for map substr($_, 0, 72), $translators_str =~ m[(.{1,72})(?:; |$)]g;
+            print $OUTFILE "\"\n\n";
+        }
+    }
+    $credits++ if ($credits && substr($_, 0, 1) eq "#");
+    next if ($credits == 1);
+    print $OUTFILE $_
+}
+close($INFILE);
+close($OUTFILE);
+rename $outfile, $infile;
+=begin
+    perl extract-translators.pl filename
+
+Finds comments at the beginning of the po file of the form
+  Name email-address? number
+Where email-address is optional and number is one or more four-digit years separated by commas or hyphens. The name and years are extracted and replace the msgstr for msgid "translator-credits".
+
+Run this command in a shell for loop:
+   for i in po/*.po; do perl extract-translators.pl $i; done
+Then review the changes and commit them.
+=end



Summary of changes:
 util/extract-translators.pl | 71 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 util/extract-translators.pl



More information about the gnucash-changes mailing list