3 # copied from webwml/english/po/wmlxgettext.pl and
4 # adapted for Template Toolkit
5 # Copyright © 2002-2003 Denis Barbier <barbier@debian.org>
6 # Copyright © 2007 Frank Lichtenheld <frank@lichtenheld.de>
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.
20 my $domain = shift @ARGV;
33 return ($text =~ s/\n//g);
39 my ($text, $lineno, $comment, $nextlineno, $msgid);
44 open(IN, "< $file") || die "Unable to open $file\n";
49 if ($prefix =~ s/=(.*)//) {
52 $file =~ s{^$prefix}{$repl}o unless $prefix eq '__';
53 # # Remove comments if they contain <gettext> or </gettext>
54 # $text =~ s/^[ \t]*#.*<\/?gettext\b//mg;
56 while ($text =~ m{\G(.*?) # begin at end of previous match, $1=prefix
57 (\bg\(\s* # "g(" , $2=whole match
58 (["']) # " quoting, $3=quotes
59 (.*?)\3 # string, $4=string
62 $lineno += countNewline ($1.$2);
63 $nextlineno = countNewline ($4);;
65 # my $dom = ($3) ? $3 : 'templates';
66 # if ($domain ne $dom) {
67 # $lineno += $nextlineno;
68 # next; # wrong domain
71 if ($1 =~ m/(((^|\n)\s*(\[%)?\s*#.*)+)\n?[^\n]*$/) {
75 $comment =~ s/^\s+#\s*//;
76 $comment =~ s/\n[ \t]*#\s*/\n/g;
78 push (@msgids, $msgid);
79 # if (defined ($messages->{$msgid})) {
80 # print STDERR "ttxgettext: Warning: msgid multiple defined:\n\t".
83 # $messages->{$msgid} = [];
85 push (@{$messages->{$msgid}}, $comment, $file, $lineno);
86 $lineno += $nextlineno;
94 processFile($_, $opt_p);
97 print "msgid \"\"\nmsgstr \"\"\n".
98 "\"Content-Type: text/plain; charset=UTF-8\\n\"\n".
99 "\"Content-Transfer-Encoding: 8bit\\n\"\n\n";
101 foreach my $msgid (@msgids) {
102 next unless $messages->{$msgid};
103 while (@{$messages->{$msgid}}) {
104 $_ = shift(@{$messages->{$msgid}});
106 print "#. ".$_."\n" if $_;
107 print "#: ".shift(@{$messages->{$msgid}}).":".
108 shift(@{$messages->{$msgid}})."\n";
110 print "msgid \"$msgid\"\nmsgstr \"\"\n\n";
111 undef $messages->{$msgid};