[fa56920] | 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 | for my $po_file (@ARGV) { |
---|
| 16 | my $todo = $po_file; |
---|
| 17 | if (!($todo =~ s/\.po$/.todo/)) { |
---|
| 18 | print STDERR "$po_file: doesn't end '.po'\n"; |
---|
| 19 | next; |
---|
| 20 | } |
---|
| 21 | my $po = Locale::PO->load_file_asarray($po_file); |
---|
| 22 | if (!defined $po) { |
---|
| 23 | print STDERR "$po_file: Bad!\n"; |
---|
| 24 | next; |
---|
| 25 | } |
---|
| 26 | my $c = 0; |
---|
| 27 | open TODO, '>', $todo or die $!; |
---|
| 28 | foreach my $po_entry (@{$po}) { |
---|
| 29 | my $msgid = $po_entry->msgid; |
---|
| 30 | my $msgstr = $po_entry->msgstr; |
---|
| 31 | ($msgid eq '""' || $msgstr eq '""' || $po_entry->fuzzy) or next; |
---|
| 32 | $msgstr =~ s/\\n(..)/\\n"\n"$1/g; |
---|
| 33 | if ($msgid eq '""') { |
---|
| 34 | print TODO "msgid $msgid\n"; |
---|
| 35 | print TODO "msgstr \"\"\n$msgstr\n"; |
---|
| 36 | next; |
---|
| 37 | } |
---|
| 38 | if (defined $po_entry->automatic) { |
---|
| 39 | my $automatic = "\n" . $po_entry->automatic; |
---|
| 40 | $automatic =~ s/\n/\n#. /g; |
---|
| 41 | while ($automatic =~ s/\n#. \n/\n#.\n/g) { } |
---|
| 42 | print TODO $automatic; |
---|
| 43 | } |
---|
| 44 | my $ref = $po_entry->reference; |
---|
| 45 | if (defined $ref) { |
---|
| 46 | $ref = "\n" . $ref; |
---|
| 47 | $ref =~ s/\n/\n#: /mg; |
---|
| 48 | print TODO $ref; |
---|
| 49 | } |
---|
| 50 | my $fuzzy = $po_entry->fuzzy; |
---|
| 51 | my $c_format = $po_entry->c_format; |
---|
| 52 | if ($fuzzy || $c_format) { |
---|
| 53 | print TODO "\n#"; |
---|
| 54 | print TODO ", fuzzy" if $fuzzy; |
---|
| 55 | print TODO ", c-format" if $c_format; |
---|
| 56 | } |
---|
| 57 | print TODO "\n"; |
---|
| 58 | print TODO "#~ " if $po_entry->obsolete; |
---|
| 59 | print TODO "msgid $msgid\n"; |
---|
| 60 | print TODO "#~ " if $po_entry->obsolete; |
---|
| 61 | print TODO "msgstr $msgstr\n"; |
---|
| 62 | ++$c; |
---|
| 63 | } |
---|
| 64 | close TODO or die $!; |
---|
| 65 | ($c == 0) and unlink $todo; |
---|
| 66 | } |
---|