X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=bin%2Fdebtags-xgettext;fp=bin%2Fdebtags-xgettext;h=a7f718b39d421fd80d8d68948b2de4e1a2a18b05;hb=8ac8fa1f369ab0073709518ec2a8d44aa859afcf;hp=0000000000000000000000000000000000000000;hpb=4fe4646140ff04d6b69e2932bcb3591da17e8f5a;p=deb%2Fpackages.git diff --git a/bin/debtags-xgettext b/bin/debtags-xgettext new file mode 100755 index 0000000..a7f718b --- /dev/null +++ b/bin/debtags-xgettext @@ -0,0 +1,87 @@ +#! /usr/bin/perl -w + +# copied from webwml/english/po/wmlxgettext.pl and +# changed to a crude intltool replacement +# Copyright © 2002-2003 Denis Barbier +# Copyright © 2007 Frank Lichtenheld +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +use strict; + +my $messages = {}; +my @msgids = (); + +sub escape { + my $text = shift; + $text =~ s/\\/\\\\/g; + $text =~ s/"/\\"/g; + $text =~ s/\n/\\n/g; + $text =~ s/\t/\\t/g; + return $text; +} + +sub processFile { + my $file = shift; + my ($text, $comment); + my (@messages) = (); + my (%msgids) = (); + + open(IN, "<", $file) || die "Unable to open $file\n"; + local ($/) = ""; + while () { + my %data = (); + chomp; + s/\n /\377/g; + while (/^(\S+):\s*(.*)\s*$/mg) { + my ($key, $value) = ($1, $2); + $value =~ s/\377/\n /g; + $key =~ tr [A-Z] [a-z]; + $data{$key} = $value; + } + next unless $data{description}; + my $comment = ''; + if ($data{facet}) { + $comment = "Facet: $data{facet}"; + } elsif ($data{tag}) { + $comment = "Tag: $data{tag}"; + } else { + die "Neither Facet nor Tag found."; + } + + my ($short, $long) = split /\n/, $data{description}, 2; + + $short = escape($short); + push (@msgids, $short); + push (@{$messages->{$short}}, $comment.", short desc", $file); + + if ($long) { + $long = escape($long); + push (@msgids, $long); + push (@{$messages->{$long}}, $comment.", long desc", $file); + } + } + close(IN); +} + +foreach (@ARGV) { + processFile($_); +} + +print "msgid \"\"\nmsgstr \"\"\n". + "\"Content-Type: text/plain; charset=UTF-8\\n\"\n". + "\"Content-Transfer-Encoding: 8bit\\n\"\n\n"; + +foreach my $msgid (@msgids) { + next unless $messages->{$msgid}; + while (@{$messages->{$msgid}}) { + $_ = shift(@{$messages->{$msgid}}); + s/\n/\n#. /g; + print "#. ".$_."\n" if $_; + print "#: ".shift(@{$messages->{$msgid}})."\n"; + } + print "msgid \"$msgid\"\nmsgstr \"\"\n\n"; + undef $messages->{$msgid}; +}