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

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

lib/,src/Makefile.am,src/gettexttomsg.pl: Eliminate po_codes and just
store the message numbers as the line number in a fake source
reference to file 'n'.

  • Property mode set to 100755
File size: 2.7 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("survex.pot");
49my $first = 1;
50foreach my $po_entry (@{$num_list}) {
51    my $msgno = '';
52    my $ref = $po_entry->reference;
53    if (defined $ref && $ref =~ /^n:(\d+)$/m) {
54        $msgno = $1;
55    }
56    if ($first) {
57        $first = 0;
58        next if ($po_entry->msgid eq '""');
59    }
60    my $msg;
61    if (exists $msgs{$msgno}) {
62        $msg = $msgs{$msgno};
63        delete $msgs{$msgno};
64    } else {
65        print STDERR "Message number $msgno is in survex.pot but not found in source - preserving\n" unless $po_entry->obsolete;
66        $msg = $po_entry->dequote($po_entry->msgid);
67    }
68    if (defined $po_entry->automatic) {
69        my $automatic = "\n" . $po_entry->automatic;
70        $automatic =~ s/\n/\n#. /g;
71        while ($automatic =~ s/\n#. \n/\n#.\n/g) { }
72        print $automatic;
73    }
74    if ($msgno =~ /^\d+$/) {
75        for (@{$uses[$msgno]}) {
76            print "\n#: ", $_;
77        }
78        print "\n#: n:$msgno";
79    }
80    print "\n#, c-format" if $msg =~ /\%[a-z0-9]/;
81    if ($msg =~ s/(?:^|[^\\])"/\\"/g) {
82        print STDERR "Escaping unescaped \" in message number $msgno\n";
83    }
84    print "\n";
85    print "#~ " if $po_entry->obsolete;
86    print "msgid \"$msg\"\n";
87    print "#~ " if $po_entry->obsolete;
88    print "msgstr \"\"\n";
89}
90
91for my $msgno (sort keys %msgs) {
92    next if ($msgno == 0 || $msgno >= 1000);
93    print STDERR "New message number $msgno\n";
94    for (@{$uses[$msgno]}) {
95        print "\n#: ", $_;
96    }
97    my $msg = $msgs{$msgno};
98    print "\n#: n:$msgno";
99    print "\n#, c-format" if $msg =~ /\%[a-z0-9]/;
100    if ($msg =~ s/(?:^|[^\\])"/\\"/g) {
101        print STDERR "Escaping unescaped \" in message number $msgno\n";
102    }
103    print "\nmsgid \"$msg\"\n";
104    print "msgstr \"\"\n";
105}
Note: See TracBrowser for help on using the repository browser.