1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | use File::Find; |
---|
7 | |
---|
8 | our %used_keys = (); |
---|
9 | our %registered_keys = (); |
---|
10 | |
---|
11 | my $piwigo_dir = $ARGV[0]; # '/home/pierrick/public_html/piwigo/dev/trunk'; |
---|
12 | my $type = $ARGV[1]; # common, admin, install, upgrade |
---|
13 | |
---|
14 | find(\&used_keys, $piwigo_dir); |
---|
15 | load_registered_keys($type); |
---|
16 | |
---|
17 | # foreach my $key (sort keys %used_keys) { |
---|
18 | # # print "{".$key."}", ' is used', "\n"; |
---|
19 | |
---|
20 | # if (not defined $registered_keys{$key}) { |
---|
21 | # # print "{".$key."}", ' is missing', "\n"; |
---|
22 | # print '$lang[\''.$key.'\'] = \''.$key.'\';', "\n"; |
---|
23 | # } |
---|
24 | # } |
---|
25 | |
---|
26 | my %ignore_keys = ( |
---|
27 | '%d new image' => 1, |
---|
28 | '%d new images' => 1, |
---|
29 | '%d category updated' => 1, |
---|
30 | '%d categories updated' => 1, |
---|
31 | '%d new comment' => 1, |
---|
32 | '%d new comments' => 1, |
---|
33 | '%d comment to validate' => 1, |
---|
34 | '%d comments to validate' => 1, |
---|
35 | '%d new user' => 1, |
---|
36 | '%d new users' => 1, |
---|
37 | '%d waiting element' => 1, |
---|
38 | '%d waiting elements' => 1, |
---|
39 | 'user_status_admin' => '', |
---|
40 | 'user_status_generic' => '', |
---|
41 | 'user_status_guest' => '', |
---|
42 | 'user_status_normal' => '', |
---|
43 | 'user_status_webmaster' => '', |
---|
44 | 'Level 0' => '', |
---|
45 | 'Level 1' => '', |
---|
46 | 'Level 2' => '', |
---|
47 | 'Level 4' => '', |
---|
48 | 'Level 8' => '', |
---|
49 | 'ACCESS_0' => '', |
---|
50 | 'ACCESS_1' => '', |
---|
51 | 'ACCESS_2' => '', |
---|
52 | 'ACCESS_3' => '', |
---|
53 | 'ACCESS_4' => '', |
---|
54 | 'ACCESS_5' => '', |
---|
55 | 'month' => '', |
---|
56 | 'day' => '', |
---|
57 | 'chronology_monthly_calendar' => '', |
---|
58 | 'chronology_monthly_list' => '', |
---|
59 | 'chronology_weekly_list' => '', |
---|
60 | 'public' => '', |
---|
61 | 'private' => '', |
---|
62 | 'none' => '', |
---|
63 | 'other' => '', |
---|
64 | 'high' => '', |
---|
65 | 'Waiting page: %s' => '', |
---|
66 | 'Admin: %s' => '', |
---|
67 | 'Manage this user comment: %s' => '', |
---|
68 | 'Main "guest" user does not exist' => '', |
---|
69 | 'Main "guest" user status is incorrect' => '', |
---|
70 | 'Main "webmaster" user does not exist' => '', |
---|
71 | 'Main "webmaster" user status is incorrect' => '', |
---|
72 | 'Default user does not exist' => '', |
---|
73 | '(!) This comment requires validation' => '', |
---|
74 | ); |
---|
75 | |
---|
76 | |
---|
77 | foreach my $key (sort keys %registered_keys) { |
---|
78 | if (not defined $used_keys{$key} and not defined $ignore_keys{$key}) { |
---|
79 | print "{".$key."}", ' is not used anywhere', "\n"; |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | sub used_keys { |
---|
84 | if ($File::Find::name !~ m/(tpl|php)$/) { |
---|
85 | return 0; |
---|
86 | } |
---|
87 | |
---|
88 | if ($File::Find::name =~ m{/(plugins|language|_data)/}) { |
---|
89 | return 0; |
---|
90 | } |
---|
91 | |
---|
92 | if ('upgrade' eq $type) { |
---|
93 | if ($File::Find::name !~ m{upgrade\.(tpl|php)$}) { |
---|
94 | # return 0; |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | if ('install' eq $type) { |
---|
99 | if ($File::Find::name =~ m{upgrade\.(tpl|php)$}) { |
---|
100 | return 0; |
---|
101 | } |
---|
102 | if ($File::Find::name !~ m{/install(\.tpl|\.php|/)}) { |
---|
103 | return 0; |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | if ('admin' eq $type) { |
---|
108 | if ($File::Find::name =~ m{upgrade\.(tpl|php)$}) { |
---|
109 | return 0; |
---|
110 | } |
---|
111 | if ($File::Find::name =~ m{/install(\.tpl|\.php|/)}) { |
---|
112 | return 0; |
---|
113 | } |
---|
114 | |
---|
115 | my $is_admin = 0; |
---|
116 | |
---|
117 | if ($File::Find::name =~ m{themes/default/template/mail}) { |
---|
118 | $is_admin = 1; |
---|
119 | } |
---|
120 | if ($File::Find::name =~ m{/admin/}) { |
---|
121 | $is_admin = 1; |
---|
122 | } |
---|
123 | if ($File::Find::name =~ m{/admin\.php$}) { |
---|
124 | $is_admin = 1; |
---|
125 | } |
---|
126 | |
---|
127 | if (not $is_admin) { |
---|
128 | return 0; |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | if ('common' eq $type) { |
---|
133 | if ($File::Find::name =~ m{upgrade\.(tpl|php)$}) { |
---|
134 | return 0; |
---|
135 | } |
---|
136 | if ($File::Find::name =~ m{/install(\.tpl|\.php|/)}) { |
---|
137 | return 0; |
---|
138 | } |
---|
139 | if ($File::Find::name =~ m{/admin(/|\.php)} or $File::Find::name =~ m{themes/default/template/mail}) { |
---|
140 | return 0; |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | if (-f) { |
---|
145 | my $big_string = ''; |
---|
146 | open(my $fhi, '<', $File::Find::name); |
---|
147 | while (<$fhi>) { |
---|
148 | chomp; |
---|
149 | s{//.*$}{}; |
---|
150 | $big_string.= $_; |
---|
151 | } |
---|
152 | close($fhi); |
---|
153 | |
---|
154 | while ($big_string =~ m/\{(['"])(.+?)\1\|\@translate/g) { |
---|
155 | $used_keys{$2}++; |
---|
156 | } |
---|
157 | |
---|
158 | while ($big_string =~ m/l10n \s* \( \s* (['"]) (.+?) \1 \s* \)/xg) { |
---|
159 | $used_keys{$2}++; |
---|
160 | } |
---|
161 | |
---|
162 | while ($big_string =~ m/l10n_args \s* \( \s* (['"]) (.+?) \1 \s* ,/xg) { |
---|
163 | $used_keys{$2}++; |
---|
164 | } |
---|
165 | |
---|
166 | while ($big_string =~ m/l10n_dec \s* \( \s* (['"]) (.+?) \1 \s* ,\s* (['"]) (.+?) \3 \s* ,/xg) { |
---|
167 | $used_keys{$2}++; |
---|
168 | $used_keys{$4}++; |
---|
169 | } |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | sub load_registered_keys { |
---|
174 | my ($type) = @_; |
---|
175 | |
---|
176 | my %files_for_type = ( |
---|
177 | common => [qw/common/], |
---|
178 | admin => [qw/common admin/], |
---|
179 | install => [qw/common admin install/], |
---|
180 | upgrade => [qw/common admin install upgrade/], |
---|
181 | ); |
---|
182 | |
---|
183 | foreach my $file_code (@{$files_for_type{$type}}) { |
---|
184 | my $filepath = $piwigo_dir.'/language/en_UK/'.$file_code.'.lang.php'; |
---|
185 | |
---|
186 | open(my $fhi, '<', $filepath); |
---|
187 | while (<$fhi>) { |
---|
188 | if (m/\$lang\[ \s* (['"]) (.+?) \1 \s* \]/x) { |
---|
189 | $registered_keys{$2}++; |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | } |
---|