line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cake::Plugins::I18N; |
2
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
60
|
|
3
|
1
|
|
|
1
|
|
4
|
use Cake 'Plugin'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
my $settings = {}; |
5
|
|
|
|
|
|
|
my $langs = {}; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub loc { |
8
|
6
|
|
|
6
|
1
|
20
|
my $self = shift; |
9
|
6
|
|
|
|
|
8
|
my $string = shift; |
10
|
6
|
|
33
|
|
|
16
|
$settings ||= settings(); |
11
|
6
|
|
33
|
|
|
37
|
my $dir = $settings->{path} || $self->app->{'dir'} . '/I18N'; |
12
|
6
|
|
50
|
|
|
20
|
my $lang = $settings->{lang} || 'en'; |
13
|
6
|
|
|
|
|
11
|
my $path = $dir.'/'.$lang; |
14
|
6
|
|
|
|
|
8
|
my $file; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#croak "I18N Folder Not found in $path app directory please create one" if (! -e "$path"); |
17
|
6
|
100
|
|
|
|
16
|
if (ref $string eq 'ARRAY'){ |
18
|
2
|
|
|
|
|
5
|
$lang = $lang . '::' . $string->[0]; |
19
|
2
|
|
|
|
|
6
|
$file = $path.'/'.$string->[0].'.po'; |
20
|
2
|
|
|
|
|
4
|
$string = $string->[1]; |
21
|
|
|
|
|
|
|
} else { |
22
|
4
|
|
|
|
|
10
|
$file = $path.'.po'; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
6
|
100
|
|
|
|
26
|
if (!$langs->{$lang}){ ##memoize |
26
|
4
|
|
|
|
|
13
|
my %hash = Cake::Plugins::I18N::Lexi::_get_lexi($file); |
27
|
|
|
|
|
|
|
{ |
28
|
4
|
|
|
|
|
8
|
$langs->{$lang} = sub { |
29
|
6
|
|
|
6
|
|
8
|
my $str = shift; |
30
|
6
|
|
|
|
|
8
|
my $hash = \%hash; |
31
|
6
|
|
33
|
|
|
19
|
$str = $hash->{$str} || $str; |
32
|
6
|
|
|
|
|
8
|
my @arr = (); |
33
|
6
|
100
|
|
|
|
13
|
if (@_){ |
|
2
|
|
|
|
|
8
|
|
34
|
4
|
100
|
66
|
|
|
24
|
@arr = ('', @_ > 1 || !ref $_[0] ? @_ : @{$_[0]} ); |
|
2
|
|
|
|
|
7
|
|
35
|
4
|
|
|
|
|
39
|
$str =~ s/%(\d+)/$arr[$1]/g; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else {$str =~ s/%(\d+)//g;} |
38
|
6
|
|
|
|
|
38
|
return $str; |
39
|
4
|
|
|
|
|
28
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
6
|
|
|
|
|
21
|
return $langs->{$lang}->($string,@_); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub set_lang { |
47
|
5
|
|
|
5
|
1
|
4443
|
my $self = shift; |
48
|
5
|
|
|
|
|
9
|
my $lang = shift; |
49
|
5
|
|
33
|
|
|
16
|
$settings ||= settings(); |
50
|
5
|
50
|
|
|
|
15
|
$settings->{lang} = $lang if $lang; |
51
|
5
|
|
|
|
|
17
|
return 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_lang { |
55
|
2
|
|
|
2
|
0
|
19
|
my $self = shift; |
56
|
2
|
|
50
|
|
|
15
|
return $settings->{lang} || 'en'; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
register(); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package #hide |
62
|
|
|
|
|
|
|
Cake::Plugins::I18N::Lexi; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my %hash; |
65
|
|
|
|
|
|
|
my $last; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub msgstr { |
68
|
5
|
|
|
5
|
|
9
|
my $str = shift; |
69
|
5
|
50
|
|
|
|
20
|
$hash{$last} = $str if $last; |
70
|
5
|
|
|
|
|
54
|
$last = undef; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub msgid { |
74
|
5
|
|
|
5
|
|
10
|
my $str = shift; |
75
|
5
|
|
|
|
|
116
|
$last = $str; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _get_lexi { |
79
|
4
|
|
|
4
|
|
6
|
my $package = shift; |
80
|
4
|
|
|
|
|
5
|
my $data; |
81
|
4
|
50
|
|
|
|
246
|
open my $DATA, '<', $package |
82
|
|
|
|
|
|
|
or die "Can't open $package for input:\n$!"; |
83
|
4
|
|
|
|
|
22
|
binmode $DATA,":utf8"; |
84
|
4
|
|
|
|
|
5
|
$data = do { local $/; <$DATA> }; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
316
|
|
85
|
4
|
|
|
|
|
51
|
close $DATA; |
86
|
4
|
|
|
|
|
91
|
$data =~ s/(\w+["'])[\r\n]/$1;\n/g; |
87
|
4
|
|
|
|
|
316
|
eval "$data"; |
88
|
4
|
|
|
|
|
30
|
return %hash; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |