source: trunk/tools/replace_language_values.pl @ 7026

Last change on this file since 7026 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.5 KB
RevLine 
[7026]1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6my $replacement_file = $ARGV[0];
7my $language_dir = $ARGV[1];
8
9# load the new values for given keys
10my %new_value_of = ();
11open(my $ifh_rep, '<'.$replacement_file);
12while (<$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
19my %replacement_performed_for = ();
20
21foreach 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
57foreach 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}
Note: See TracBrowser for help on using the repository browser.