line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Localize::Gettext; |
2
|
1
|
|
|
1
|
|
1465
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
3
|
1
|
|
|
1
|
|
27
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
314
|
use Module::Load (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
5
|
1
|
|
|
1
|
|
12
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
6
|
1
|
|
|
1
|
|
586
|
use Data::Localize::Gettext::Parser; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
7
|
1
|
|
|
1
|
|
6
|
use File::Temp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
8
|
1
|
|
|
1
|
|
4
|
use Data::Localize; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
9
|
1
|
|
|
1
|
|
577
|
use Data::Localize::Storage::Hash; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
67
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
|
|
1
|
|
945
|
if (Data::Localize::DEBUG) { |
13
|
|
|
|
|
|
|
require Data::Localize::Log; |
14
|
|
|
|
|
|
|
Data::Localize::Log->import; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
extends 'Data::Localize::Localizer'; |
19
|
|
|
|
|
|
|
with 'Data::Localize::Trait::WithStorage'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has encoding => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
default => sub { 'utf-8' }, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has paths => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
trigger => sub { |
29
|
|
|
|
|
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
if ($self->initialized) { |
31
|
|
|
|
|
|
|
$self->load_from_path($_) for @{$_[0]}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has use_fuzzy => ( |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
default => sub { 0 }, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has keep_empty => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
default => sub { 0 }, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has _parser => ( |
47
|
|
|
|
|
|
|
is => 'rw', |
48
|
|
|
|
|
|
|
lazy => 1, |
49
|
|
|
|
|
|
|
builder => "_build__parser", |
50
|
|
|
|
|
|
|
isa => sub { $_[0]->isa('Data::Localize::Gettext::Parser') }, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
around register => sub { |
54
|
|
|
|
|
|
|
my ($next, $self, $loc) = @_; |
55
|
|
|
|
|
|
|
$self->$next($loc); |
56
|
|
|
|
|
|
|
$loc->add_localizer_map('*', $self); |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _build__parser { |
60
|
3
|
|
|
3
|
|
860
|
my $self = shift; |
61
|
3
|
|
|
|
|
79
|
return Data::Localize::Gettext::Parser->new( |
62
|
|
|
|
|
|
|
use_fuzzy => $self->use_fuzzy(), |
63
|
|
|
|
|
|
|
keep_empty => $self->keep_empty(), |
64
|
|
|
|
|
|
|
encoding => $self->encoding(), |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
after BUILD => sub { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
my $paths = $self->paths; |
71
|
|
|
|
|
|
|
foreach my $path (@$paths) { |
72
|
|
|
|
|
|
|
$self->load_from_path($path); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub BUILDARGS { |
77
|
3
|
|
|
3
|
0
|
6279
|
my ($class, %args) = @_; |
78
|
|
|
|
|
|
|
|
79
|
3
|
|
|
|
|
9
|
my $path = delete $args{path}; |
80
|
3
|
50
|
|
|
|
14
|
if ($path) { |
81
|
3
|
|
50
|
|
|
31
|
$args{paths} ||= []; |
82
|
3
|
|
|
|
|
5
|
push @{$args{paths}}, $path; |
|
3
|
|
|
|
|
10
|
|
83
|
|
|
|
|
|
|
} |
84
|
3
|
|
|
|
|
32
|
$class->SUPER::BUILDARGS(%args); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _build_formatter { |
88
|
2
|
|
|
2
|
|
1105
|
Module::Load::load( 'Data::Localize::Format::Gettext' ); |
89
|
2
|
|
|
|
|
96
|
return Data::Localize::Format::Gettext->new(); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub add_path { |
93
|
1
|
|
|
1
|
1
|
10
|
my $self = shift; |
94
|
1
|
|
|
|
|
2
|
push @{$self->paths}, @_; |
|
1
|
|
|
|
|
6
|
|
95
|
1
|
|
|
|
|
6
|
$self->load_from_path($_) for @_; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub load_from_path { |
99
|
4
|
|
|
4
|
1
|
7
|
my ($self, $path) = @_; |
100
|
|
|
|
|
|
|
|
101
|
4
|
50
|
|
|
|
11
|
return unless $path; |
102
|
|
|
|
|
|
|
|
103
|
4
|
|
|
|
|
7
|
if (Data::Localize::DEBUG) { |
104
|
|
|
|
|
|
|
debugf("load_from_path - loading from glob(%s)", $path); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
4
|
|
|
|
|
364
|
foreach my $x (glob($path)) { |
108
|
4
|
50
|
|
|
|
71
|
$self->load_from_file($x) if -f $x; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub load_from_file { |
113
|
4
|
|
|
4
|
1
|
9
|
my ($self, $file) = @_; |
114
|
|
|
|
|
|
|
|
115
|
4
|
|
|
|
|
5
|
if (Data::Localize::DEBUG) { |
116
|
|
|
|
|
|
|
debugf("load_from_file - loading from file %s", $file); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
4
|
|
|
|
|
211
|
my $lexicon = $self->_parser->parse_file($file); |
120
|
|
|
|
|
|
|
|
121
|
4
|
|
|
|
|
191
|
my $lang = File::Basename::basename($file); |
122
|
4
|
|
|
|
|
17
|
$lang =~ s/\.[mp]o$//; |
123
|
|
|
|
|
|
|
|
124
|
4
|
|
|
|
|
6
|
if (Data::Localize::DEBUG) { |
125
|
|
|
|
|
|
|
debugf("load_from_file - registering %d keys", scalar keys %{$lexicon}); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# This needs to be merged |
129
|
4
|
|
|
|
|
19
|
$self->merge_lexicon($lang, $lexicon); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |