1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#!/usr/bin/perl
#
# tmplgettext <regexp> <directories>
#
# Creates a gettext pot-template from any text template specified by <regexp>
# in <directories> (recursivly)
#
# Any text matching /<%! (.*) !%>/ (even across multiple lines) will be
# interpreted as a translatable strings like in gettext("foo") or _("foo").
#
# e.g.: tmplgettext "^.*\.html$" ./templates >templates.pot
#
# Output goes to stdout.
#
# 04/2005 - Tobias Grimm <vdr@e-tobi.net>
#
my $BASENAME;
BEGIN {
$BASENAME = $1;
unshift(@INC, $BASENAME . "../tools/lib/");
}
use String::Escape qw(printable);
use File::Find;
my $START_TAG = "<%! ";
my $END_TAG = " !%>";
my $filePattern = "";
sub WritePotHeader
{
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);
print "#
# Translators, if you are not familiar with the PO format, gettext
# documentation is worth reading, especially sections dedicated to
# this format, e.g. by running:
# info -n '(gettext)PO Files'
# info -n '(gettext)Header Entry'
#
# Some information specific to po-debconf are available at
# /usr/share/doc/po-debconf/README-trans
# or http://www.debian.org/intl/l10n/po-debconf/README-trans
#
# Developers do not need to manually edit POT or PO files.
#
#, fuzzy
msgid \"\"
msgstr \"\"
\"Project-Id-Version: VDRAdmin-0.97-AM3.3\\n\"
\"Report-Msgid-Bugs-To: Andreas Mair <mail@andreas.vdr-developer.org>\\n\"\n";
# FIXME: Correctly set timezone
printf "\"POT-Creation-Date: %4d-%02d-%02d %02d:%02d+0100\"\n",
$year + 1900, $mon + 1, $mday, $hour, $min;
print "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"
\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"
\"Language-Team: LANGUAGE <LL@li.org>\\n\"
\"MIME-Version: 1.0\\n\"
\"Content-Type: text/plain; charset=CHARSET\\n\"
\"Content-Transfer-Encoding: 8bit\\n\"\n\n";
}
sub my_normalize {
my $text = shift;
$text =~ s/[\t\n]//g;
return printable($text);
}
sub WritePotEntry
{
my ($fileName, $lineNumber, $msgid) = @_;
my $escapedMsgid = my_normalize($msgid);
print "#: $fileName:$lineNumber\n";
print "msgid \"$escapedMsgid\"\n";
print "msgstr \"\"\n\n";
}
sub ExtractMsgids
{
my ($fileName, @fileContent) = @_;
my $text = "";
my $isTextStarted = 0;
my $lineCounter = 0;
my $textStartLine;
foreach my $line (@fileContent)
{
my $lookAhead;
$lineCounter++;
if ($isTextStarted = 1)
{
$text = $text . "\n";
}
for (my $index=0; $index < length($line); $index++)
{
$lookAhead = substr($line, $index, length($START_TAG));
if ($lookAhead eq $START_TAG)
{
$index = $index + length($START_TAG); # skip whole tag
$isTextStarted = 1;
$textStartLine = $lineCounter;
$text = "";
}
$lookAhead = substr($line, $index, length($END_TAG));
if ($lookAhead eq $END_TAG)
{
if ($isTextStarted)
{
$index = $index + length($END_TAG); # skip whole tag
if (length($text) > 0)
{
WritePotEntry($fileName, $textStartLine, $text);
}
$isTextStarted = 0;
}
}
if ($isTextStarted)
{
$text = $text . substr($line, $index, 1);
}
}
}
}
sub ProcessFile
{
if ($File::Find::name =~ /$filePattern/)
{
open(HTML, "< $File::Find::name");
my @fileContent = <HTML>;
close(HTML);
ExtractMsgids($File::Find::name, @fileContent);
}
}
#
# main()
#
$filePattern = shift(@ARGV);
WritePotHeader;
find({no_chdir => 1, wanted => \&ProcessFile}, @ARGV);
|