line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ark::Plugin::I18N; |
2
|
4
|
|
|
4
|
|
51559
|
use 5.008001; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
139
|
|
3
|
4
|
|
|
4
|
|
23
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
115
|
|
4
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
156
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
3023
|
use Ark::Plugin; |
|
4
|
|
|
|
|
35909
|
|
|
4
|
|
|
|
|
27
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
8311
|
use I18N::LangTags (); |
|
4
|
|
|
|
|
11081
|
|
|
4
|
|
|
|
|
98
|
|
11
|
4
|
|
|
4
|
|
3603
|
use I18N::LangTags::Detect; |
|
4
|
|
|
|
|
1434460
|
|
|
4
|
|
|
|
|
1611
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require Locale::Maketext::Simple; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub BUILD { |
16
|
6
|
|
|
6
|
0
|
164929
|
my $self = shift; |
17
|
6
|
|
|
|
|
51
|
my $stash = $self->class_stash; |
18
|
|
|
|
|
|
|
|
19
|
6
|
100
|
|
|
|
357
|
return if $stash->{setup_finished}; |
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
16
|
my $class = ref($self->app); |
22
|
3
|
|
|
|
|
14
|
(my $module_path = $class) =~ s!::!/!g; |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
|
|
26
|
my $path = $self->path_to('lib', $module_path, 'I18N'); |
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
|
|
681
|
eval <<""; |
27
|
|
|
|
|
|
|
package $class; |
28
|
|
|
|
|
|
|
Locale::Maketext::Simple->import( |
29
|
|
|
|
|
|
|
Class => '$class', |
30
|
|
|
|
|
|
|
Path => '$path', |
31
|
|
|
|
|
|
|
Export => '_loc', |
32
|
|
|
|
|
|
|
Decode => 1 |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
3
|
50
|
|
|
|
72199
|
if ($@) { |
36
|
0
|
|
|
|
|
0
|
$self->log( error => qq/Couldn't initialize i18n "$class\::I18N", "$@"/ ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
3
|
|
|
|
|
55
|
$self->log( debug => qq/Initialized i18n "$class\::I18N"/); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
149
|
$stash->{setup_finished}++; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub languages { |
46
|
7
|
|
|
7
|
0
|
14
|
my ($self, $languages) = @_; |
47
|
|
|
|
|
|
|
|
48
|
7
|
50
|
|
|
|
23
|
if ($languages) { |
49
|
0
|
0
|
|
|
|
0
|
$self->{languages} = ref($languages) eq 'ARRAY' ? $languages : [$languages]; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
7
|
|
100
|
|
|
117
|
$self->{languages} ||= [ |
53
|
|
|
|
|
|
|
I18N::LangTags::implicate_supers( |
54
|
|
|
|
|
|
|
I18N::LangTags::Detect->http_accept_langs( |
55
|
|
|
|
|
|
|
$self->request->header('Accept-Language'), |
56
|
|
|
|
|
|
|
), |
57
|
|
|
|
|
|
|
), |
58
|
|
|
|
|
|
|
'i-default', |
59
|
|
|
|
|
|
|
]; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
7
|
50
|
|
|
|
2158
|
if (my $mt = $self->app->can('_loc_lang')) { |
63
|
7
|
|
|
|
|
14
|
$mt->(@{ $self->{languages} }); |
|
7
|
|
|
|
|
38
|
|
64
|
|
|
|
|
|
|
} |
65
|
7
|
|
|
|
|
8440
|
$self->{languages}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub language { |
69
|
2
|
|
|
2
|
0
|
723
|
my $self = shift; |
70
|
2
|
|
|
|
|
9
|
my $class = ref($self->app); |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
5
|
"${class}::I18N"->get_handle(@{ $self->languages })->language_tag; |
|
2
|
|
|
|
|
9
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
{ |
76
|
4
|
|
|
4
|
|
39
|
no warnings 'once'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
614
|
|
77
|
|
|
|
|
|
|
*loc = \&localize; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub localize { |
81
|
5
|
|
|
5
|
0
|
6501
|
my $self = shift; |
82
|
5
|
|
|
|
|
25
|
$self->languages; |
83
|
|
|
|
|
|
|
|
84
|
5
|
50
|
|
|
|
43
|
my $loc = $self->app->can('_loc') or return; |
85
|
5
|
50
|
|
|
|
23
|
if (ref $_[1] eq 'ARRAY') { |
86
|
0
|
|
|
|
|
0
|
return $loc->( $_[0], @{ $_[1] } ); |
|
0
|
|
|
|
|
0
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
5
|
|
|
|
|
28
|
return $loc->(@_); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |