source: trunk/tools/convert_language_to_2.1.pl @ 5535

Last change on this file since 5535 was 5535, checked in by plg, 14 years ago

Fix missing keys: some keys have been removed by mistake during the massive
key conversion.

  • Property svn:eol-style set to LF
File size: 3.9 KB
Line 
1#!/usr/bin/perl
2
3# Here is the way I finally used this script:
4#
5# for language in ar_SA cz_CZ da_DK de_DE es_AR es_ES hr_HR hu_HU it_IT ja_JP nl_NL pl_PL pt_BR pt_PT ru_RU sr_RS vi_VN zh_CN
6# do
7#   export PWG_LANG=$language
8#   rm -rf language/$PWG_LANG
9#   cp -r ../branches/2.0/language/$PWG_LANG language/
10#   perl tools/convert_language_to_2.1.pl language/$PWG_LANG
11# done
12
13use strict;
14use warnings;
15
16my $language_dir = $ARGV[0];
17
18my @file_codes = qw/upgrade install admin common/;
19
20my %ignore_keys = (
21    'user_status_admin' => '',
22    'user_status_generic' => '',
23    'user_status_guest' => '',
24    'user_status_normal' => '',
25    'user_status_webmaster' => '',
26    'Level 0' => '',
27    'Level 1' => '',
28    'Level 2' => '',
29    'Level 4' => '',
30    'Level 8' => '',
31    'ACCESS_0' => '',
32    'ACCESS_1' => '',
33    'ACCESS_2' => '',
34    'ACCESS_3' => '',
35    'ACCESS_4' => '',
36    'ACCESS_5' => '',
37    'month' => '',
38    'day' => '',
39    'chronology_monthly_calendar' => '',
40    'chronology_monthly_list' => '',
41    'chronology_weekly_list' => '',
42);
43
44my %remove_keys = (
45    common => {
46        'You can\'t upload pictures in this category' => '',
47        'display pictures added on' => '',
48    },
49    admin => {
50        'nbm_content_goto_2' => '',
51        'nbm_content_hello_2' => '',
52        'nbm_redirect_msg' => '',
53
54        'username' => '',
55        'No tag defined. Use Administration>Pictures>Tags' => '',
56        'Remote site url must start by http or https and must only contain characters among "/", "a-zA-Z0-9", "-" or "_"' => '',
57        'path' => '',
58    },
59    upgrade => {
60        'Are you sure?' => '',
61    },
62);
63
64my %to_copy = ();
65
66# load the replacements
67my %replace_by = ();
68foreach my $file_code (@file_codes) {
69    open(my $ifh_rep, '<language/templates/'.$file_code.'.lang.php');
70    while (<$ifh_rep>) {
71        if (m/^\$lang\['(.*)'\] \s* = \s* (['"])(.*)\2;/x) {
72            if ($1 ne $3 and length($1) > 0) {
73                $replace_by{$1} = $3;
74            }
75        }
76    }
77}
78# use Data::Dumper; print Dumper(\%replace_by); exit();
79
80my $append_to_common = '';
81
82foreach my $file_code (@file_codes) {
83    my $filename = $language_dir.'/'.$file_code.'.lang.php';
84    print $filename;
85    if (not -f $filename) {
86        print ' is missing', "\n";
87        next;
88    }
89    print ' is under process', "\n";
90
91    if ($file_code eq 'admin') {
92        %to_copy = (
93            'Are you sure?' => '',
94            'Email address is missing. Please specify an email address.' => '',
95            'delete this comment' => '',
96            'validate this comment' => '',
97        );
98    }
99    else {
100        %to_copy = ();
101    }
102
103    my $file_content = '';
104    my $copy_content = '';
105
106    open(my $ifh, '<'.$language_dir.'/'.$file_code.'.lang.php');
107    while (my $line = <$ifh>) {
108        if ($line =~ m/^\$lang\['(.*)'\] \s* =/x) {
109            if (defined $remove_keys{$file_code}{$1}) {
110                next;
111            }
112            elsif (defined $ignore_keys{$1}) {
113                $file_content.= $line;
114            }
115            elsif (defined $to_copy{$1}) {
116                $append_to_common.= $line;
117            }
118            elsif (defined $replace_by{$1}) {
119                my $search = quotemeta($1);
120                my $replace = $replace_by{$1};
121
122                $line =~ s{$search}{$replace};
123
124                if (defined $to_copy{$replace}) {
125                    $append_to_common.= $line;
126                }
127                else {
128                    $file_content.= $line;
129                }
130            }
131            else {
132                $file_content.= $line;
133            }
134        }
135        elsif ($line =~ m/^?>/) {
136            if ('common' eq $file_code) {
137                $file_content.= $append_to_common;
138            }
139            $file_content.= $line;
140        }
141        else {
142            $file_content.= $line;
143        }
144    }
145    close($ifh);
146
147    open(my $ofh, '>'.$language_dir.'/'.$file_code.'.lang.php');
148    print {$ofh} $file_content;
149    close($ofh);
150}
Note: See TracBrowser for help on using the repository browser.