| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Locale::Simple; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
6
|
|
|
6
|
|
159804
|
$Locale::Simple::AUTHORITY = 'cpan:GETTY'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
# ABSTRACT: Functions for translate text based on gettext data, also in JavaScript |
|
6
|
|
|
|
|
|
|
$Locale::Simple::VERSION = '0.017'; |
|
7
|
6
|
|
|
6
|
|
52
|
use strict; |
|
|
6
|
|
|
|
|
14
|
|
|
|
6
|
|
|
|
|
512
|
|
|
8
|
6
|
|
|
6
|
|
32
|
use warnings; |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
216
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
42
|
use Exporter 'import'; |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
209
|
|
|
11
|
6
|
|
|
6
|
|
6264
|
use Locale::TextDomain 1.23 (); # to ensure we get the right version of gettext_dumb |
|
|
6
|
|
|
|
|
204018
|
|
|
|
6
|
|
|
|
|
205
|
|
|
12
|
6
|
|
|
6
|
|
6021
|
use Locale::gettext_dumb qw(:locale_h :libintl_h); |
|
|
6
|
|
|
|
|
184623
|
|
|
|
6
|
|
|
|
|
1943
|
|
|
13
|
6
|
|
|
6
|
|
69
|
use POSIX qw' setlocale '; |
|
|
6
|
|
|
|
|
15
|
|
|
|
6
|
|
|
|
|
51
|
|
|
14
|
6
|
|
|
6
|
|
20647
|
use IO::All 0.41 -utf8; |
|
|
6
|
|
|
|
|
81430
|
|
|
|
6
|
|
|
|
|
87
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
l_dir |
|
19
|
|
|
|
|
|
|
l_lang |
|
20
|
|
|
|
|
|
|
l_dry |
|
21
|
|
|
|
|
|
|
l_nolocales |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
l |
|
24
|
|
|
|
|
|
|
ln |
|
25
|
|
|
|
|
|
|
lp |
|
26
|
|
|
|
|
|
|
lnp |
|
27
|
|
|
|
|
|
|
ld |
|
28
|
|
|
|
|
|
|
ldn |
|
29
|
|
|
|
|
|
|
ldp |
|
30
|
|
|
|
|
|
|
ldnp |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
ltd |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $dry; |
|
37
|
|
|
|
|
|
|
my $nowrite; |
|
38
|
|
|
|
|
|
|
my $nolocales; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my %tds; |
|
41
|
|
|
|
|
|
|
my $dir; |
|
42
|
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
0
|
625
|
sub l_nolocales { $nolocales = shift } |
|
44
|
1
|
50
|
|
1
|
0
|
609
|
sub l_dry { $dry = shift; $nowrite = shift; $nolocales = 1 if $dry } |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub gettext_escape { |
|
47
|
44
|
|
|
44
|
0
|
63
|
my ( $content ) = @_; |
|
48
|
44
|
|
|
|
|
283
|
$content =~ s/\\/\\\\/g; |
|
49
|
44
|
|
|
|
|
62
|
$content =~ s/\n/\\n/g; |
|
50
|
44
|
|
|
|
|
70
|
$content =~ s/"/\\"/g; |
|
51
|
44
|
|
|
|
|
504
|
return $content; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub sprintf_compare { |
|
55
|
0
|
|
|
0
|
0
|
0
|
my ( $first, $second ) = @_; |
|
56
|
0
|
|
|
|
|
0
|
my $re = qr/(?:%%|%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX])/; |
|
57
|
0
|
|
|
|
|
0
|
my @placeholder_first = sort { $a cmp $b } map { my @chars = split(//,$_); pop @chars; } ($first =~ m/$re/g); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
58
|
0
|
|
|
|
|
0
|
my @placeholder_second = sort { $a cmp $b } map { my @chars = split(//,$_); pop @chars; } ($second =~ m/$re/g); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
59
|
0
|
|
|
|
|
0
|
return join("",@placeholder_first) eq join("",@placeholder_second); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub coderef_hash {{ |
|
63
|
0
|
|
|
0
|
|
0
|
l => sub { l(@_) }, |
|
64
|
0
|
|
|
0
|
|
0
|
ln => sub { ln(@_) }, |
|
65
|
0
|
|
|
0
|
|
0
|
lp => sub { lp(@_) }, |
|
66
|
0
|
|
|
0
|
|
0
|
lnp => sub { lnp(@_) }, |
|
67
|
0
|
|
|
0
|
|
0
|
ld => sub { ld(@_) }, |
|
68
|
0
|
|
|
0
|
|
0
|
ldn => sub { ldn(@_) }, |
|
69
|
0
|
|
|
0
|
|
0
|
ldp => sub { ldp(@_) }, |
|
70
|
0
|
|
|
0
|
|
0
|
ldnp => sub { ldnp(@_) }, |
|
71
|
0
|
|
|
0
|
0
|
0
|
}} |
|
72
|
|
|
|
|
|
|
|
|
73
|
3
|
|
|
3
|
0
|
32
|
sub l_dir { $dir = shift } |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub l_lang { |
|
76
|
2
|
|
|
2
|
0
|
15
|
my $primary = shift; |
|
77
|
2
|
|
|
|
|
18
|
$ENV{LANGUAGE} = $primary; |
|
78
|
2
|
|
|
|
|
12
|
$ENV{LANG} = $primary; # unsure if these ENV assignments are still needed with the setlocale below |
|
79
|
2
|
|
|
|
|
9
|
$ENV{LC_ALL} = $primary; |
|
80
|
2
|
|
|
|
|
10
|
$ENV{LC_MESSAGES} = $primary; # set locale for messages if the system supports it |
|
81
|
2
|
50
|
|
|
|
6
|
setlocale( LC_MESSAGES, $primary ) if eval { LC_MESSAGES }; # set locale for messages if the system supports it |
|
|
2
|
|
|
|
|
65
|
|
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# write dry |
|
85
|
5
|
50
|
|
5
|
0
|
21
|
sub wd { io($dry)->append(join("\n",@_)."\n\n") if !$nowrite } |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# l(msgid,...) |
|
88
|
9
|
|
|
9
|
0
|
1501
|
sub l { return ldnp('',undef,shift,undef,undef,@_) } |
|
89
|
|
|
|
|
|
|
# ln(msgid,msgid_plural,count,...) |
|
90
|
12
|
|
|
12
|
0
|
47
|
sub ln { return ldnp('',undef,@_) } |
|
91
|
|
|
|
|
|
|
# lp(msgctxt,msgid,...) |
|
92
|
1
|
|
|
1
|
0
|
4
|
sub lp { return ldnp('',shift,shift,undef,undef,@_) } |
|
93
|
|
|
|
|
|
|
# lnp(msgctxt,msgid,msgid_plural,count,...) |
|
94
|
0
|
|
|
0
|
0
|
0
|
sub lnp { return ldnp('',shift,shift,shift,shift,@_) } |
|
95
|
|
|
|
|
|
|
# ld(domain,msgid,...) |
|
96
|
0
|
|
|
0
|
0
|
0
|
sub ld { return ldnp(shift,undef,shift,undef,undef,@_) } |
|
97
|
|
|
|
|
|
|
# ldn(domain,msgid,msgid_plural,count,...) |
|
98
|
0
|
|
|
0
|
0
|
0
|
sub ldn { return ldnp(shift,undef,shift,shift,shift,@_) } |
|
99
|
|
|
|
|
|
|
# ldp(domain,msgctxt,msgid,...) |
|
100
|
0
|
|
|
0
|
0
|
0
|
sub ldp { return ldnp(shift,shift,shift,undef,undef,@_) } |
|
101
|
|
|
|
|
|
|
# ldnp(domain,msgctxt,msgid,msgid_plural,count,...) |
|
102
|
|
|
|
|
|
|
sub ldnp { |
|
103
|
22
|
100
|
100
|
22
|
0
|
106
|
die "please set a locale directory with l_dir() before using other translate functions" unless $dir || $nolocales; |
|
104
|
21
|
|
|
|
|
55
|
my ($td, $ctxt, $id, $idp, $n) = (shift,shift,shift,shift,shift); |
|
105
|
21
|
|
|
|
|
43
|
my @args = @_; |
|
106
|
21
|
100
|
|
|
|
52
|
unshift @args, $n if $idp; |
|
107
|
21
|
|
|
|
|
27
|
my $return; |
|
108
|
21
|
100
|
|
|
|
56
|
if ($dry) { |
|
109
|
5
|
50
|
|
|
|
11
|
if (!$nowrite) { |
|
110
|
5
|
|
|
|
|
5
|
my @save; |
|
111
|
5
|
50
|
|
|
|
9
|
push @save, '# domain: '.$td if $td; |
|
112
|
5
|
50
|
|
|
|
8
|
push @save, 'msgctxt "'.gettext_escape($ctxt).'"' if $ctxt; |
|
113
|
5
|
|
|
|
|
11
|
push @save, 'msgid "'.gettext_escape($id).'"'; |
|
114
|
5
|
100
|
|
|
|
15
|
push @save, 'msgid_plural "'.gettext_escape($idp).'"' if $idp; |
|
115
|
5
|
|
|
|
|
10
|
wd(@save); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
5
|
100
|
100
|
|
|
12769
|
$return = sprintf($idp && $n != 1 ? $idp : $id, @args); |
|
118
|
|
|
|
|
|
|
} else { |
|
119
|
|
|
|
|
|
|
# L::TD handles msg ids as bytes internally |
|
120
|
16
|
|
|
|
|
38
|
utf8::encode($id); |
|
121
|
16
|
|
|
|
|
58
|
my $gt = dnpgettext($td, $ctxt, $id, $idp, $n); |
|
122
|
|
|
|
|
|
|
# Fixing bad utf8 handling |
|
123
|
16
|
|
|
|
|
5185
|
utf8::decode($gt); |
|
124
|
16
|
|
|
|
|
58
|
$return = sprintf($gt,@args); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
21
|
|
|
|
|
682
|
return $return; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub ltd { |
|
130
|
6
|
100
|
100
|
6
|
0
|
451
|
die "please set a locale directory with l_dir() before using other translate functions" unless $dir || $nolocales; |
|
131
|
5
|
|
|
|
|
15
|
my $td = shift; |
|
132
|
5
|
50
|
|
|
|
26
|
unless (defined $tds{$td}) { |
|
133
|
5
|
|
|
|
|
35
|
bindtextdomain($td,$dir); |
|
134
|
5
|
|
|
|
|
126
|
bind_textdomain_codeset($td,'utf-8'); |
|
135
|
5
|
|
|
|
|
52
|
$tds{$td} = 1; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
5
|
|
|
|
|
24
|
textdomain($td); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
__END__ |