source: git/lib/merge-po@ 613028c

RELEASE/1.2 debug-ci debug-ci-sanitisers faster-cavernlog log-select main stereo stereo-2025 walls-data walls-data-hanging-as-warning warn-only-for-hanging-survey
Last change on this file since 613028c was df126137, checked in by Olly Betts <olly@…>, 13 years ago

lib/Makefile.am,lib/merge-po: Add "merge-pos" target to merge in new
messages and updates to comments from survex.pot to the .po files.

  • Property mode set to 100755
File size: 1.8 KB
RevLine 
[df126137]1#!/usr/bin/perl -w
2require 5.008;
3use bytes;
4use strict;
5use POSIX;
6use Locale::PO;
7
8use integer;
9
10if (@ARGV == 0 || $ARGV[0] eq '--help') {
11 print STDERR "Syntax: $0 PO_FILE...\n";
12 exit (@ARGV != 0);
13}
14
15my $pot = Locale::PO->load_file_asarray("survex.pot");
16for 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}
Note: See TracBrowser for help on using the repository browser.