Last change
on this file since 11493 was
5612,
checked in by plg, 15 years ago
|
Here comes a beta script to convert language keys in a set of 2.0 *.tpl files.
Backup your *.tpl directory first.
|
-
Property svn:eol-style set to
LF
|
File size:
1.1 KB
|
Line | |
---|
1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # perl tools/convert_template_to_2.1.pl /path/to/tpl/files/directory |
---|
4 | |
---|
5 | use strict; |
---|
6 | use warnings; |
---|
7 | |
---|
8 | use File::Find; |
---|
9 | |
---|
10 | my $base_dir = $ARGV[0]; |
---|
11 | |
---|
12 | # load the replacements |
---|
13 | my @file_codes = qw/upgrade install admin common/; |
---|
14 | my %replace_by = (); |
---|
15 | foreach my $file_code (@file_codes) { |
---|
16 | open(my $ifh_rep, '<language/templates/'.$file_code.'.lang.php'); |
---|
17 | while (<$ifh_rep>) { |
---|
18 | if (m/^\$lang\['(.*)'\] \s* = \s* (['"])(.*)\2;/x) { |
---|
19 | if ($1 ne $3 and length($1) > 0) { |
---|
20 | $replace_by{$1} = $3; |
---|
21 | } |
---|
22 | } |
---|
23 | } |
---|
24 | } |
---|
25 | # use Data::Dumper; print Dumper(\%replace_by); exit(); |
---|
26 | |
---|
27 | find(\&replace_keys, $base_dir); |
---|
28 | |
---|
29 | sub replace_keys { |
---|
30 | if ($File::Find::name !~ m/tpl$/) { |
---|
31 | return 0; |
---|
32 | } |
---|
33 | |
---|
34 | my $file_content = ''; |
---|
35 | open(my $fhi, '<', $File::Find::name); |
---|
36 | while (<$fhi>) { |
---|
37 | foreach my $from (keys %replace_by) { |
---|
38 | my $to = $replace_by{$from}; |
---|
39 | s/{'$from'\|\@translate/{'$to'|\@translate/g; |
---|
40 | } |
---|
41 | $file_content.= $_; |
---|
42 | } |
---|
43 | close($fhi); |
---|
44 | |
---|
45 | open(my $fho, '>', $File::Find::name); |
---|
46 | print {$fho} $file_content; |
---|
47 | close($fho); |
---|
48 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.