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

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

lib/,src/Makefile.am,src/gettexttomsg.pl: Rename codes.po to po_codes
so it doesn't get picked up by tools looking for .po files. Add
survex.pot to the repo so launchpad's auto translation syncing can
work.

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