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 | |
---|
13 | use strict; |
---|
14 | use warnings; |
---|
15 | |
---|
16 | my $language_dir = $ARGV[0]; |
---|
17 | |
---|
18 | my @file_codes = qw/upgrade install admin common/; |
---|
19 | |
---|
20 | my %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 | |
---|
44 | my %remove_keys = ( |
---|
45 | admin => { |
---|
46 | 'nbm_content_goto_2' => '', |
---|
47 | 'nbm_content_hello_2' => '', |
---|
48 | 'nbm_redirect_msg' => '', |
---|
49 | }, |
---|
50 | upgrade => { |
---|
51 | 'Are you sure?' => '', |
---|
52 | }, |
---|
53 | ); |
---|
54 | |
---|
55 | my %to_copy = (); |
---|
56 | |
---|
57 | # load the replacements |
---|
58 | my %replace_by = (); |
---|
59 | foreach my $file_code (@file_codes) { |
---|
60 | open(my $ifh_rep, '<language/templates/'.$file_code.'.lang.php'); |
---|
61 | while (<$ifh_rep>) { |
---|
62 | if (m/^\$lang\['(.*)'\] \s* = \s* (['"])(.*)\2;/x) { |
---|
63 | if ($1 ne $3 and length($1) > 0) { |
---|
64 | $replace_by{$1} = $3; |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|
69 | # use Data::Dumper; print Dumper(\%replace_by); exit(); |
---|
70 | |
---|
71 | my $append_to_common = ''; |
---|
72 | |
---|
73 | foreach my $file_code (@file_codes) { |
---|
74 | my $filename = $language_dir.'/'.$file_code.'.lang.php'; |
---|
75 | print $filename; |
---|
76 | if (not -f $filename) { |
---|
77 | print ' is missing', "\n"; |
---|
78 | next; |
---|
79 | } |
---|
80 | print ' is under process', "\n"; |
---|
81 | |
---|
82 | if ($file_code eq 'admin') { |
---|
83 | %to_copy = ( |
---|
84 | 'Are you sure?' => '', |
---|
85 | 'Email address is missing. Please specify an email address.' => '', |
---|
86 | 'delete this comment' => '', |
---|
87 | 'validate this comment' => '', |
---|
88 | ); |
---|
89 | } |
---|
90 | else { |
---|
91 | %to_copy = (); |
---|
92 | } |
---|
93 | |
---|
94 | my $file_content = ''; |
---|
95 | my $copy_content = ''; |
---|
96 | |
---|
97 | open(my $ifh, '<'.$language_dir.'/'.$file_code.'.lang.php'); |
---|
98 | while (my $line = <$ifh>) { |
---|
99 | if ($line =~ m/^\$lang\['(.*)'\] \s* =/x) { |
---|
100 | if (defined $remove_keys{$file_code}{$1}) { |
---|
101 | next; |
---|
102 | } |
---|
103 | elsif (defined $ignore_keys{$1}) { |
---|
104 | $file_content.= $line; |
---|
105 | } |
---|
106 | elsif (defined $to_copy{$1}) { |
---|
107 | $append_to_common.= $line; |
---|
108 | } |
---|
109 | elsif (defined $replace_by{$1}) { |
---|
110 | my $search = quotemeta($1); |
---|
111 | my $replace = $replace_by{$1}; |
---|
112 | |
---|
113 | $line =~ s{$search}{$replace}; |
---|
114 | |
---|
115 | if (defined $to_copy{$replace}) { |
---|
116 | $append_to_common.= $line; |
---|
117 | } |
---|
118 | else { |
---|
119 | $file_content.= $line; |
---|
120 | } |
---|
121 | } |
---|
122 | else { |
---|
123 | $file_content.= $line; |
---|
124 | } |
---|
125 | } |
---|
126 | elsif ($line =~ m/^?>/) { |
---|
127 | if ('common' eq $file_code) { |
---|
128 | $file_content.= $append_to_common; |
---|
129 | } |
---|
130 | $file_content.= $line; |
---|
131 | } |
---|
132 | else { |
---|
133 | $file_content.= $line; |
---|
134 | } |
---|
135 | } |
---|
136 | close($ifh); |
---|
137 | |
---|
138 | open(my $ofh, '>'.$language_dir.'/'.$file_code.'.lang.php'); |
---|
139 | print {$ofh} $file_content; |
---|
140 | close($ofh); |
---|
141 | } |
---|