build: update i18n-scan.pl, now reliably finds template and Lua i18n tokens
[project/luci.git] / build / i18n-html2lua.pl
1 #!/usr/bin/perl
2
3 @ARGV || die "Usage: $0 template1.htm [... templateN.htm]\n";
4
5
6 my %tags;
7
8 foreach my $file ( @ARGV )
9 {
10 if( open F, "< $file" )
11 {
12 local $/ = undef;
13
14 my $data = <F>;
15
16 while( $data =~ m/ <%: -? (\w+) (.*?) %> /sgx )
17 {
18 my ( $key, $val ) = ( $1, $2 );
19
20 if( $key && $val )
21 {
22 $val =~ s/\s+/ /sg;
23 $val =~ s/^\s+//;
24 $val =~ s/\s+$//;
25
26 $tags{$key} = $val;
27 }
28 else
29 {
30 $tags{$key} ||= '';
31 }
32 }
33
34 close F;
35 }
36 }
37
38 foreach my $key ( sort keys %tags )
39 {
40 if( $val =~ /'/ )
41 {
42 printf "%s = [[%s]]\n", $key, $tags{$key};
43 }
44 else
45 {
46 printf "%s = '%s'\n", $key, $tags{$key};
47 }
48 }