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 $pot = Locale::PO->load_file_asarray("survex.pot"); |
---|
16 | for my $po_file (@ARGV) { |
---|
17 | my $po = Locale::PO->load_file_ashash($po_file); |
---|
18 | if (!defined $po) { |
---|
19 | print STDERR "$po_file: Bad!\n"; |
---|
20 | next; |
---|
21 | } |
---|
22 | open NEW, '>', "$po_file.tmp" or die $!; |
---|
23 | foreach my $pot_entry (@{$pot}) { |
---|
24 | my $msgid = $pot_entry->msgid; |
---|
25 | my $msgstr = '""'; |
---|
26 | my $po_entry; |
---|
27 | if (exists $$po{$msgid}) { |
---|
28 | $po_entry = $$po{$msgid}; |
---|
29 | $msgstr = $po_entry->msgstr; |
---|
30 | delete $$po{$msgid}; |
---|
31 | if ($msgid eq '""') { |
---|
32 | $msgstr =~ s/\\n(..)/\\n"\n"$1/g; |
---|
33 | print NEW "msgid $msgid\nmsgstr \"\"\n$msgstr\n"; |
---|
34 | next; |
---|
35 | } |
---|
36 | } else { |
---|
37 | $po_entry = $pot_entry; |
---|
38 | } |
---|
39 | if (defined $pot_entry->automatic) { |
---|
40 | my $automatic = "\n" . $pot_entry->automatic; |
---|
41 | $automatic =~ s/\n/\n#. /g; |
---|
42 | while ($automatic =~ s/\n#. \n/\n#.\n/g) { } |
---|
43 | print NEW $automatic; |
---|
44 | } |
---|
45 | my $ref = $pot_entry->reference; |
---|
46 | if (defined $ref) { |
---|
47 | $ref = "\n" . $ref; |
---|
48 | $ref =~ s/\n/\n#: /mg; |
---|
49 | print NEW $ref; |
---|
50 | } |
---|
51 | my $fuzzy = $po_entry->fuzzy; |
---|
52 | my $c_format = $pot_entry->c_format; |
---|
53 | if ($fuzzy || $c_format) { |
---|
54 | print NEW "\n#"; |
---|
55 | print NEW ", fuzzy" if $fuzzy; |
---|
56 | print NEW ", c-format" if $c_format; |
---|
57 | } |
---|
58 | print NEW "\n"; |
---|
59 | print NEW "#~ " if $pot_entry->obsolete; |
---|
60 | print NEW "msgid $msgid\n"; |
---|
61 | print NEW "#~ " if $pot_entry->obsolete; |
---|
62 | print NEW "msgstr $msgstr\n"; |
---|
63 | } |
---|
64 | close NEW or die $!; |
---|
65 | unlink "$po_file.old"; |
---|
66 | for (sort keys %{$po}) { |
---|
67 | my $msgstr = $$po{$_}->msgstr; |
---|
68 | if ($msgstr ne '""') { |
---|
69 | print "$po_file: Dropping [$_] -> [$msgstr]\n"; |
---|
70 | } |
---|
71 | } |
---|
72 | link $po_file, "$po_file.old" or die $!; |
---|
73 | rename "$po_file.tmp", $po_file or die $!; |
---|
74 | } |
---|