line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2007-2018 by [Mark Overmeer ]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
5
|
|
|
|
|
|
|
# This code is part of distribution Log-Report-Lexicon. Meta-POD processed |
6
|
|
|
|
|
|
|
# with OODoc into POD and HTML manual-pages. See README.md |
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Log::Report::Lexicon::Index; |
10
|
3
|
|
|
3
|
|
16
|
use vars '$VERSION'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
121
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.11'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
55
|
|
15
|
3
|
|
|
3
|
|
24
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
51
|
|
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
9
|
use Log::Report 'log-report-lexicon'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
12
|
|
18
|
3
|
|
|
3
|
|
562
|
use Log::Report::Util qw/parse_locale/; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
113
|
|
19
|
3
|
|
|
3
|
|
12
|
use File::Find (); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
2860
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# The next two need extension when other lexicon formats are added |
22
|
27
|
|
|
27
|
|
444
|
sub _understand_file_format($) { $_[0] =~ qr/\.(?:gmo|mo|po)$/i } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _find($$) |
25
|
157
|
|
|
157
|
|
199
|
{ my ($index, $name) = (shift, lc shift); |
26
|
157
|
50
|
66
|
|
|
674
|
$index->{"$name.mo"} || $index->{"name.gmo"} || $index->{"$name.po"}; # prefer mo |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# On windows, other locale names are used. They will get translated |
30
|
|
|
|
|
|
|
# into the Linux (ISO) convensions. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $locale_unifier; |
33
|
|
|
|
|
|
|
if($^O eq 'MSWin32') |
34
|
|
|
|
|
|
|
{ require Log::Report::Win32Locale; |
35
|
|
|
|
|
|
|
Log::Report::Win32Locale->import; |
36
|
|
|
|
|
|
|
$locale_unifier = sub { iso_locale($_[0]) }; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else |
39
|
|
|
|
|
|
|
{ # some UNIXes do not understand "POSIX" |
40
|
|
|
|
|
|
|
$locale_unifier = sub { uc $_[0] eq 'POSIX' ? 'c' : lc $_[0] }; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new($;@) |
45
|
2
|
|
|
2
|
1
|
4
|
{ my ($class, $dir) = (shift, shift); |
46
|
2
|
|
|
|
|
17
|
bless {dir => $dir, @_}, $class; # dir before first argument. |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#------------------- |
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
4
|
1
|
693
|
sub directory() {shift->{dir}} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#------------------- |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub index() |
56
|
20
|
|
|
20
|
1
|
22
|
{ my $self = shift; |
57
|
20
|
100
|
|
|
|
45
|
return $self->{index} if exists $self->{index}; |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
5
|
my $dir = $self->directory; |
60
|
2
|
|
|
|
|
25
|
my $strip_dir = qr!\Q$dir/!; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
5
|
$self->{index} = {}; |
63
|
|
|
|
|
|
|
File::Find::find |
64
|
|
|
|
|
|
|
( +{ wanted => sub |
65
|
31
|
100
|
66
|
31
|
|
756
|
{ -f && !m[/\.] && _understand_file_format($_) or return 1; |
|
|
|
100
|
|
|
|
|
66
|
15
|
|
|
|
|
52
|
(my $key = $_) =~ s/$strip_dir//; |
67
|
15
|
|
|
|
|
51
|
$self->addFile($key, $_); |
68
|
15
|
|
|
|
|
366
|
1; |
69
|
|
|
|
|
|
|
} |
70
|
2
|
|
|
|
|
271
|
, follow => 1 |
71
|
|
|
|
|
|
|
, no_chdir => 1 |
72
|
|
|
|
|
|
|
, follow_skip => 2 |
73
|
|
|
|
|
|
|
} , $dir |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
14
|
$self->{index}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub addFile($;$) |
81
|
16
|
|
|
16
|
1
|
24
|
{ my ($self, $base, $abs) = @_; |
82
|
16
|
|
66
|
|
|
34
|
$abs ||= File::Spec->catfile($self->directory, $base); |
83
|
16
|
|
|
|
|
18
|
$base =~ s!\\!/!g; # dos->unix |
84
|
16
|
|
|
|
|
46
|
$self->{index}{lc $base} = $abs; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub find($$) |
89
|
14
|
|
|
14
|
1
|
564
|
{ my $self = shift; |
90
|
14
|
|
|
|
|
19
|
my $domain = lc shift; |
91
|
14
|
|
|
|
|
22
|
my $locale = $locale_unifier->(shift); |
92
|
|
|
|
|
|
|
|
93
|
14
|
|
|
|
|
23
|
my $index = $self->index; |
94
|
14
|
50
|
|
|
|
26
|
keys %$index or return undef; |
95
|
|
|
|
|
|
|
|
96
|
14
|
|
|
|
|
28
|
my ($lang, $terr, $cs, $modif) = parse_locale $locale; |
97
|
14
|
50
|
|
|
|
341
|
unless(defined $lang) |
98
|
0
|
0
|
|
|
|
0
|
{ defined $locale or $locale = ''; |
99
|
|
|
|
|
|
|
# avoid problem with recursion, not translatable! |
100
|
0
|
|
|
|
|
0
|
print STDERR "illegal locale $locale, when looking for $domain"; |
101
|
0
|
|
|
|
|
0
|
return undef; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
14
|
100
|
|
|
|
24
|
$terr = defined $terr ? '_'.$terr : ''; |
105
|
14
|
50
|
|
|
|
21
|
$cs = defined $cs ? '.'.$cs : ''; |
106
|
14
|
50
|
|
|
|
16
|
$modif = defined $modif ? '@'.$modif : ''; |
107
|
|
|
|
|
|
|
|
108
|
14
|
|
|
|
|
17
|
(my $normcs = $cs) =~ s/[^a-z0-9]//g; |
109
|
14
|
50
|
|
|
|
29
|
if(length $normcs) |
110
|
0
|
0
|
|
|
|
0
|
{ $normcs = "iso$normcs" if $normcs !~ /[^0-9-]/; |
111
|
0
|
|
|
|
|
0
|
$normcs = '.'.$normcs; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
14
|
|
|
|
|
10
|
my $fn; |
115
|
14
|
|
|
|
|
32
|
for my $f ("/lc_messages/$domain", "/$domain") |
116
|
28
|
|
33
|
|
|
81
|
{ $fn |
|
|
|
33
|
|
|
|
|
117
|
|
|
|
|
|
|
||= _find($index, "$lang$terr$cs$modif$f") |
118
|
|
|
|
|
|
|
|| _find($index, "$lang$terr$normcs$modif$f") |
119
|
|
|
|
|
|
|
|| _find($index, "$lang$terr$modif$f") |
120
|
|
|
|
|
|
|
|| _find($index, "$lang$modif$f") |
121
|
|
|
|
|
|
|
|| _find($index, "$lang$f"); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$fn |
125
|
14
|
0
|
66
|
|
|
42
|
|| _find($index, "$domain/$lang$terr$cs$modif") |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
126
|
|
|
|
|
|
|
|| _find($index, "$domain/$lang$terr$normcs$modif") |
127
|
|
|
|
|
|
|
|| _find($index, "$domain/$lang$terr$modif") |
128
|
|
|
|
|
|
|
|| _find($index, "$domain/$lang$cs$modif") |
129
|
|
|
|
|
|
|
|| _find($index, "$domain/$lang$normcs$modif") |
130
|
|
|
|
|
|
|
|| _find($index, "$domain/$lang$modif") |
131
|
|
|
|
|
|
|
|| _find($index, "$domain/$lang"); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub list($;$) |
136
|
4
|
|
|
4
|
1
|
689
|
{ my $self = shift; |
137
|
4
|
|
|
|
|
7
|
my $domain = lc shift; |
138
|
4
|
|
|
|
|
7
|
my $filter = shift; |
139
|
4
|
|
|
|
|
7
|
my $index = $self->index; |
140
|
4
|
|
|
|
|
71
|
my @list = map $index->{$_}, grep m!\b\Q$domain\E\b!, keys %$index; |
141
|
|
|
|
|
|
|
|
142
|
4
|
100
|
|
|
|
19
|
defined $filter |
143
|
|
|
|
|
|
|
or return @list; |
144
|
|
|
|
|
|
|
|
145
|
1
|
50
|
33
|
|
|
13
|
$filter = qr/\.\Q$filter\E$/i |
146
|
|
|
|
|
|
|
if defined $filter && ref $filter ne 'Regexp'; |
147
|
|
|
|
|
|
|
|
148
|
1
|
|
|
|
|
14
|
grep $_ =~ $filter, @list; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
#------------------------------------- |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |