line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Localize::Localizer; |
2
|
5
|
|
|
5
|
|
8410
|
use utf8; |
|
5
|
|
|
|
|
37
|
|
|
5
|
|
|
|
|
33
|
|
3
|
5
|
|
|
5
|
|
153
|
use Moo; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
38
|
|
4
|
5
|
|
|
5
|
|
1645
|
use Carp (); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
113
|
|
5
|
5
|
|
|
5
|
|
29
|
use Data::Localize; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
117
|
|
6
|
5
|
|
|
5
|
|
3627
|
use Encode (); |
|
5
|
|
|
|
|
36362
|
|
|
5
|
|
|
|
|
287
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
5
|
|
|
5
|
|
2020
|
if (Data::Localize::DEBUG) { |
10
|
|
|
|
|
|
|
require Data::Localize::Log; |
11
|
|
|
|
|
|
|
Data::Localize::Log->import |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has _localizer => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
weak_ref => 1, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has initialized => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
default => 0, |
23
|
|
|
|
|
|
|
init_arg => undef, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has formatter => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
lazy => 1, |
29
|
|
|
|
|
|
|
isa => sub { $_[0]->isa('Data::Localize::Format') }, |
30
|
|
|
|
|
|
|
builder => "_build_formatter", |
31
|
|
|
|
|
|
|
required => 1, |
32
|
|
|
|
|
|
|
handles => { format_string => 'format' }, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _build_formatter { |
36
|
6
|
|
|
6
|
|
3257
|
Module::Load::load('Data::Localize::Format::Maketext'); |
37
|
6
|
|
|
|
|
470
|
return Data::Localize::Format::Maketext->new(); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub BUILD { |
41
|
12
|
|
|
12
|
0
|
3876
|
$_[0]->initialized(1); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub register { |
45
|
4
|
|
|
4
|
1
|
13
|
my ($self, $loc) = @_; |
46
|
4
|
50
|
|
|
|
52
|
if ($self->_localizer) { |
47
|
0
|
|
|
|
|
0
|
Carp::confess("Localizer $self is already attached to another Data::Localize object ($loc)"); |
48
|
|
|
|
|
|
|
} |
49
|
4
|
|
|
|
|
1749
|
$self->_localizer( $loc ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub localize_for { |
53
|
13
|
|
|
13
|
1
|
2713
|
my ($self, %args) = @_; |
54
|
13
|
|
|
|
|
48
|
my ($lang, $id, $args) = @args{ qw(lang id args) }; |
55
|
|
|
|
|
|
|
|
56
|
13
|
50
|
|
|
|
55
|
my $value = $self->get_lexicon($lang, $id) or return (); |
57
|
13
|
|
|
|
|
19
|
if (Data::Localize::DEBUG()) { |
58
|
|
|
|
|
|
|
debugf("localize_for - '%s' -> '%s'", |
59
|
|
|
|
|
|
|
$id, |
60
|
|
|
|
|
|
|
defined($value) ? Encode::encode_utf8($value) : '(null)' |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
} |
63
|
13
|
50
|
|
|
|
28
|
if ( $value ) { |
64
|
13
|
|
|
|
|
429
|
return $self->format_string($lang, $value, @$args); |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
return (); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |