Revision 880bc0d2
Von Moritz Bunkus vor etwa 12 Jahren hinzugefügt
scripts/locales.pl | ||
---|---|---|
9 | 9 |
use utf8; |
10 | 10 |
use strict; |
11 | 11 |
|
12 |
use Carp; |
|
12 | 13 |
use Data::Dumper; |
13 | 14 |
use English; |
15 |
use File::Slurp qw(slurp); |
|
14 | 16 |
use FileHandle; |
15 | 17 |
use Getopt::Long; |
18 |
use IO::Dir; |
|
16 | 19 |
use List::Util qw(first); |
17 | 20 |
use POSIX; |
18 | 21 |
use Pod::Usage; |
19 |
use Carp; |
|
20 |
use File::Slurp qw(slurp); |
|
21 | 22 |
|
22 | 23 |
$OUTPUT_AUTOFLUSH = 1; |
23 | 24 |
|
... | ... | |
43 | 44 |
init(); |
44 | 45 |
|
45 | 46 |
sub find_files { |
46 |
my ($dir_name, $files) = @_;
|
|
47 |
my ($top_dir_name) = @_;
|
|
47 | 48 |
|
48 |
$files ||= [];
|
|
49 |
my (@files, $finder);
|
|
49 | 50 |
|
50 |
my @dirs_to_check; |
|
51 |
$finder = sub { |
|
52 |
my ($dir_name) = @_; |
|
51 | 53 |
|
52 |
opendir my $dir, $dir_name or die "$! $dir_name";
|
|
54 |
tie my %dir_h, 'IO::Dir', $dir_name;
|
|
53 | 55 |
|
54 |
foreach my $name (readdir $dir) {
|
|
55 |
next if $name eq '.' || $name eq '..';
|
|
56 |
push @files, grep { -f } map { "${dir_name}/${_}" } keys %dir_h;
|
|
57 |
my @sub_dirs = grep { -d } map { "${dir_name}/${_}" } grep { ! m/^\.\.?$/ } keys %dir_h;
|
|
56 | 58 |
|
57 |
my $full_name = "${dir_name}/${name}"; |
|
58 |
if (-d $full_name) { |
|
59 |
push @dirs_to_check, $full_name; |
|
60 |
} else { |
|
61 |
push @{ $files }, $full_name; |
|
62 |
} |
|
63 |
} |
|
59 |
$finder->($_) for @sub_dirs; |
|
60 |
}; |
|
64 | 61 |
|
65 |
closedir $dir;
|
|
62 |
$finder->($top_dir_name);
|
|
66 | 63 |
|
67 |
map { find_files($_, $files) } @dirs_to_check; |
|
68 |
|
|
69 |
return @{ $files }; |
|
64 |
return @files; |
|
70 | 65 |
} |
71 | 66 |
|
72 | 67 |
my @bindir_files = find_files($bindir); |
... | ... | |
76 | 71 |
push @progfiles, map { m:^(.+)/([^/]+)$:; [ $2, $1 ] } grep { /\.pm$/ } map { find_files($_) } @progdirs; |
77 | 72 |
|
78 | 73 |
# put customized files into @customfiles |
79 |
my @menufiles;
|
|
74 |
my (@menufiles, %dir_h);
|
|
80 | 75 |
|
81 | 76 |
if ($opt_n) { |
82 | 77 |
@customfiles = (); |
83 | 78 |
@menufiles = ($menufile); |
84 | 79 |
} else { |
85 |
opendir DIR, "$basedir" or die "$!"; |
|
86 |
@menufiles = grep { /.*?_$menufile$/ } readdir DIR; |
|
87 |
closedir DIR; |
|
80 |
tie %dir_h, 'IO::Dir', $basedir; |
|
81 |
@menufiles = grep { /.*?_$menufile$/ } keys %dir_h; |
|
88 | 82 |
unshift @menufiles, $menufile; |
89 | 83 |
} |
90 | 84 |
|
91 |
opendir DIR, $dbupdir or die "$!"; |
|
92 |
my @dbplfiles = grep { /\.pl$/ } readdir DIR; |
|
93 |
closedir DIR; |
|
85 |
tie %dir_h, 'IO::Dir', $dbupdir; |
|
86 |
my @dbplfiles = grep { /\.pl$/ } keys %dir_h; |
|
94 | 87 |
|
95 |
opendir DIR, $dbupdir2 or die "$!"; |
|
96 |
my @dbplfiles2 = grep { /\.pl$/ } readdir DIR; |
|
97 |
closedir DIR; |
|
88 |
tie %dir_h, 'IO::Dir', $dbupdir2; |
|
89 |
my @dbplfiles2 = grep { /\.pl$/ } keys %dir_h; |
|
98 | 90 |
|
99 | 91 |
# slurp the translations in |
100 | 92 |
our $self = {}; |
... | ... | |
119 | 111 |
|
120 | 112 |
my %old_texts = %{ $self->{texts} || {} }; |
121 | 113 |
|
122 |
map({ handle_file(@{ $_ }); } @progfiles);
|
|
123 |
map({ handle_file($_, $dbupdir); } @dbplfiles);
|
|
124 |
map({ handle_file($_, $dbupdir2); } @dbplfiles2);
|
|
114 |
handle_file(@{ $_ }) for @progfiles;
|
|
115 |
handle_file($_, $dbupdir) for @dbplfiles;
|
|
116 |
handle_file($_, $dbupdir2) for @dbplfiles2;
|
|
125 | 117 |
|
126 | 118 |
# generate all |
127 | 119 |
generate_file( |
... | ... | |
430 | 422 |
|
431 | 423 |
} |
432 | 424 |
|
433 |
map { $alllocales{$_} = 1 } keys %{$cached{$file}{all}}; |
|
434 |
map { $locale{$_} = 1 } keys %{$cached{$file}{locale}}; |
|
435 |
map { $submit{$_} = 1 } keys %{$cached{$file}{submit}}; |
|
436 |
map { &scanfile($_, 0, $scanned_files) } keys %{$cached{$file}{scan}}; |
|
437 |
map { &scanfile($_, 1, $scanned_files) } keys %{$cached{$file}{scannosubs}}; |
|
438 |
map { &scanhtmlfile($_) } keys %{$cached{$file}{scanh}}; |
|
425 |
$alllocales{$_} = 1 for keys %{$cached{$file}{all}}; |
|
426 |
$locale{$_} = 1 for keys %{$cached{$file}{locale}}; |
|
427 |
$submit{$_} = 1 for keys %{$cached{$file}{submit}}; |
|
428 |
|
|
429 |
scanfile($_, 0, $scanned_files) for keys %{$cached{$file}{scan}}; |
|
430 |
scanfile($_, 1, $scanned_files) for keys %{$cached{$file}{scannosubs}}; |
|
431 |
scanhtmlfile($_) for keys %{$cached{$file}{scanh}}; |
|
439 | 432 |
|
440 |
@referenced_html_files{keys %{$cached{$file}{scanh}}} = (1) x scalar keys %{$cached{$file}{scanh}};
|
|
433 |
$referenced_html_files{$_} = 1 for keys %{$cached{$file}{scanh}};
|
|
441 | 434 |
} |
442 | 435 |
|
443 | 436 |
sub scanmenu { |
... | ... | |
555 | 548 |
} |
556 | 549 |
|
557 | 550 |
# copy back into global arrays |
558 |
map { $alllocales{$_} = 1 } keys %{$cached{$file}{all}};
|
|
559 |
map { $locale{$_} = 1 } keys %{$cached{$file}{html}};
|
|
560 |
map { $submit{$_} = 1 } keys %{$cached{$file}{submit}};
|
|
551 |
$alllocales{$_} = 1 for keys %{$cached{$file}{all}};
|
|
552 |
$locale{$_} = 1 for keys %{$cached{$file}{html}};
|
|
553 |
$submit{$_} = 1 for keys %{$cached{$file}{submit}};
|
|
561 | 554 |
|
562 |
map { scanhtmlfile($_) } keys %{$cached{$file}{scanh}};
|
|
555 |
scanhtmlfile($_) for keys %{$cached{$file}{scanh}};
|
|
563 | 556 |
|
564 |
@referenced_html_files{keys %{$cached{$file}{scanh}}} = (1) x scalar keys %{$cached{$file}{scanh}};
|
|
557 |
$referenced_html_files{$_} = 1 for keys %{$cached{$file}{scanh}};
|
|
565 | 558 |
} |
566 | 559 |
|
567 | 560 |
sub search_unused_htmlfiles { |
Auch abrufbar als: Unified diff
Refactoring