Last change
on this file since 8068 was
7026,
checked in by plg, 14 years ago
|
feature 1616: add a tool to replace language keys from a mapping file + replace values from a template file
|
File size:
1.4 KB
|
Line | |
---|
1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | my $replacement_file = $ARGV[0]; |
---|
7 | my $language_dir = $ARGV[1]; |
---|
8 | |
---|
9 | # load the replacements |
---|
10 | my %replace_by = (); |
---|
11 | open(my $ifh_rep, '<'.$replacement_file); |
---|
12 | while (<$ifh_rep>) { |
---|
13 | if (m/^\$lang\['(.*)'\] \s* = \s* (['"])(.*)\2;/x) { |
---|
14 | if ($1 ne $3 and length($1) > 0) { |
---|
15 | $replace_by{$1} = $3; |
---|
16 | } |
---|
17 | } |
---|
18 | } |
---|
19 | # use Data::Dumper; print Dumper(\%replace_by); exit(); |
---|
20 | |
---|
21 | my $append_to_common = ''; |
---|
22 | |
---|
23 | foreach my $file_code (qw/upgrade install admin common plugin/) { |
---|
24 | my $filename = $language_dir.'/'.$file_code.'.lang.php'; |
---|
25 | # print $filename; |
---|
26 | if (not -f $filename) { |
---|
27 | # print ' is missing', "\n"; |
---|
28 | next; |
---|
29 | } |
---|
30 | print $filename.' is under process', "\n"; |
---|
31 | |
---|
32 | my $file_content = ''; |
---|
33 | |
---|
34 | open(my $ifh, '<'.$filename); |
---|
35 | while (my $line = <$ifh>) { |
---|
36 | if ($line =~ m/^\$lang\['(.*)'\] \s* =/x) { |
---|
37 | if (defined $replace_by{$1}) { |
---|
38 | my $search = quotemeta($1); |
---|
39 | my $replace = $replace_by{$1}; |
---|
40 | |
---|
41 | $line =~ s{$search}{$replace}; |
---|
42 | $file_content.= $line; |
---|
43 | } |
---|
44 | else { |
---|
45 | $file_content.= $line; |
---|
46 | } |
---|
47 | } |
---|
48 | elsif ($line =~ m/^?>/) { |
---|
49 | $file_content.= $line; |
---|
50 | } |
---|
51 | else { |
---|
52 | $file_content.= $line; |
---|
53 | } |
---|
54 | } |
---|
55 | close($ifh); |
---|
56 | |
---|
57 | open(my $ofh, '>'.$filename); |
---|
58 | print {$ofh} $file_content; |
---|
59 | close($ofh); |
---|
60 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.