]> git.deb.at Git - deb/packages.git/blob - bin/debtags-xgettext
setup-site: Various improvements
[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/\\n/g;
22         $text =~ s/\t/\\t/g;
23         return $text;
24 }
25
26 sub processFile {
27         my $file = shift;
28         my ($text, $comment);
29         my (@messages) = ();
30         my (%msgids) = ();
31
32         open(IN, "<", $file) || die "Unable to open $file\n";
33         local ($/) = "";
34         while (<IN>) {
35             my %data = ();
36             chomp;
37             s/\n /\377/g;
38             while (/^(\S+):\s*(.*)\s*$/mg) {
39                 my ($key, $value) = ($1, $2);
40                 $value =~ s/\377/\n /g;
41                 $key =~ tr [A-Z] [a-z];
42                 $data{$key} = $value;
43             }
44             next unless $data{description};
45             my $comment = '';
46             if ($data{facet}) {
47                 $comment = "Facet: $data{facet}";
48             } elsif ($data{tag}) {
49                 $comment = "Tag: $data{tag}";
50             } else {
51                 die "Neither Facet nor Tag found.";
52             }
53
54             my ($short, $long) = split /\n/, $data{description}, 2;
55
56             $short = escape($short);
57             push (@msgids, $short);
58             push (@{$messages->{$short}}, $comment.", short desc", $file);
59
60             if ($long) {
61                 $long = escape($long);
62                 push (@msgids, $long);
63                 push (@{$messages->{$long}}, $comment.", long desc", $file);
64             }
65         }
66         close(IN);
67 }
68
69 foreach (@ARGV) {
70         processFile($_);
71 }
72
73 print "msgid \"\"\nmsgstr \"\"\n".
74         "\"Content-Type: text/plain; charset=UTF-8\\n\"\n".
75         "\"Content-Transfer-Encoding: 8bit\\n\"\n\n";
76
77 foreach my $msgid (@msgids) {
78         next unless $messages->{$msgid};
79         while (@{$messages->{$msgid}}) {
80                 $_ = shift(@{$messages->{$msgid}});
81                 s/\n/\n#. /g;
82                 print "#. ".$_."\n" if $_;
83                 print "#: ".shift(@{$messages->{$msgid}})."\n";
84         }
85         print "msgid \"$msgid\"\nmsgstr \"\"\n\n";
86         undef $messages->{$msgid};
87 }