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 | # foreach my $key (sort keys %registered_keys) { |
---|
27 | # if (not defined $used_keys{$key}) { |
---|
28 | # print "{".$key."}", ' is not used anywhere', "\n"; |
---|
29 | # } |
---|
30 | # } |
---|
31 | |
---|
32 | sub used_keys { |
---|
33 | if ($File::Find::name !~ m/(tpl|php)$/) { |
---|
34 | return 0; |
---|
35 | } |
---|
36 | |
---|
37 | if ($File::Find::name =~ m{/(plugins|language|_data)/}) { |
---|
38 | return 0; |
---|
39 | } |
---|
40 | |
---|
41 | if ('upgrade' eq $type) { |
---|
42 | if ($File::Find::name !~ m{upgrade\.(tpl|php)$}) { |
---|
43 | return 0; |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | if ('install' eq $type) { |
---|
48 | if ($File::Find::name =~ m{upgrade\.(tpl|php)$}) { |
---|
49 | return 0; |
---|
50 | } |
---|
51 | if ($File::Find::name !~ m{/install(\.tpl|\.php|/)}) { |
---|
52 | return 0; |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | if ('admin' eq $type) { |
---|
57 | if ($File::Find::name =~ m{upgrade\.(tpl|php)$}) { |
---|
58 | return 0; |
---|
59 | } |
---|
60 | if ($File::Find::name =~ m{/install(\.tpl|\.php|/)}) { |
---|
61 | return 0; |
---|
62 | } |
---|
63 | |
---|
64 | my $is_admin = 0; |
---|
65 | |
---|
66 | if ($File::Find::name =~ m{themes/default/template/mail}) { |
---|
67 | $is_admin = 1; |
---|
68 | } |
---|
69 | if ($File::Find::name =~ m{/admin/}) { |
---|
70 | $is_admin = 1; |
---|
71 | } |
---|
72 | if ($File::Find::name =~ m{/admin\.php$}) { |
---|
73 | $is_admin = 1; |
---|
74 | } |
---|
75 | |
---|
76 | if (not $is_admin) { |
---|
77 | return 0; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | if ('common' eq $type) { |
---|
82 | if ($File::Find::name =~ m{upgrade\.(tpl|php)$}) { |
---|
83 | return 0; |
---|
84 | } |
---|
85 | if ($File::Find::name =~ m{/install(\.tpl|\.php|/)}) { |
---|
86 | return 0; |
---|
87 | } |
---|
88 | if ($File::Find::name =~ m{/admin(/|\.php)} or $File::Find::name =~ m{themes/default/template/mail}) { |
---|
89 | return 0; |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | if (-f) { |
---|
94 | open(my $fhi, '<', $File::Find::name); |
---|
95 | while (<$fhi>) { |
---|
96 | if ($File::Find::name =~ m/tpl$/) { |
---|
97 | while (m/\{(['"])(.+?)\1\|\@translate/g) { |
---|
98 | $used_keys{$2}++; |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | if ($File::Find::name =~ m/php$/) { |
---|
103 | while (m/l10n \s* \( \s* (['"]) (.+?) \1 \s* \)/xg) { |
---|
104 | $used_keys{$2}++; |
---|
105 | } |
---|
106 | |
---|
107 | while (m/l10n_args \s* \( \s* (['"]) (.+?) \1 \s* ,/xg) { |
---|
108 | $used_keys{$2}++; |
---|
109 | } |
---|
110 | |
---|
111 | while (m/l10n_dec \s* \( \s* (['"]) (.+?) \1 \s* ,\s* (['"]) (.+?) \3 \s* ,/xg) { |
---|
112 | $used_keys{$2}++; |
---|
113 | $used_keys{$4}++; |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | sub load_registered_keys { |
---|
121 | my ($type) = @_; |
---|
122 | |
---|
123 | my %files_for_type = ( |
---|
124 | common => [qw/common/], |
---|
125 | admin => [qw/common admin/], |
---|
126 | install => [qw/common admin install/], |
---|
127 | upgrade => [qw/common admin install upgrade/], |
---|
128 | ); |
---|
129 | |
---|
130 | foreach my $file_code (@{$files_for_type{$type}}) { |
---|
131 | my $filepath = $piwigo_dir.'/language/en_UK/'.$file_code.'.lang.php'; |
---|
132 | |
---|
133 | open(my $fhi, '<', $filepath); |
---|
134 | while (<$fhi>) { |
---|
135 | if (m/\$lang\[ \s* (['"]) (.+?) \1 \s* \]/x) { |
---|
136 | $registered_keys{$2}++; |
---|
137 | } |
---|
138 | } |
---|
139 | } |
---|
140 | } |
---|