]> git.deb.at Git - deb/packages.git/blob - bin/debtags-xgettext
Replace non working volatile mirror debian.domainmail.org with mirror.csclub.uwaterloo.ca
[deb/packages.git] / bin / debtags-xgettext
1 #! /usr/bin/perl -w
2
3 # copied from webwml/english/po/wmlxgettext.pl and
4 # changed to a crude intltool replacement
5 #  Copyright © 2002-2003  Denis Barbier <barbier@debian.org>
6 #  Copyright © 2007 Frank Lichtenheld <frank@lichtenheld.de>
7 #
8 #  This program is free software; you can redistribute it and/or modify
9 #  it under the terms of the GNU General Public License as published by
10 #  the Free Software Foundation; either version 2 of the License, or
11 #  (at your option) any later version.
12 use strict;
13
14 my $messages = {};
15 my @msgids = ();
16
17 sub escape {
18         my $text = shift;
19         $text =~ s/\\/\\\\/g;
20         $text =~ s/"/\\"/g;
21         $text =~ s/\n\s*\.\n\s?/\\n/g;
22         $text =~ s/\n  /\\n/g;
23         $text =~ s/\n//g;
24         $text =~ s/\t/\\t/g;
25         return $text;
26 }
27
28 sub processFile {
29         my $file = shift;
30         my ($text, $comment);
31         my (@messages) = ();
32         my (%msgids) = ();
33
34         open(IN, "<", $file) || die "Unable to open $file\n";
35         local ($/) = "";
36         while (<IN>) {
37             my %data = ();
38             chomp;
39             s/\n /\377/g;
40             while (/^(\S+):\s*(.*)\s*$/mg) {
41                 my ($key, $value) = ($1, $2);
42                 $value =~ s/\377/\n /g;
43                 $key =~ tr [A-Z] [a-z];
44                 $data{$key} = $value;
45             }
46             next unless $data{description};
47             my $comment = '';
48             if ($data{facet}) {
49                 $comment = "Facet: $data{facet}";
50             } elsif ($data{tag}) {
51                 $comment = "Tag: $data{tag}";
52             } else {
53                 die "Neither Facet nor Tag found.";
54             }
55
56             my ($short, $long) = split /\n/, $data{description}, 2;
57
58             $short = escape($short);
59             push (@msgids, $short);
60             push (@{$messages->{$short}}, $comment.", short desc", $file);
61
62             if ($long) {
63                 $long = escape($long);
64                 $long =~ s/^\s//;
65                 push (@msgids, $long);
66                 push (@{$messages->{$long}}, $comment.", long desc", $file);
67             }
68         }
69         close(IN);
70 }
71
72 foreach (@ARGV) {
73         processFile($_);
74 }
75
76 print "msgid \"\"\nmsgstr \"\"\n".
77         "\"Content-Type: text/plain; charset=UTF-8\\n\"\n".
78         "\"Content-Transfer-Encoding: 8bit\\n\"\n\n";
79
80 foreach my $msgid (@msgids) {
81         next unless $messages->{$msgid};
82         while (@{$messages->{$msgid}}) {
83                 $_ = shift(@{$messages->{$msgid}});
84                 s/\n/\n#. /g;
85                 print "#. ".$_."\n" if $_;
86                 print "#: ".shift(@{$messages->{$msgid}})."\n";
87         }
88         print "msgid \"$msgid\"\nmsgstr \"\"\n\n";
89         undef $messages->{$msgid};
90 }