| 1 | #!/usr/bin/perl -w
|
|---|
| 2 | require 5.008;
|
|---|
| 3 | use bytes;
|
|---|
| 4 | use strict;
|
|---|
| 5 | use POSIX;
|
|---|
| 6 | use Locale::PO;
|
|---|
| 7 |
|
|---|
| 8 | use integer;
|
|---|
| 9 |
|
|---|
| 10 | if (@ARGV == 0 || $ARGV[0] eq '--help') {
|
|---|
| 11 | print STDERR "Syntax: $0 PO_FILE...\n";
|
|---|
| 12 | exit (@ARGV != 0);
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | my @nonempty;
|
|---|
| 16 | for my $po_file (@ARGV) {
|
|---|
| 17 | my $todo = $po_file;
|
|---|
| 18 | if (!($todo =~ s/\.po$/.todo/)) {
|
|---|
| 19 | print STDERR "$po_file: doesn't end '.po'\n";
|
|---|
| 20 | next;
|
|---|
| 21 | }
|
|---|
| 22 | my $po = Locale::PO->load_file_asarray($po_file);
|
|---|
| 23 | if (!defined $po) {
|
|---|
| 24 | print STDERR "$po_file: Bad!\n";
|
|---|
| 25 | next;
|
|---|
| 26 | }
|
|---|
| 27 | my $c = 0;
|
|---|
| 28 | open TODO, '>', $todo or die $!;
|
|---|
| 29 | foreach my $po_entry (@{$po}) {
|
|---|
| 30 | my $msgid = $po_entry->msgid;
|
|---|
| 31 | my $msgstr = $po_entry->msgstr;
|
|---|
| 32 | ($msgid eq '""' || $msgstr eq '""' || $po_entry->fuzzy) or next;
|
|---|
| 33 | $msgstr =~ s/\\n(..)/\\n"\n"$1/g;
|
|---|
| 34 | if ($msgid eq '""') {
|
|---|
| 35 | print TODO "msgid $msgid\n";
|
|---|
| 36 | print TODO "msgstr \"\"\n$msgstr\n";
|
|---|
| 37 | next;
|
|---|
| 38 | }
|
|---|
| 39 | if (defined $po_entry->automatic) {
|
|---|
| 40 | my $automatic = "\n" . $po_entry->automatic;
|
|---|
| 41 | $automatic =~ s/\n/\n#. /g;
|
|---|
| 42 | while ($automatic =~ s/\n#. \n/\n#.\n/g) { }
|
|---|
| 43 | print TODO $automatic;
|
|---|
| 44 | }
|
|---|
| 45 | my $ref = $po_entry->reference;
|
|---|
| 46 | if (defined $ref) {
|
|---|
| 47 | $ref = "\n" . $ref;
|
|---|
| 48 | $ref =~ s/\n/\n#: /mg;
|
|---|
| 49 | print TODO $ref;
|
|---|
| 50 | }
|
|---|
| 51 | my $fuzzy = $po_entry->fuzzy;
|
|---|
| 52 | my $c_format = $po_entry->c_format;
|
|---|
| 53 | if ($fuzzy || $c_format) {
|
|---|
| 54 | print TODO "\n#";
|
|---|
| 55 | print TODO ", fuzzy" if $fuzzy;
|
|---|
| 56 | print TODO ", c-format" if $c_format;
|
|---|
| 57 | }
|
|---|
| 58 | print TODO "\n";
|
|---|
| 59 | print TODO "#~ " if $po_entry->obsolete;
|
|---|
| 60 | print TODO "msgid $msgid\n";
|
|---|
| 61 | print TODO "#~ " if $po_entry->obsolete;
|
|---|
| 62 | print TODO "msgstr $msgstr\n";
|
|---|
| 63 | ++$c;
|
|---|
| 64 | }
|
|---|
| 65 | close TODO or die $!;
|
|---|
| 66 | if ($c > 0) {
|
|---|
| 67 | push @nonempty, $todo;
|
|---|
| 68 | } else {
|
|---|
| 69 | unlink $todo;
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | my $host = 'atreus.tartarus.org';
|
|---|
| 74 | my $webpath = '/srv/www/survex.com/software/i18n';
|
|---|
| 75 |
|
|---|
| 76 | print "To update the files on the webserver:\n";
|
|---|
| 77 | if (@nonempty) {
|
|---|
| 78 | print "rsync -av --delete-after *.todo '$host:$webpath/'\n";
|
|---|
| 79 | } else {
|
|---|
| 80 | print "ssh $host rm '$webpath/*.todo'\n";
|
|---|
| 81 | }
|
|---|