source: git/lib/extract-msgs.pl @ f8fa253

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since f8fa253 was f8fa253, checked in by Olly Betts <olly@…>, 11 years ago

lib/extract-msgs.pl,src/Makefile.am: Don't include version in
'Project-Id-Version'.

  • Property mode set to 100755
File size: 2.6 KB
Line 
1#!/usr/bin/perl -w
2require 5.008;
3use bytes;
4use strict;
5use POSIX;
6use Locale::PO;
7
8my $pot_creation_date = strftime "%Y-%m-%d %H:%M:%S +0000", gmtime();
9
10use integer;
11
12my (%msgs, @uses);
13while (<ARGV>) {
14    while (m!/\*(.*?)\*/(\d+)\b!g) {
15        my ($msg, $msgno) = ($1, $2);
16        if (exists $msgs{$msgno}) {
17            if ($msgs{$msgno} ne $msg) {
18                print STDERR "Mismatch for message number $msgno:\n";
19                print STDERR "$msgs{$msgno}\n$msg\n";
20            }
21        } else {
22            $msgs{$msgno} = $msg;
23        }
24        push @{$uses[$msgno]}, "$ARGV:$.";
25    }
26} continue {
27    # Reset $. for each input file.
28    close ARGV if eof;
29}
30
31print << "END";
32# Survex translation template.
33# Copyright (C) YEAR COPYRIGHT HOLDERS
34# This file is distributed under the same licence as Survex.
35#
36msgid ""
37msgstr ""
38"Project-Id-Version: survex\\n"
39"Report-Msgid-Bugs-To: olly\@survex.com\\n"
40"POT-Creation-Date: $pot_creation_date\\n"
41"PO-Revision-Date: YEAR-MO-DA HO:MI:SE +ZONE\\n"
42"Language-Team: LANGUAGE <LL\@li.org>\\n"
43"MIME-Version: 1.0\\n"
44"Content-Type: text/plain; charset=utf-8\\n"
45"Content-Transfer-Encoding: 8bit\\n"
46END
47
48my $num_list = Locale::PO->load_file_asarray("po_codes");
49my $first = 1;
50foreach my $po_entry (@{$num_list}) {
51    my $msgno = $po_entry->dequote($po_entry->msgstr);
52    if ($first) {
53        $first = 0;
54        next if ($po_entry->msgid eq '""');
55    }
56    my $msg;
57    if (exists $msgs{$msgno}) {
58        $msg = $msgs{$msgno};
59        delete $msgs{$msgno};
60    } else {
61        print STDERR "Message number $msgno is in po_codes but not found in source - preserving\n" unless $po_entry->obsolete;
62        $msg = $po_entry->dequote($po_entry->msgid);
63    }
64    if (defined $po_entry->automatic) {
65        my $automatic = "\n" . $po_entry->automatic;
66        $automatic =~ s/\n/\n#. /g;
67        while ($automatic =~ s/\n#. \n/\n#.\n/g) { }
68        print $automatic;
69    }
70    if ($msgno =~ /^\d+$/) {
71        for (@{$uses[$msgno]}) {
72            print "\n#: ", $_;
73        }
74    }
75    print "\n#, c-format" if $msg =~ /\%[a-z0-9]/;
76    if ($msg =~ s/(?:^|[^\\])"/\\"/g) {
77        print STDERR "Escaping unescaped \" in message number $msgno\n";
78    }
79    print "\n";
80    print "#~ " if $po_entry->obsolete;
81    print "msgid \"$msg\"\n";
82    print "#~ " if $po_entry->obsolete;
83    print "msgstr \"$msgno\"\n";
84}
85
86for my $msgno (sort keys %msgs) {
87    next if ($msgno == 0 || $msgno >= 1000);
88    print STDERR "New message number $msgno\n";
89    for (@{$uses[$msgno]}) {
90        print "\n#: ", $_;
91    }
92    my $msg = $msgs{$msgno};
93    print "\n#, c-format" if $msg =~ /\%[a-z0-9]/;
94    if ($msg =~ s/(?:^|[^\\])"/\\"/g) {
95        print STDERR "Escaping unescaped \" in message number $msgno\n";
96    }
97    print "\nmsgid \"$msg\"\n";
98    print "msgstr \"$msgno\"\n";
99}
Note: See TracBrowser for help on using the repository browser.