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 new values for given keys |
---|
10 | my %new_value_of = (); |
---|
11 | open(my $ifh_rep, '<'.$replacement_file); |
---|
12 | while (<$ifh_rep>) { |
---|
13 | if (m/^\$lang\['(.*)'\] \s* = \s* (.*);/x) { |
---|
14 | $new_value_of{$1} = $2; |
---|
15 | } |
---|
16 | } |
---|
17 | # use Data::Dumper; print Dumper(\%new_value_of); exit(); |
---|
18 | |
---|
19 | my %replacement_performed_for = (); |
---|
20 | |
---|
21 | foreach my $file_code (qw/upgrade install admin common plugin/) { |
---|
22 | my $filename = $language_dir.'/'.$file_code.'.lang.php'; |
---|
23 | # print $filename; |
---|
24 | if (not -f $filename) { |
---|
25 | # print ' is missing', "\n"; |
---|
26 | next; |
---|
27 | } |
---|
28 | print $filename.' is under process', "\n"; |
---|
29 | |
---|
30 | my $file_content = ''; |
---|
31 | |
---|
32 | open(my $ifh, '<'.$filename); |
---|
33 | while (my $line = <$ifh>) { |
---|
34 | if ($line =~ m/^\$lang\['(.*)'\] \s* =/x) { |
---|
35 | if (defined $new_value_of{$1}) { |
---|
36 | $file_content.= '$lang[\''.$1.'\'] = '.$new_value_of{$1}.';'."\n"; |
---|
37 | $replacement_performed_for{$1}++; |
---|
38 | } |
---|
39 | else { |
---|
40 | $file_content.= $line; |
---|
41 | } |
---|
42 | } |
---|
43 | elsif ($line =~ m/^?>/) { |
---|
44 | $file_content.= $line; |
---|
45 | } |
---|
46 | else { |
---|
47 | $file_content.= $line; |
---|
48 | } |
---|
49 | } |
---|
50 | close($ifh); |
---|
51 | |
---|
52 | open(my $ofh, '>'.$filename); |
---|
53 | print {$ofh} $file_content; |
---|
54 | close($ofh); |
---|
55 | } |
---|
56 | |
---|
57 | foreach my $new_value (keys %new_value_of) { |
---|
58 | if (not defined $replacement_performed_for{$new_value}) { |
---|
59 | print 'no replacement performed on: ', $new_value, "\n"; |
---|
60 | } |
---|
61 | } |
---|