[5286] | 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 | |
---|
[5296] | 11 | my $piwigo_dir = $ARGV[0]; # '/home/pierrick/public_html/piwigo/dev/trunk'; |
---|
| 12 | my $type = $ARGV[1]; # common, admin, install, upgrade |
---|
[5286] | 13 | |
---|
| 14 | find(\&used_keys, $piwigo_dir); |
---|
| 15 | load_registered_keys($type); |
---|
| 16 | |
---|
[5741] | 17 | # foreach my $key (sort keys %used_keys) { |
---|
| 18 | # # print "{".$key."}", ' is used', "\n"; |
---|
[5286] | 19 | |
---|
[5741] | 20 | # if (not defined $registered_keys{$key}) { |
---|
| 21 | # # print "{".$key."}", ' is missing', "\n"; |
---|
| 22 | # print '$lang[\''.$key.'\'] = \''.$key.'\';', "\n"; |
---|
| 23 | # } |
---|
| 24 | # } |
---|
[5510] | 25 | |
---|
| 26 | my %ignore_keys = ( |
---|
[8665] | 27 | '%d new photo' => 1, |
---|
| 28 | '%d new photos' => 1, |
---|
[5510] | 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' => '', |
---|
[5535] | 60 | 'public' => '', |
---|
| 61 | 'private' => '', |
---|
| 62 | 'none' => '', |
---|
| 63 | 'other' => '', |
---|
| 64 | 'high' => '', |
---|
| 65 | 'Waiting page: %s' => '', |
---|
[5559] | 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' => '', |
---|
[5510] | 74 | ); |
---|
| 75 | |
---|
| 76 | |
---|
[5741] | 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 | } |
---|
[5286] | 82 | |
---|
| 83 | sub used_keys { |
---|
| 84 | if ($File::Find::name !~ m/(tpl|php)$/) { |
---|
| 85 | return 0; |
---|
| 86 | } |
---|
| 87 | |
---|
[5296] | 88 | if ($File::Find::name =~ m{/(plugins|language|_data)/}) { |
---|
[5286] | 89 | return 0; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | if ('upgrade' eq $type) { |
---|
| 93 | if ($File::Find::name !~ m{upgrade\.(tpl|php)$}) { |
---|
[5510] | 94 | # return 0; |
---|
[5286] | 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 | } |
---|
[5296] | 123 | if ($File::Find::name =~ m{/admin\.php$}) { |
---|
| 124 | $is_admin = 1; |
---|
| 125 | } |
---|
[5286] | 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 | } |
---|
[5296] | 139 | if ($File::Find::name =~ m{/admin(/|\.php)} or $File::Find::name =~ m{themes/default/template/mail}) { |
---|
[5286] | 140 | return 0; |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | if (-f) { |
---|
[5510] | 145 | my $big_string = ''; |
---|
[5286] | 146 | open(my $fhi, '<', $File::Find::name); |
---|
| 147 | while (<$fhi>) { |
---|
[5510] | 148 | chomp; |
---|
| 149 | s{//.*$}{}; |
---|
| 150 | $big_string.= $_; |
---|
| 151 | } |
---|
| 152 | close($fhi); |
---|
[5286] | 153 | |
---|
[5510] | 154 | while ($big_string =~ m/\{(['"])(.+?)\1\|\@translate/g) { |
---|
| 155 | $used_keys{$2}++; |
---|
| 156 | } |
---|
[5286] | 157 | |
---|
[5510] | 158 | while ($big_string =~ m/l10n \s* \( \s* (['"]) (.+?) \1 \s* \)/xg) { |
---|
| 159 | $used_keys{$2}++; |
---|
| 160 | } |
---|
[5286] | 161 | |
---|
[5510] | 162 | while ($big_string =~ m/l10n_args \s* \( \s* (['"]) (.+?) \1 \s* ,/xg) { |
---|
| 163 | $used_keys{$2}++; |
---|
[5286] | 164 | } |
---|
[5510] | 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 | } |
---|
[5286] | 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 | } |
---|