]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/script/tpl_generate.pl
bweb: Add sqlite support
[bacula/bacula] / gui / bweb / script / tpl_generate.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 =head1 LICENSE
5
6    Bweb - A Bacula web interface
7    Bacula® - 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® 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ürich,
32    Switzerland, email:ftf@fsfeurope.org.
33
34 =head1 USAGE
35
36     cd bweb
37     rm -f lang/fr/tpl/*.tpl
38     LANGUAGE=fr ./script/tpl_generate.pl tpl/*.pl
39
40 =cut
41
42 my $debug=0;
43
44 my $lang = $ENV{LANGUAGE};
45
46 if (!$lang or $lang !~ /^[a-z]+$/) {
47     print "Can't find \$LANGUAGE, please set it before running $0 (to en, fr, it, es...)\n";
48     exit 0;
49 }
50
51 my $out = "lang/$lang/tpl";
52
53 die "Can't write to $out" unless (-d $out);
54
55 print "Using LANGUAGE=$lang and writing tpl to: $out\n";
56
57 use Locale::TextDomain ('bweb', './po/');
58 use File::Basename qw/basename/;
59
60 foreach my $f (@ARGV)
61 {
62     my $nb=0;
63     if (! -f $f) {
64         print STDERR "Skipping $f, file not found\n";
65         next;
66     }
67
68     my $file = basename($f);
69
70     open(FP, $f) or print STDERR "Can't open $f for reading $!\n";
71     open(OUT, ">$out/$file") or print STDERR "Can't open $out/$file for writing $!\n";
72     print "Converting $f -> $out/$file ";
73     while (my $l = <FP>)
74     {
75 #        $l =~ s:bresto.html:bresto.html<TMPL_IF cur_name>?dir=<TMPL_VAR cur_name></TMPL_IF>:;
76 #        $l =~ s:(href=['"](\w+.pl)?\?):${1}<TMPL_IF cur_name>dir=<TMPL_VAR cur_name>;</TMPL_IF>:g;
77 #        $l =~ s:(<form [^>]+>):$1<TMPL_IF cur_name><input type='hidden' name='dir' value='<TMPL_VAR cur_name>'></TMPL_IF>:g;
78         my (@str) = ($l =~ m/__(.+?)__/g);
79         
80         while (my $s = shift @str) {
81             $nb++;
82             my $r = __$s;
83
84             if ($debug) {
85                 print STDERR "$s -> $r\n";
86             }
87
88             $s =~ s/[?]/\\?/g;
89             $s =~ s/\$/\\\$/g;
90             $r =~ s/\$/\\\$/g;
91             $s =~ s/([\[\]\(\)])/\\$1/g;
92
93             $l =~ s/__${s}__/$r/g;
94         }
95         print OUT $l;
96     }
97     print "($nb strings)\n";
98     close(OUT);
99     close(FP);
100 }