]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/script/tpl_extract_msg.pl
bweb: Update some GPL2 notice to AGPL
[bacula/bacula] / gui / bweb / script / tpl_extract_msg.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 =head1 LICENSE
5
6    Bweb - A Bacula web interface
7    Bacula\81Â\81® - The Network Backup Solution
8
9    Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
10
11    The main author of Bweb is Eric Bollengier.
12    The main author of Bacula is Kern Sibbald, with contributions from
13    many others, a complete list can be found in the file AUTHORS.
14    This program is Free Software; you can redistribute it and/or
15    modify it under the terms of version three of the GNU Affero General Public
16    License as published by the Free Software Foundation and included
17    in the file LICENSE.
18
19    This program is distributed in the hope that it will be useful, but
20    WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22    Affero General Public License for more details.
23
24    You should have received a copy of the GNU Affero General Public License
25    along with this program; if not, write to the Free Software
26    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27    02110-1301, USA.
28
29    Bacula\81® is a registered trademark of Kern Sibbald.
30    The licensor of Bacula is the Free Software Foundation Europe
31    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Z\81ürich,
32    Switzerland, email:ftf@fsfeurope.org.
33
34 =head1 INFORMATIONS
35
36     This script is used to extract strings from tpl files
37
38 =cut
39
40 package TmplParser;
41 use base "HTML::Parser";
42 use HTML::Parser;
43 use Locale::PO;
44 my $in_script;
45
46 my %dict;
47 my $l=0;
48 my $file;
49
50 sub init_fp
51 {
52     open(FP, "|sort -n") ;
53 }
54
55 sub print_it
56 {
57     foreach my $w (@_) {
58 #       print "<$w\n";
59         next if ($w eq '&nbsp;');
60         next if ($w !~ /\w/);
61         next if ($w =~ />/);
62         next if ($w eq 'checked');
63 #       print "$w>\n";
64         next if (exists $dict{$w});
65         $dict{$w}=1;
66
67         # we add " at the begining and the end of the string
68         #$w =~ s/'/\\'/gm; # "
69         #print "s\@(?!value='|_)$w\@\$1_${w}_\@g;\n";
70         #print "s!(${w})([^a-zA-Z0-9]|\$)!__\$1__\$2!g;\n";
71         print "$w\n";
72     }
73 }
74
75 sub text {
76     my ($self, $text) = @_;
77     
78     # between <script>..</script> we take only "words"
79     if ($in_script) {
80         my @words = ($text =~ /"([\w\s\81é\81è\81à\81ç\81û\81ô\81ö\81ü\81ï\81î\81ù!?]+)"/gs);
81         print_it(@words);
82         return;
83     }
84
85     # just print out the original text
86 #    $text =~ s/<\/?TMPL[^>]+>//gs;
87
88     # strip extra spaces
89     $text =~ s/(^\s+)|(\s+$)//gs;
90
91     # skip some special cases
92     return if ($text eq 'selected');
93     print_it($text);
94 }
95
96 sub start {
97     my ($self, $tag, $attr, $attrseq, $origtext) = @_;
98
99     # On note qu'on se trouve dans un script
100     # pour prendre que les chaines entre ""
101     if ($tag eq 'script') {
102         $in_script = 1;
103     }
104
105     #return unless ($tag =~ /^(a|input|img)$/);
106
107     # liste des attributs a traduire
108     if (defined $attr->{'title'}) {
109         print_it($attr->{'title'});
110     }
111
112     if (defined $attr->{'alt'}) {
113         print_it($attr->{'alt'});
114     }
115 }
116
117 sub end {
118     if ($in_script) {
119         $in_script=0;
120     }
121 }
122
123 sub finish_fp
124 {
125     close(FP);
126 }
127 1;
128
129 package main;
130
131 my $p = new TmplParser;
132 $p->init_fp();
133 for (my $f = shift ; $f and -f $f ; $f = shift) {
134     #$TmplParser::nb=0;
135 #    print "#============ $f ==========\n";
136     $file = $f;
137     $file =~ s!.*?/([\w\d]+).tpl$!$1!;
138     $p->parse_file($f); $l=0;
139 }
140 $p->finish_fp();
141 #print "s/value='__([^']+)__'/value='\$1'/g;\n";