| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#! /bin/false |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# vim: set autoindent shiftwidth=4 tabstop=4: |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# Pure Perl implementation of Uniforum message translation. |
|
6
|
|
|
|
|
|
|
# Copyright (C) 2002-2017 Guido Flohr , |
|
7
|
|
|
|
|
|
|
# all rights reserved. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
|
11
|
|
|
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or |
|
12
|
|
|
|
|
|
|
# (at your option) any later version. |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
|
15
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
|
|
|
|
# GNU General Public License for more details. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
|
20
|
|
|
|
|
|
|
# along with this program. If not, see . |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package Locale::gettext_pp; |
|
23
|
|
|
|
|
|
|
|
|
24
|
22
|
|
|
22
|
|
5901
|
use strict; |
|
|
22
|
|
|
|
|
48
|
|
|
|
22
|
|
|
|
|
961
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
require 5.004; |
|
27
|
|
|
|
|
|
|
|
|
28
|
22
|
|
|
|
|
1977
|
use vars qw ($__gettext_pp_default_dir |
|
29
|
|
|
|
|
|
|
$__gettext_pp_textdomain |
|
30
|
|
|
|
|
|
|
$__gettext_pp_domain_bindings |
|
31
|
|
|
|
|
|
|
$__gettext_pp_domain_codeset_bindings |
|
32
|
|
|
|
|
|
|
$__gettext_pp_domains |
|
33
|
|
|
|
|
|
|
$__gettext_pp_recoders |
|
34
|
|
|
|
|
|
|
$__gettext_pp_unavailable_dirs |
|
35
|
|
|
|
|
|
|
$__gettext_pp_domain_cache |
|
36
|
|
|
|
|
|
|
$__gettext_pp_alias_cache |
|
37
|
22
|
|
|
22
|
|
109
|
$__gettext_pp_context_glue); |
|
|
22
|
|
|
|
|
37
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
22
|
|
|
22
|
|
9925
|
use locale; |
|
|
22
|
|
|
|
|
12795
|
|
|
|
22
|
|
|
|
|
115
|
|
|
40
|
22
|
|
|
22
|
|
805
|
use File::Spec; |
|
|
22
|
|
|
|
|
45
|
|
|
|
22
|
|
|
|
|
410
|
|
|
41
|
22
|
|
|
22
|
|
624
|
use Locale::Messages; |
|
|
22
|
|
|
|
|
41
|
|
|
|
22
|
|
|
|
|
2770
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
BEGIN { |
|
44
|
22
|
|
|
22
|
|
81
|
$__gettext_pp_textdomain = 'messages'; |
|
45
|
22
|
|
|
|
|
43
|
$__gettext_pp_domain_bindings = {}; |
|
46
|
22
|
|
|
|
|
87
|
$__gettext_pp_domain_codeset_bindings = {}; |
|
47
|
22
|
|
|
|
|
78
|
$__gettext_pp_domains = {}; |
|
48
|
22
|
|
|
|
|
62
|
$__gettext_pp_recoders = {}; |
|
49
|
22
|
|
|
|
|
59
|
$__gettext_pp_unavailable_dirs = {}; |
|
50
|
22
|
|
|
|
|
64
|
$__gettext_pp_domain_cache = {}; |
|
51
|
22
|
|
|
|
|
74
|
$__gettext_pp_alias_cache = {}; |
|
52
|
|
|
|
|
|
|
# The separator between msgctxt and msgid in a .mo file. */ |
|
53
|
22
|
|
|
|
|
49
|
$__gettext_pp_context_glue = "\004"; |
|
54
|
|
|
|
|
|
|
|
|
55
|
22
|
|
|
|
|
68
|
$__gettext_pp_default_dir = ''; |
|
56
|
|
|
|
|
|
|
|
|
57
|
22
|
|
|
|
|
71
|
for my $dir (qw (/usr/share/locale /usr/local/share/locale)) { |
|
58
|
22
|
50
|
|
|
|
468
|
if (-d $dir) { |
|
59
|
22
|
|
|
|
|
67
|
$__gettext_pp_default_dir = $dir; |
|
60
|
22
|
|
|
|
|
1121
|
last; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
BEGIN { |
|
66
|
22
|
|
|
22
|
|
10620
|
require POSIX; |
|
67
|
22
|
|
|
|
|
135657
|
require Exporter; |
|
68
|
22
|
|
|
22
|
|
11771
|
use IO::Handle; |
|
|
22
|
|
|
|
|
130449
|
|
|
|
22
|
|
|
|
|
4353
|
|
|
69
|
22
|
|
|
|
|
9215
|
require Locale::Recode; |
|
70
|
|
|
|
|
|
|
|
|
71
|
22
|
|
|
|
|
66
|
local $@; |
|
72
|
22
|
|
|
|
|
57
|
my ($has_messages, $five_ok); |
|
73
|
|
|
|
|
|
|
|
|
74
|
22
|
|
|
|
|
1445
|
$has_messages = eval '&POSIX::LC_MESSAGES'; |
|
75
|
|
|
|
|
|
|
|
|
76
|
22
|
50
|
33
|
|
|
263
|
unless (defined $has_messages && length $has_messages) { |
|
77
|
0
|
|
0
|
|
|
0
|
$five_ok = ! grep {my $x = eval "&POSIX::$_" || 0; $x eq '5';} |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
78
|
|
|
|
|
|
|
qw (LC_CTYPE |
|
79
|
|
|
|
|
|
|
LC_NUMERIC |
|
80
|
|
|
|
|
|
|
LC_TIME |
|
81
|
|
|
|
|
|
|
LC_COLLATE |
|
82
|
|
|
|
|
|
|
LC_MONETARY |
|
83
|
|
|
|
|
|
|
LC_ALL); |
|
84
|
0
|
0
|
|
|
|
0
|
if ($five_ok) { |
|
85
|
0
|
|
|
|
|
0
|
$five_ok = POSIX::setlocale (5, ''); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
22
|
50
|
33
|
|
|
180
|
if (defined $has_messages && length $has_messages) { |
|
|
|
0
|
|
|
|
|
|
|
90
|
22
|
|
|
1521
|
1
|
1694
|
eval <<'EOF'; |
|
|
1521
|
|
|
|
|
4336
|
|
|
|
1521
|
|
|
|
|
5166
|
|
|
91
|
|
|
|
|
|
|
sub LC_MESSAGES() |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
|
|
|
|
|
|
local $!; # Do not clobber errno! |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
return &POSIX::LC_MESSAGES; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
EOF |
|
98
|
|
|
|
|
|
|
} elsif ($five_ok) { |
|
99
|
0
|
|
|
|
|
0
|
eval <<'EOF'; |
|
100
|
|
|
|
|
|
|
sub LC_MESSAGES() |
|
101
|
|
|
|
|
|
|
{ |
|
102
|
|
|
|
|
|
|
local $!; # Do not clobber errno! |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Hack: POSIX.pm deems LC_MESSAGES an invalid macro until |
|
105
|
|
|
|
|
|
|
# Perl 5.8.0. However, on LC_MESSAGES should be 5 ... |
|
106
|
|
|
|
|
|
|
return 5; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
EOF |
|
109
|
|
|
|
|
|
|
} else { |
|
110
|
0
|
|
|
|
|
0
|
eval <<'EOF'; |
|
111
|
|
|
|
|
|
|
sub LC_MESSAGES() |
|
112
|
|
|
|
|
|
|
{ |
|
113
|
|
|
|
|
|
|
local $!; # Do not clobber errno! |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# This fallback value is widely used, |
|
116
|
|
|
|
|
|
|
# when LC_MESSAGES is not available. |
|
117
|
|
|
|
|
|
|
return 1729; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
EOF |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
22
|
|
|
22
|
|
152
|
use vars qw (%EXPORT_TAGS @EXPORT_OK @ISA $VERSION); |
|
|
22
|
|
|
|
|
45
|
|
|
|
22
|
|
|
|
|
93713
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
%EXPORT_TAGS = (locale_h => [ qw ( |
|
126
|
|
|
|
|
|
|
gettext |
|
127
|
|
|
|
|
|
|
dgettext |
|
128
|
|
|
|
|
|
|
dcgettext |
|
129
|
|
|
|
|
|
|
ngettext |
|
130
|
|
|
|
|
|
|
dngettext |
|
131
|
|
|
|
|
|
|
dcngettext |
|
132
|
|
|
|
|
|
|
pgettext |
|
133
|
|
|
|
|
|
|
dpgettext |
|
134
|
|
|
|
|
|
|
dcpgettext |
|
135
|
|
|
|
|
|
|
npgettext |
|
136
|
|
|
|
|
|
|
dnpgettext |
|
137
|
|
|
|
|
|
|
dcnpgettext |
|
138
|
|
|
|
|
|
|
textdomain |
|
139
|
|
|
|
|
|
|
bindtextdomain |
|
140
|
|
|
|
|
|
|
bind_textdomain_codeset |
|
141
|
|
|
|
|
|
|
) |
|
142
|
|
|
|
|
|
|
], |
|
143
|
|
|
|
|
|
|
libintl_h => [ qw (LC_CTYPE |
|
144
|
|
|
|
|
|
|
LC_NUMERIC |
|
145
|
|
|
|
|
|
|
LC_TIME |
|
146
|
|
|
|
|
|
|
LC_COLLATE |
|
147
|
|
|
|
|
|
|
LC_MONETARY |
|
148
|
|
|
|
|
|
|
LC_MESSAGES |
|
149
|
|
|
|
|
|
|
LC_ALL) |
|
150
|
|
|
|
|
|
|
], |
|
151
|
|
|
|
|
|
|
); |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
@EXPORT_OK = qw (gettext |
|
154
|
|
|
|
|
|
|
dgettext |
|
155
|
|
|
|
|
|
|
dcgettext |
|
156
|
|
|
|
|
|
|
ngettext |
|
157
|
|
|
|
|
|
|
dngettext |
|
158
|
|
|
|
|
|
|
dcngettext |
|
159
|
|
|
|
|
|
|
pgettext |
|
160
|
|
|
|
|
|
|
dpgettext |
|
161
|
|
|
|
|
|
|
dcpgettext |
|
162
|
|
|
|
|
|
|
npgettext |
|
163
|
|
|
|
|
|
|
dnpgettext |
|
164
|
|
|
|
|
|
|
dcnpgettext |
|
165
|
|
|
|
|
|
|
textdomain |
|
166
|
|
|
|
|
|
|
bindtextdomain |
|
167
|
|
|
|
|
|
|
bind_textdomain_codeset |
|
168
|
|
|
|
|
|
|
nl_putenv |
|
169
|
|
|
|
|
|
|
setlocale |
|
170
|
|
|
|
|
|
|
LC_CTYPE |
|
171
|
|
|
|
|
|
|
LC_NUMERIC |
|
172
|
|
|
|
|
|
|
LC_TIME |
|
173
|
|
|
|
|
|
|
LC_COLLATE |
|
174
|
|
|
|
|
|
|
LC_MONETARY |
|
175
|
|
|
|
|
|
|
LC_MESSAGES |
|
176
|
|
|
|
|
|
|
LC_ALL); |
|
177
|
|
|
|
|
|
|
@ISA = qw (Exporter); |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $has_nl_langinfo; |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub __load_catalog; |
|
182
|
|
|
|
|
|
|
sub __load_domain; |
|
183
|
|
|
|
|
|
|
sub __locale_category; |
|
184
|
|
|
|
|
|
|
sub __untaint_plural_header; |
|
185
|
|
|
|
|
|
|
sub __compile_plural_function; |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub LC_NUMERIC() |
|
188
|
|
|
|
|
|
|
{ |
|
189
|
2
|
|
|
2
|
1
|
8
|
&POSIX::LC_NUMERIC; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub LC_CTYPE() |
|
193
|
|
|
|
|
|
|
{ |
|
194
|
2
|
|
|
2
|
1
|
16
|
&POSIX::LC_CTYPE; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub LC_TIME() |
|
198
|
|
|
|
|
|
|
{ |
|
199
|
2
|
|
|
2
|
1
|
9
|
&POSIX::LC_TIME; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub LC_COLLATE() |
|
203
|
|
|
|
|
|
|
{ |
|
204
|
2
|
|
|
2
|
1
|
8
|
&POSIX::LC_COLLATE; |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub LC_MONETARY() |
|
208
|
|
|
|
|
|
|
{ |
|
209
|
2
|
|
|
2
|
1
|
8
|
&POSIX::LC_MONETARY; |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub LC_ALL() |
|
213
|
|
|
|
|
|
|
{ |
|
214
|
17
|
|
|
17
|
1
|
163
|
&POSIX::LC_ALL; |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub textdomain(;$) |
|
218
|
|
|
|
|
|
|
{ |
|
219
|
208
|
|
|
208
|
1
|
346
|
my $new_domain = shift; |
|
220
|
|
|
|
|
|
|
|
|
221
|
208
|
100
|
100
|
|
|
590
|
$__gettext_pp_textdomain = $new_domain if defined $new_domain && |
|
222
|
|
|
|
|
|
|
length $new_domain; |
|
223
|
|
|
|
|
|
|
|
|
224
|
208
|
|
|
|
|
496
|
return $__gettext_pp_textdomain; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub bindtextdomain($;$) |
|
228
|
|
|
|
|
|
|
{ |
|
229
|
50
|
|
|
50
|
1
|
138
|
my ($domain, $directory) = @_; |
|
230
|
|
|
|
|
|
|
|
|
231
|
50
|
|
|
|
|
94
|
my $retval; |
|
232
|
50
|
50
|
33
|
|
|
263
|
if (defined $domain && length $domain) { |
|
233
|
50
|
100
|
100
|
|
|
217
|
if (defined $directory && length $directory) { |
|
|
|
100
|
|
|
|
|
|
|
234
|
37
|
|
|
|
|
139
|
$retval = $__gettext_pp_domain_bindings->{$domain} |
|
235
|
|
|
|
|
|
|
= $directory; |
|
236
|
|
|
|
|
|
|
} elsif (exists $__gettext_pp_domain_bindings->{$domain}) { |
|
237
|
11
|
|
|
|
|
19
|
$retval = $__gettext_pp_domain_bindings->{$domain}; |
|
238
|
|
|
|
|
|
|
} else { |
|
239
|
2
|
|
|
|
|
3
|
$retval = $__gettext_pp_default_dir; |
|
240
|
|
|
|
|
|
|
} |
|
241
|
50
|
50
|
33
|
|
|
226
|
$retval = '/usr/share/locale' unless defined $retval && |
|
242
|
|
|
|
|
|
|
length $retval; |
|
243
|
50
|
|
|
|
|
173
|
return $retval; |
|
244
|
|
|
|
|
|
|
} else { |
|
245
|
0
|
|
|
|
|
0
|
return; |
|
246
|
|
|
|
|
|
|
} |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub bind_textdomain_codeset($;$) |
|
250
|
|
|
|
|
|
|
{ |
|
251
|
2
|
|
|
2
|
1
|
5
|
my ($domain, $codeset) = @_; |
|
252
|
|
|
|
|
|
|
|
|
253
|
2
|
50
|
33
|
|
|
11
|
if (defined $domain && length $domain) { |
|
254
|
2
|
50
|
33
|
|
|
8
|
if (defined $codeset && length $codeset) { |
|
|
|
0
|
|
|
|
|
|
|
255
|
2
|
|
|
|
|
8
|
return $__gettext_pp_domain_codeset_bindings->{$domain} = $codeset; |
|
256
|
|
|
|
|
|
|
} elsif (exists $__gettext_pp_domain_codeset_bindings->{$domain}) { |
|
257
|
0
|
|
|
|
|
0
|
return $__gettext_pp_domain_codeset_bindings->{$domain}; |
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
} |
|
260
|
|
|
|
|
|
|
|
|
261
|
0
|
|
|
|
|
0
|
return; |
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub gettext($) |
|
265
|
|
|
|
|
|
|
{ |
|
266
|
97
|
|
|
97
|
1
|
412
|
my ($msgid) = @_; |
|
267
|
|
|
|
|
|
|
|
|
268
|
97
|
|
|
|
|
239
|
return dcnpgettext ('', undef, $msgid, undef, undef, undef); |
|
269
|
|
|
|
|
|
|
} |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub dgettext($$) |
|
272
|
|
|
|
|
|
|
{ |
|
273
|
12
|
|
|
12
|
1
|
36
|
my ($domainname, $msgid) = @_; |
|
274
|
|
|
|
|
|
|
|
|
275
|
12
|
|
|
|
|
34
|
return dcnpgettext ($domainname, undef, $msgid, undef, undef, undef); |
|
276
|
|
|
|
|
|
|
} |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub dcgettext($$$) |
|
279
|
|
|
|
|
|
|
{ |
|
280
|
12
|
|
|
12
|
1
|
30
|
my ($domainname, $msgid, $category) = @_; |
|
281
|
|
|
|
|
|
|
|
|
282
|
12
|
|
|
|
|
34
|
return dcnpgettext ($domainname, undef, $msgid, undef, undef, undef); |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
sub ngettext($$$) |
|
286
|
|
|
|
|
|
|
{ |
|
287
|
83
|
|
|
83
|
1
|
154
|
my ($msgid, $msgid_plural, $n) = @_; |
|
288
|
|
|
|
|
|
|
|
|
289
|
83
|
|
|
|
|
181
|
return dcnpgettext ('', undef, $msgid, $msgid_plural, $n, undef); |
|
290
|
|
|
|
|
|
|
} |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
sub dngettext($$$$) |
|
293
|
|
|
|
|
|
|
{ |
|
294
|
83
|
|
|
83
|
1
|
201
|
my ($domainname, $msgid, $msgid_plural, $n) = @_; |
|
295
|
|
|
|
|
|
|
|
|
296
|
83
|
|
|
|
|
205
|
return dcnpgettext ($domainname, undef, $msgid, $msgid_plural, $n, undef); |
|
297
|
|
|
|
|
|
|
} |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub dcngettext($$$$$) |
|
300
|
|
|
|
|
|
|
{ |
|
301
|
83
|
|
|
83
|
1
|
163
|
my ($domainname, $msgid, $msgid_plural, $n, $category) = @_; |
|
302
|
|
|
|
|
|
|
|
|
303
|
83
|
|
|
|
|
146
|
return dcnpgettext ($domainname, undef, $msgid, $msgid_plural, $n, , $category); |
|
304
|
|
|
|
|
|
|
} |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub pgettext($$) |
|
308
|
|
|
|
|
|
|
{ |
|
309
|
3
|
|
|
3
|
1
|
9
|
my ($msgctxt, $msgid) = @_; |
|
310
|
|
|
|
|
|
|
|
|
311
|
3
|
|
|
|
|
9
|
return dcnpgettext ('', $msgctxt, $msgid, undef, undef, undef); |
|
312
|
|
|
|
|
|
|
} |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
sub dpgettext($$$) |
|
315
|
|
|
|
|
|
|
{ |
|
316
|
4
|
|
|
4
|
1
|
10
|
my ($domainname, $msgctxt, $msgid) = @_; |
|
317
|
|
|
|
|
|
|
|
|
318
|
4
|
|
|
|
|
18
|
return dcnpgettext ($domainname, $msgctxt, $msgid, undef, undef, undef); |
|
319
|
|
|
|
|
|
|
} |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
sub dcpgettext($$$$) |
|
322
|
|
|
|
|
|
|
{ |
|
323
|
5
|
|
|
5
|
1
|
14
|
my ($domainname, $msgctxt, $msgid, $category) = @_; |
|
324
|
|
|
|
|
|
|
|
|
325
|
5
|
|
|
|
|
12
|
return dcnpgettext ($domainname, $msgctxt, $msgid, undef, undef, undef); |
|
326
|
|
|
|
|
|
|
} |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
sub npgettext($$$$) |
|
329
|
|
|
|
|
|
|
{ |
|
330
|
91
|
|
|
91
|
1
|
178
|
my ($msgctxt, $msgid, $msgid_plural, $n) = @_; |
|
331
|
|
|
|
|
|
|
|
|
332
|
91
|
|
|
|
|
190
|
return dcnpgettext ('', $msgctxt, $msgid, $msgid_plural, $n, undef); |
|
333
|
|
|
|
|
|
|
} |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
sub dnpgettext($$$$$) |
|
336
|
|
|
|
|
|
|
{ |
|
337
|
91
|
|
|
91
|
1
|
202
|
my ($domainname, $msgctxt, $msgid, $msgid_plural, $n) = @_; |
|
338
|
|
|
|
|
|
|
|
|
339
|
91
|
|
|
|
|
181
|
return dcnpgettext ($domainname, $msgctxt, $msgid, $msgid_plural, $n, undef); |
|
340
|
|
|
|
|
|
|
} |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
# This is the actual implementation of dncpgettext. It is also used by the |
|
343
|
|
|
|
|
|
|
# corresponding function in Locale::gettext_dumb. |
|
344
|
|
|
|
|
|
|
sub _dcnpgettext_impl { |
|
345
|
664
|
|
|
664
|
|
1400
|
my ($domainname, $msgctxt, $msgid, $msgid_plural, $n, $category, |
|
346
|
|
|
|
|
|
|
$locale) = @_; |
|
347
|
|
|
|
|
|
|
|
|
348
|
664
|
50
|
|
|
|
1316
|
return unless defined $msgid; |
|
349
|
|
|
|
|
|
|
|
|
350
|
664
|
|
|
|
|
996
|
my $plural = defined $msgid_plural; |
|
351
|
664
|
|
|
|
|
17075
|
Locale::Messages::turn_utf_8_off($msgid); |
|
352
|
664
|
100
|
|
|
|
5964
|
Locale::Messages::turn_utf_8_off($msgctxt) if defined $msgctxt; |
|
353
|
664
|
100
|
|
|
|
1575
|
my $msg_ctxt_id = defined $msgctxt ? join($__gettext_pp_context_glue, ($msgctxt, $msgid)) : $msgid; |
|
354
|
|
|
|
|
|
|
|
|
355
|
664
|
|
|
|
|
2484
|
local $!; # Do not clobber errno! |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
# This is also done in __load_domain but we need a proper value. |
|
358
|
664
|
100
|
66
|
|
|
2469
|
$domainname = $__gettext_pp_textdomain |
|
359
|
|
|
|
|
|
|
unless defined $domainname && length $domainname; |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
# Category is always LC_MESSAGES (other categories are ignored). |
|
362
|
664
|
|
|
|
|
966
|
my $category_name = 'LC_MESSAGES'; |
|
363
|
664
|
|
|
|
|
12249
|
$category = LC_MESSAGES; |
|
364
|
|
|
|
|
|
|
|
|
365
|
664
|
|
|
|
|
1489
|
my $domains = __load_domain ($domainname, $category, $category_name, |
|
366
|
|
|
|
|
|
|
$locale); |
|
367
|
|
|
|
|
|
|
|
|
368
|
664
|
|
|
|
|
1137
|
my @trans = (); |
|
369
|
664
|
|
|
|
|
1034
|
my $domain; |
|
370
|
|
|
|
|
|
|
my $found; |
|
371
|
664
|
|
|
|
|
1306
|
foreach my $this_domain (@$domains) { |
|
372
|
9
|
100
|
66
|
|
|
37
|
if ($this_domain && defined $this_domain->{messages}->{$msg_ctxt_id}) { |
|
373
|
5
|
|
|
|
|
7
|
@trans = @{$this_domain->{messages}->{$msg_ctxt_id}}; |
|
|
5
|
|
|
|
|
13
|
|
|
374
|
5
|
|
|
|
|
9
|
shift @trans; |
|
375
|
5
|
|
|
|
|
6
|
$domain = $this_domain; |
|
376
|
5
|
|
|
|
|
8
|
$found = 1; |
|
377
|
5
|
|
|
|
|
7
|
last; |
|
378
|
|
|
|
|
|
|
} |
|
379
|
|
|
|
|
|
|
} |
|
380
|
664
|
100
|
|
|
|
1786
|
@trans = ($msgid, $msgid_plural) unless @trans; |
|
381
|
|
|
|
|
|
|
|
|
382
|
664
|
|
|
|
|
1080
|
my $trans = $trans[0]; |
|
383
|
664
|
100
|
|
|
|
1226
|
if ($plural) { |
|
384
|
522
|
50
|
|
|
|
896
|
if ($domain) { |
|
385
|
0
|
|
|
|
|
0
|
my $nplurals = 0; |
|
386
|
0
|
|
|
|
|
0
|
($nplurals, $plural) = &{$domain->{plural_func}} ($n); |
|
|
0
|
|
|
|
|
0
|
|
|
387
|
0
|
0
|
|
|
|
0
|
$plural = 0 unless defined $plural; |
|
388
|
0
|
0
|
|
|
|
0
|
$nplurals = 0 unless defined $nplurals; |
|
389
|
0
|
0
|
|
|
|
0
|
$plural = 0 if $nplurals <= $plural; |
|
390
|
|
|
|
|
|
|
} else { |
|
391
|
522
|
|
100
|
|
|
1168
|
$plural = $n != 1 || 0; |
|
392
|
|
|
|
|
|
|
} |
|
393
|
|
|
|
|
|
|
|
|
394
|
522
|
50
|
|
|
|
1121
|
$trans = $trans[$plural] if defined $trans[$plural]; |
|
395
|
|
|
|
|
|
|
} |
|
396
|
|
|
|
|
|
|
|
|
397
|
664
|
100
|
66
|
|
|
1309
|
if ($found && defined $domain->{po_header}->{charset}) { |
|
398
|
5
|
|
|
|
|
9
|
my $input_codeset = $domain->{po_header}->{charset}; |
|
399
|
|
|
|
|
|
|
# Convert into output charset. |
|
400
|
5
|
|
|
|
|
10
|
my $output_codeset = $__gettext_pp_domain_codeset_bindings->{$domainname}; |
|
401
|
|
|
|
|
|
|
|
|
402
|
5
|
50
|
|
|
|
17
|
$output_codeset = $ENV{OUTPUT_CHARSET} unless defined $output_codeset; |
|
403
|
|
|
|
|
|
|
$output_codeset = __get_codeset ($category, $category_name, |
|
404
|
|
|
|
|
|
|
$domain->{locale_id}) |
|
405
|
5
|
50
|
|
|
|
16
|
unless defined $output_codeset; |
|
406
|
|
|
|
|
|
|
|
|
407
|
5
|
50
|
|
|
|
13
|
unless (defined $output_codeset) { |
|
408
|
|
|
|
|
|
|
# Still no point. |
|
409
|
5
|
|
|
|
|
11
|
my $lc_ctype = __locale_category (POSIX::LC_CTYPE(), |
|
410
|
|
|
|
|
|
|
'LC_CTYPE'); |
|
411
|
5
|
50
|
|
|
|
15
|
$output_codeset = $1 |
|
412
|
|
|
|
|
|
|
if $lc_ctype =~ /^[a-z]{2}(?:_[A-Z]{2})?\.([^@]+)/; |
|
413
|
|
|
|
|
|
|
} |
|
414
|
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
# No point. :-( |
|
416
|
|
|
|
|
|
|
$output_codeset = $domain->{po_header}->{charset} |
|
417
|
5
|
50
|
|
|
|
14
|
unless defined $output_codeset; |
|
418
|
|
|
|
|
|
|
|
|
419
|
5
|
100
|
|
|
|
11
|
if (exists $__gettext_pp_domain_cache->{$output_codeset}) { |
|
420
|
3
|
|
|
|
|
6
|
$output_codeset = $__gettext_pp_domain_cache->{$output_codeset}; |
|
421
|
|
|
|
|
|
|
} else { |
|
422
|
2
|
50
|
|
|
|
7
|
$output_codeset = 'utf-8' if lc $output_codeset eq 'utf8'; |
|
423
|
|
|
|
|
|
|
$output_codeset = |
|
424
|
2
|
|
|
|
|
11
|
$__gettext_pp_domain_cache->{$output_codeset} = |
|
425
|
|
|
|
|
|
|
Locale::Recode->resolveAlias ($output_codeset); |
|
426
|
|
|
|
|
|
|
} |
|
427
|
|
|
|
|
|
|
|
|
428
|
5
|
50
|
33
|
|
|
32
|
if (defined $output_codeset && |
|
429
|
|
|
|
|
|
|
$output_codeset ne $domain->{po_header}->{charset}) { |
|
430
|
|
|
|
|
|
|
# We have to convert. |
|
431
|
0
|
|
|
|
|
0
|
my $recoder; |
|
432
|
|
|
|
|
|
|
|
|
433
|
0
|
0
|
|
|
|
0
|
if (exists |
|
434
|
|
|
|
|
|
|
$__gettext_pp_recoders->{$input_codeset}->{$output_codeset}) { |
|
435
|
0
|
|
|
|
|
0
|
$recoder = $__gettext_pp_recoders->{$input_codeset}->{$output_codeset}; |
|
436
|
|
|
|
|
|
|
} else { |
|
437
|
|
|
|
|
|
|
$recoder = |
|
438
|
0
|
|
|
|
|
0
|
$__gettext_pp_recoders->{$input_codeset}->{$output_codeset} = |
|
439
|
|
|
|
|
|
|
Locale::Recode->new (from => $input_codeset, |
|
440
|
|
|
|
|
|
|
to => $output_codeset, |
|
441
|
|
|
|
|
|
|
); |
|
442
|
|
|
|
|
|
|
} |
|
443
|
|
|
|
|
|
|
|
|
444
|
0
|
|
|
|
|
0
|
$recoder->recode ($trans); |
|
445
|
|
|
|
|
|
|
} |
|
446
|
|
|
|
|
|
|
} |
|
447
|
|
|
|
|
|
|
|
|
448
|
664
|
|
|
|
|
13974
|
return $trans; |
|
449
|
|
|
|
|
|
|
} |
|
450
|
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
sub dcnpgettext ($$$$$$) { |
|
452
|
655
|
|
|
655
|
1
|
1143
|
return &_dcnpgettext_impl; |
|
453
|
|
|
|
|
|
|
} |
|
454
|
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
sub nl_putenv ($) |
|
456
|
|
|
|
|
|
|
{ |
|
457
|
525
|
|
|
525
|
1
|
969
|
my ($envspec) = @_; |
|
458
|
525
|
50
|
|
|
|
1027
|
return unless defined $envspec; |
|
459
|
525
|
50
|
|
|
|
921
|
return unless length $envspec; |
|
460
|
525
|
50
|
|
|
|
1089
|
return if substr ($envspec, 0, 1) eq '='; |
|
461
|
|
|
|
|
|
|
|
|
462
|
525
|
|
|
|
|
1272
|
my ($var, $value) = split /=/, $envspec, 2; |
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
# In Perl we *could* set empty environment variables even under |
|
465
|
|
|
|
|
|
|
# MS-DOS, but for compatibility reasons, we implement the |
|
466
|
|
|
|
|
|
|
# brain-damaged behavior of the Microsoft putenv(). |
|
467
|
525
|
50
|
|
|
|
1258
|
if ($^O eq 'MSWin32') { |
|
468
|
0
|
0
|
|
|
|
0
|
$value = '' unless defined $value; |
|
469
|
0
|
0
|
|
|
|
0
|
if (length $value) { |
|
470
|
0
|
|
|
|
|
0
|
$ENV{$var} = $value; |
|
471
|
|
|
|
|
|
|
} else { |
|
472
|
0
|
|
|
|
|
0
|
delete $ENV{$var}; |
|
473
|
|
|
|
|
|
|
} |
|
474
|
|
|
|
|
|
|
} else { |
|
475
|
525
|
100
|
|
|
|
899
|
if (defined $value) { |
|
476
|
407
|
|
|
|
|
1486
|
$ENV{$var} = $value; |
|
477
|
|
|
|
|
|
|
} else { |
|
478
|
118
|
|
|
|
|
468
|
delete $ENV{$var}; |
|
479
|
|
|
|
|
|
|
} |
|
480
|
|
|
|
|
|
|
} |
|
481
|
|
|
|
|
|
|
|
|
482
|
525
|
|
|
|
|
1004
|
return 1; |
|
483
|
|
|
|
|
|
|
} |
|
484
|
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
sub setlocale($;$) { |
|
486
|
126
|
|
|
126
|
1
|
581
|
require POSIX; |
|
487
|
126
|
|
|
|
|
2397
|
&POSIX::setlocale; |
|
488
|
|
|
|
|
|
|
} |
|
489
|
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
sub __selected_locales { |
|
491
|
9
|
|
|
9
|
|
18
|
my ($locale, $category, $category_name) = @_; |
|
492
|
|
|
|
|
|
|
|
|
493
|
9
|
|
|
|
|
15
|
my @locales; |
|
494
|
|
|
|
|
|
|
my $cache_key; |
|
495
|
|
|
|
|
|
|
|
|
496
|
9
|
100
|
66
|
|
|
34
|
if (defined $ENV{LANGUAGE} && length $ENV{LANGUAGE}) { |
|
|
|
50
|
|
|
|
|
|
|
497
|
2
|
|
|
|
|
7
|
@locales = split /:/, $ENV{LANGUAGE}; |
|
498
|
2
|
|
|
|
|
3
|
$cache_key = $ENV{LANGUAGE}; |
|
499
|
|
|
|
|
|
|
} elsif (!defined $locale) { |
|
500
|
|
|
|
|
|
|
# The system does not have LC_MESSAGES. Guess the value. |
|
501
|
0
|
|
|
|
|
0
|
@locales = $cache_key = __locale_category ($category, |
|
502
|
|
|
|
|
|
|
$category_name); |
|
503
|
|
|
|
|
|
|
} else { |
|
504
|
7
|
|
|
|
|
17
|
@locales = $cache_key = $locale; |
|
505
|
|
|
|
|
|
|
} |
|
506
|
|
|
|
|
|
|
|
|
507
|
9
|
|
|
|
|
29
|
return $cache_key, @locales; |
|
508
|
|
|
|
|
|
|
} |
|
509
|
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
sub __extend_locales { |
|
511
|
2
|
|
|
2
|
|
3
|
my (@locales) = @_; |
|
512
|
|
|
|
|
|
|
|
|
513
|
2
|
|
|
|
|
5
|
my @tries = @locales; |
|
514
|
2
|
|
|
|
|
4
|
my %locale_lookup = map { $_ => $_ } @tries; |
|
|
2
|
|
|
|
|
15
|
|
|
515
|
|
|
|
|
|
|
|
|
516
|
2
|
|
|
|
|
6
|
foreach my $locale (@locales) { |
|
517
|
2
|
100
|
|
|
|
12
|
if ($locale =~ /^([a-z][a-z]) |
|
518
|
|
|
|
|
|
|
(?:(_[A-Z][A-Z])? |
|
519
|
|
|
|
|
|
|
(\.[-_A-Za-z0-9]+)? |
|
520
|
|
|
|
|
|
|
)? |
|
521
|
|
|
|
|
|
|
(\@[-_A-Za-z0-9]+)?$/x) { |
|
522
|
|
|
|
|
|
|
|
|
523
|
1
|
50
|
|
|
|
5
|
if (defined $3) { |
|
524
|
0
|
0
|
|
|
|
0
|
defined $2 ? |
|
525
|
|
|
|
|
|
|
push @tries, $1 . $2 . $3 : push @tries, $1 . $3; |
|
526
|
0
|
|
|
|
|
0
|
$locale_lookup{$tries[-1]} = $locale; |
|
527
|
|
|
|
|
|
|
} |
|
528
|
1
|
50
|
|
|
|
3
|
if (defined $2) { |
|
529
|
1
|
|
|
|
|
3
|
push @tries, $1 . $2; |
|
530
|
1
|
|
|
|
|
4
|
$locale_lookup{$1 . $2} = $locale; |
|
531
|
|
|
|
|
|
|
} |
|
532
|
1
|
50
|
|
|
|
14
|
if (defined $1) { |
|
533
|
1
|
50
|
|
|
|
4
|
push @tries, $1 if defined $1; |
|
534
|
1
|
|
|
|
|
4
|
$locale_lookup{$1} = $locale; |
|
535
|
|
|
|
|
|
|
} |
|
536
|
|
|
|
|
|
|
} |
|
537
|
|
|
|
|
|
|
} |
|
538
|
|
|
|
|
|
|
|
|
539
|
2
|
|
|
|
|
9
|
return \@tries, \%locale_lookup; |
|
540
|
|
|
|
|
|
|
} |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
sub __load_domain { |
|
543
|
664
|
|
|
664
|
|
1321
|
my ($domainname, $category, $category_name, $locale) = @_; |
|
544
|
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
# If no locale was selected for the requested locale category, |
|
546
|
|
|
|
|
|
|
# l10n is disabled completely. This matches the behavior of GNU |
|
547
|
|
|
|
|
|
|
# gettext. |
|
548
|
664
|
50
|
|
|
|
11458
|
if ($category != LC_MESSAGES) { |
|
549
|
|
|
|
|
|
|
# Not supported. |
|
550
|
0
|
|
|
|
|
0
|
return []; |
|
551
|
|
|
|
|
|
|
} |
|
552
|
|
|
|
|
|
|
|
|
553
|
664
|
100
|
66
|
|
|
2398
|
if (!defined $locale && $category != 1729) { |
|
554
|
655
|
|
|
|
|
2104
|
$locale = POSIX::setlocale ($category); |
|
555
|
655
|
50
|
33
|
|
|
2445
|
if (!defined $locale || 'C' eq $locale || 'POSIX' eq $locale) { |
|
|
|
|
33
|
|
|
|
|
|
556
|
655
|
|
|
|
|
1526
|
return []; |
|
557
|
|
|
|
|
|
|
} |
|
558
|
|
|
|
|
|
|
} |
|
559
|
|
|
|
|
|
|
|
|
560
|
9
|
50
|
33
|
|
|
32
|
$domainname = $__gettext_pp_textdomain |
|
561
|
|
|
|
|
|
|
unless defined $domainname && length $domainname; |
|
562
|
|
|
|
|
|
|
|
|
563
|
9
|
|
|
|
|
20
|
my $dir = bindtextdomain ($domainname, ''); |
|
564
|
9
|
50
|
33
|
|
|
35
|
$dir = $__gettext_pp_default_dir unless defined $dir && length $dir; |
|
565
|
|
|
|
|
|
|
|
|
566
|
9
|
50
|
33
|
|
|
33
|
return [] unless defined $dir && length $dir; |
|
567
|
|
|
|
|
|
|
|
|
568
|
9
|
|
|
|
|
20
|
my ($cache_key, @locales) = __selected_locales $locale, $category, $category_name; |
|
569
|
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
# Have we looked that one up already? |
|
571
|
9
|
|
|
|
|
24
|
my $domains = $__gettext_pp_domain_cache->{$dir}->{$cache_key}->{$category_name}->{$domainname}; |
|
572
|
9
|
100
|
|
|
|
23
|
return $domains if defined $domains; |
|
573
|
2
|
50
|
|
|
|
5
|
return [] unless @locales; |
|
574
|
|
|
|
|
|
|
|
|
575
|
2
|
|
|
|
|
4
|
my @dirs = ($dir); |
|
576
|
2
|
|
|
|
|
6
|
my ($tries, $lookup) = __extend_locales @locales; |
|
577
|
|
|
|
|
|
|
|
|
578
|
2
|
50
|
33
|
|
|
11
|
push @dirs, $__gettext_pp_default_dir |
|
579
|
|
|
|
|
|
|
if $__gettext_pp_default_dir && $dir ne $__gettext_pp_default_dir; |
|
580
|
|
|
|
|
|
|
|
|
581
|
2
|
|
|
|
|
5
|
my %seen; |
|
582
|
|
|
|
|
|
|
my %loaded; |
|
583
|
2
|
|
|
|
|
4
|
foreach my $basedir (@dirs) { |
|
584
|
4
|
|
|
|
|
9
|
foreach my $try (@$tries) { |
|
585
|
|
|
|
|
|
|
# If we had already found a catalog for "xy_XY", do not try it |
|
586
|
|
|
|
|
|
|
# again. |
|
587
|
8
|
100
|
|
|
|
20
|
next if $loaded{$try}; |
|
588
|
|
|
|
|
|
|
|
|
589
|
4
|
|
|
|
|
44
|
my $fulldir = File::Spec->catfile($basedir, $try, $category_name); |
|
590
|
4
|
50
|
|
|
|
16
|
next if $seen{$fulldir}++; |
|
591
|
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
# If the cache for unavailable directories is removed, |
|
593
|
|
|
|
|
|
|
# the three lines below should be replaced by: |
|
594
|
|
|
|
|
|
|
# 'next unless -d $fulldir;' |
|
595
|
4
|
50
|
|
|
|
10
|
next if $__gettext_pp_unavailable_dirs->{$fulldir}; |
|
596
|
4
|
100
|
50
|
|
|
150
|
++$__gettext_pp_unavailable_dirs->{$fulldir} and next |
|
597
|
|
|
|
|
|
|
unless -d $fulldir; |
|
598
|
2
|
|
|
|
|
34
|
my $filename = File::Spec->catfile($fulldir, "$domainname.mo"); |
|
599
|
2
|
|
|
|
|
11
|
my $domain = __load_catalog $filename, $try; |
|
600
|
2
|
50
|
|
|
|
7
|
next unless $domain; |
|
601
|
|
|
|
|
|
|
|
|
602
|
2
|
|
|
|
|
7
|
$loaded{$try} = 1; |
|
603
|
|
|
|
|
|
|
|
|
604
|
2
|
|
|
|
|
5
|
$domain->{locale_id} = $lookup->{$try}; |
|
605
|
2
|
|
|
|
|
6
|
push @$domains, $domain; |
|
606
|
|
|
|
|
|
|
} |
|
607
|
|
|
|
|
|
|
} |
|
608
|
|
|
|
|
|
|
|
|
609
|
2
|
100
|
|
|
|
7
|
$domains = [] unless defined $domains; |
|
610
|
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
$__gettext_pp_domain_cache->{$dir} |
|
612
|
|
|
|
|
|
|
->{$cache_key} |
|
613
|
|
|
|
|
|
|
->{$category_name} |
|
614
|
2
|
|
|
|
|
7
|
->{$domainname} = $domains; |
|
615
|
|
|
|
|
|
|
|
|
616
|
2
|
|
|
|
|
10
|
return $domains; |
|
617
|
|
|
|
|
|
|
} |
|
618
|
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
sub __load_catalog |
|
620
|
|
|
|
|
|
|
{ |
|
621
|
2
|
|
|
2
|
|
6
|
my ($filename, $locale) = @_; |
|
622
|
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
# Alternatively we could check the filename for evil characters ... |
|
624
|
|
|
|
|
|
|
# (Important for CGIs). |
|
625
|
2
|
50
|
33
|
|
|
54
|
return unless -f $filename && -r $filename; |
|
626
|
|
|
|
|
|
|
|
|
627
|
2
|
|
|
|
|
10
|
local $/; |
|
628
|
2
|
|
|
|
|
6
|
local *HANDLE; |
|
629
|
|
|
|
|
|
|
|
|
630
|
2
|
50
|
|
|
|
80
|
open HANDLE, "<$filename" |
|
631
|
|
|
|
|
|
|
or return; |
|
632
|
2
|
|
|
|
|
9
|
binmode HANDLE; |
|
633
|
2
|
|
|
|
|
109
|
my $raw = ; |
|
634
|
2
|
|
|
|
|
25
|
close HANDLE; |
|
635
|
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
# Corrupted? |
|
637
|
2
|
50
|
33
|
|
|
14
|
return if ! defined $raw || length $raw < 28; |
|
638
|
|
|
|
|
|
|
|
|
639
|
2
|
|
|
|
|
4
|
my $filesize = length $raw; |
|
640
|
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
# Read the magic number in order to determine the byte order. |
|
642
|
2
|
|
|
|
|
7
|
my $domain = { |
|
643
|
|
|
|
|
|
|
filename => $filename |
|
644
|
|
|
|
|
|
|
}; |
|
645
|
2
|
|
|
|
|
4
|
my $unpack = 'N'; |
|
646
|
2
|
|
|
|
|
12
|
$domain->{magic} = unpack $unpack, substr $raw, 0, 4; |
|
647
|
|
|
|
|
|
|
|
|
648
|
2
|
50
|
|
|
|
6
|
if ($domain->{magic} == 0xde120495) { |
|
|
|
0
|
|
|
|
|
|
|
649
|
2
|
|
|
|
|
5
|
$unpack = 'V'; |
|
650
|
|
|
|
|
|
|
} elsif ($domain->{magic} != 0x950412de) { |
|
651
|
0
|
|
|
|
|
0
|
return; |
|
652
|
|
|
|
|
|
|
} |
|
653
|
2
|
|
|
|
|
7
|
my $domain_unpack = $unpack x 6; |
|
654
|
|
|
|
|
|
|
|
|
655
|
2
|
|
|
|
|
7
|
my ($revision, $num_strings, $msgids_off, $msgstrs_off, |
|
656
|
|
|
|
|
|
|
$hash_size, $hash_off) = |
|
657
|
|
|
|
|
|
|
unpack (($unpack x 6), substr $raw, 4, 24); |
|
658
|
|
|
|
|
|
|
|
|
659
|
2
|
|
|
|
|
6
|
my $major = $revision >> 16; |
|
660
|
2
|
50
|
|
|
|
5
|
return if $major != 0; # Invalid revision number. |
|
661
|
|
|
|
|
|
|
|
|
662
|
2
|
|
|
|
|
4
|
$domain->{revision} = $revision; |
|
663
|
2
|
|
|
|
|
4
|
$domain->{num_strings} = $num_strings; |
|
664
|
2
|
|
|
|
|
4
|
$domain->{msgids_off} = $msgids_off; |
|
665
|
2
|
|
|
|
|
4
|
$domain->{msgstrs_off} = $msgstrs_off; |
|
666
|
2
|
|
|
|
|
3
|
$domain->{hash_size} = $hash_size; |
|
667
|
2
|
|
|
|
|
5
|
$domain->{hash_off} = $hash_off; |
|
668
|
|
|
|
|
|
|
|
|
669
|
2
|
50
|
|
|
|
6
|
return if $msgids_off + 4 * $num_strings > $filesize; |
|
670
|
2
|
50
|
|
|
|
7
|
return if $msgstrs_off + 4 * $num_strings > $filesize; |
|
671
|
|
|
|
|
|
|
|
|
672
|
2
|
|
|
|
|
13
|
my @orig_tab = unpack (($unpack x (2 * $num_strings)), |
|
673
|
|
|
|
|
|
|
substr $raw, $msgids_off, 8 * $num_strings); |
|
674
|
2
|
|
|
|
|
9
|
my @trans_tab = unpack (($unpack x (2 * $num_strings)), |
|
675
|
|
|
|
|
|
|
substr $raw, $msgstrs_off, 8 * $num_strings); |
|
676
|
|
|
|
|
|
|
|
|
677
|
2
|
|
|
|
|
5
|
my $messages = {}; |
|
678
|
|
|
|
|
|
|
|
|
679
|
2
|
|
|
|
|
6
|
for (my $count = 0; $count < 2 * $num_strings; $count += 2) { |
|
680
|
22
|
|
|
|
|
31
|
my $orig_length = $orig_tab[$count]; |
|
681
|
22
|
|
|
|
|
36
|
my $orig_offset = $orig_tab[$count + 1]; |
|
682
|
22
|
|
|
|
|
28
|
my $trans_length = $trans_tab[$count]; |
|
683
|
22
|
|
|
|
|
26
|
my $trans_offset = $trans_tab[$count + 1]; |
|
684
|
|
|
|
|
|
|
|
|
685
|
22
|
50
|
|
|
|
41
|
return if $orig_offset + $orig_length > $filesize; |
|
686
|
22
|
50
|
|
|
|
36
|
return if $trans_offset + $trans_length > $filesize; |
|
687
|
|
|
|
|
|
|
|
|
688
|
22
|
|
|
|
|
58
|
my @origs = split /\000/, substr $raw, $orig_offset, $orig_length; |
|
689
|
22
|
|
|
|
|
43
|
my @trans = split /\000/, substr $raw, $trans_offset, $trans_length; |
|
690
|
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
# The singular is the key, the plural plus all translations is the |
|
692
|
|
|
|
|
|
|
# value. |
|
693
|
22
|
|
|
|
|
35
|
my $msgid = $origs[0]; |
|
694
|
22
|
100
|
66
|
|
|
74
|
$msgid = '' unless defined $msgid && length $msgid; |
|
695
|
22
|
|
|
|
|
42
|
my $msgstr = [ $origs[1], @trans ]; |
|
696
|
22
|
|
|
|
|
71
|
$messages->{$msgid} = $msgstr; |
|
697
|
|
|
|
|
|
|
} |
|
698
|
|
|
|
|
|
|
|
|
699
|
2
|
|
|
|
|
4
|
$domain->{messages} = $messages; |
|
700
|
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
# Try to find po header information. |
|
702
|
2
|
|
|
|
|
5
|
my $po_header = {}; |
|
703
|
2
|
|
|
|
|
4
|
my $null_entry = $messages->{''}->[1]; |
|
704
|
2
|
50
|
|
|
|
4
|
if ($null_entry) { |
|
705
|
2
|
|
|
|
|
17
|
my @lines = split /\n/, $null_entry; |
|
706
|
2
|
|
|
|
|
6
|
foreach my $line (@lines) { |
|
707
|
17
|
|
|
|
|
39
|
my ($key, $value) = split /:/, $line, 2; |
|
708
|
17
|
|
|
|
|
47
|
$key =~ s/-/_/g; |
|
709
|
17
|
|
|
|
|
46
|
$po_header->{lc $key} = $value; |
|
710
|
|
|
|
|
|
|
} |
|
711
|
|
|
|
|
|
|
} |
|
712
|
2
|
|
|
|
|
4
|
$domain->{po_header} = $po_header; |
|
713
|
|
|
|
|
|
|
|
|
714
|
2
|
50
|
|
|
|
6
|
if (exists $domain->{po_header}->{content_type}) { |
|
715
|
2
|
|
|
|
|
3
|
my $content_type = $domain->{po_header}->{content_type}; |
|
716
|
2
|
50
|
|
|
|
12
|
if ($content_type =~ s/.*=//) { |
|
717
|
2
|
|
|
|
|
5
|
$domain->{po_header}->{charset} = $content_type; |
|
718
|
|
|
|
|
|
|
} |
|
719
|
|
|
|
|
|
|
} |
|
720
|
|
|
|
|
|
|
|
|
721
|
2
|
|
100
|
|
|
7
|
my $code = $domain->{po_header}->{plural_forms} || ''; |
|
722
|
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
# Whitespace, locale-independent. |
|
724
|
2
|
|
|
|
|
4
|
my $s = '[ \011-\015]'; |
|
725
|
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
# Untaint the plural header. |
|
727
|
|
|
|
|
|
|
# Keep line breaks as is (Perl 5_005 compatibility). |
|
728
|
|
|
|
|
|
|
$code = $domain->{po_header}->{plural_forms} |
|
729
|
2
|
|
|
|
|
14
|
= __untaint_plural_header $code; |
|
730
|
|
|
|
|
|
|
|
|
731
|
2
|
|
|
|
|
81
|
$domain->{plural_func} = __compile_plural_function $code; |
|
732
|
|
|
|
|
|
|
|
|
733
|
2
|
50
|
33
|
|
|
26
|
unless (defined $domain->{po_header}->{charset} |
|
|
|
|
33
|
|
|
|
|
|
734
|
|
|
|
|
|
|
&& length $domain->{po_header}->{charset} |
|
735
|
|
|
|
|
|
|
&& $locale =~ /^(?:[a-z][a-z]) |
|
736
|
|
|
|
|
|
|
(?:(?:_[A-Z][A-Z])? |
|
737
|
|
|
|
|
|
|
(\.[-_A-Za-z0-9]+)? |
|
738
|
|
|
|
|
|
|
)? |
|
739
|
|
|
|
|
|
|
(?:\@[-_A-Za-z0-9]+)?$/x) { |
|
740
|
0
|
|
|
|
|
0
|
$domain->{po_header}->{charset} = $1; |
|
741
|
|
|
|
|
|
|
} |
|
742
|
|
|
|
|
|
|
|
|
743
|
2
|
50
|
|
|
|
8
|
if (defined $domain->{po_header}->{charset}) { |
|
744
|
|
|
|
|
|
|
$domain->{po_header}->{charset} = |
|
745
|
2
|
|
|
|
|
15
|
Locale::Recode->resolveAlias ($domain->{po_header}->{charset}); |
|
746
|
|
|
|
|
|
|
} |
|
747
|
|
|
|
|
|
|
|
|
748
|
2
|
|
|
|
|
14
|
return $domain; |
|
749
|
|
|
|
|
|
|
} |
|
750
|
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
sub __locale_category |
|
752
|
|
|
|
|
|
|
{ |
|
753
|
5
|
|
|
5
|
|
12
|
my ($category, $category_name) = @_; |
|
754
|
|
|
|
|
|
|
|
|
755
|
5
|
|
|
|
|
6
|
local $@; |
|
756
|
5
|
|
|
|
|
10
|
my $value = eval {POSIX::setlocale ($category)}; |
|
|
5
|
|
|
|
|
12
|
|
|
757
|
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
# We support only XPG syntax, i. e. |
|
759
|
|
|
|
|
|
|
# language[_territory[.codeset]][@modifier]. |
|
760
|
5
|
50
|
33
|
|
|
30
|
undef $value unless (defined $value && |
|
|
|
|
33
|
|
|
|
|
|
761
|
|
|
|
|
|
|
length $value && |
|
762
|
|
|
|
|
|
|
$value =~ /^[a-z][a-z] |
|
763
|
|
|
|
|
|
|
(?:_[A-Z][A-Z] |
|
764
|
|
|
|
|
|
|
(?:\.[-_A-Za-z0-9]+)? |
|
765
|
|
|
|
|
|
|
)? |
|
766
|
|
|
|
|
|
|
(?:\@[-_A-Za-z0-9]+)?$/x); |
|
767
|
|
|
|
|
|
|
|
|
768
|
5
|
50
|
|
|
|
11
|
unless ($value) { |
|
769
|
5
|
|
|
|
|
9
|
$value = $ENV{LC_ALL}; |
|
770
|
5
|
100
|
66
|
|
|
17
|
$value = $ENV{$category_name} unless defined $value && length $value; |
|
771
|
5
|
100
|
66
|
|
|
27
|
$value = $ENV{LANG} unless defined $value && length $value; |
|
772
|
5
|
100
|
66
|
|
|
21
|
return 'C' unless defined $value && length $value; |
|
773
|
|
|
|
|
|
|
} |
|
774
|
|
|
|
|
|
|
|
|
775
|
2
|
50
|
33
|
|
|
24
|
return $value if $value ne 'C' && $value ne 'POSIX'; |
|
776
|
|
|
|
|
|
|
} |
|
777
|
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
sub __get_codeset |
|
779
|
|
|
|
|
|
|
{ |
|
780
|
5
|
|
|
5
|
|
12
|
my ($category, $category_name, $locale_id) = @_; |
|
781
|
|
|
|
|
|
|
|
|
782
|
5
|
|
|
|
|
5
|
local $@; |
|
783
|
5
|
100
|
|
|
|
12
|
unless (defined $has_nl_langinfo) { |
|
784
|
1
|
|
|
|
|
2
|
eval { |
|
785
|
1
|
|
|
|
|
504
|
require I18N::Langinfo; |
|
786
|
|
|
|
|
|
|
}; |
|
787
|
1
|
|
|
|
|
647
|
$has_nl_langinfo = !$@; |
|
788
|
|
|
|
|
|
|
} |
|
789
|
|
|
|
|
|
|
|
|
790
|
5
|
50
|
|
|
|
14
|
if ($has_nl_langinfo) { |
|
791
|
|
|
|
|
|
|
# Try to set the locale via the specified id. |
|
792
|
5
|
|
|
|
|
9
|
my $saved_locale = eval { POSIX::setlocale (LC_ALL) }; |
|
|
5
|
|
|
|
|
8
|
|
|
793
|
5
|
|
|
|
|
11
|
my $had_lc_all = exists $ENV{LC_ALL}; |
|
794
|
5
|
100
|
|
|
|
10
|
my $saved_lc_all = $ENV{LC_ALL} if $had_lc_all; |
|
795
|
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
# Now try to set the locale via the environment. There is no |
|
797
|
|
|
|
|
|
|
# point in calling the langinfo routines if this fails. |
|
798
|
5
|
|
|
|
|
23
|
$ENV{LC_ALL} = $locale_id; |
|
799
|
5
|
|
|
|
|
10
|
my $codeset; |
|
800
|
5
|
|
|
|
|
7
|
my $lc_all = eval { POSIX::setlocale (LC_ALL, $locale_id); }; |
|
|
5
|
|
|
|
|
9
|
|
|
801
|
5
|
50
|
|
|
|
16
|
$codeset = I18N::Langinfo::langinfo (I18N::Langinfo::CODESET()) |
|
802
|
|
|
|
|
|
|
if defined $lc_all; |
|
803
|
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
# Restore environment. |
|
805
|
5
|
50
|
|
|
|
12
|
if ($saved_locale) { |
|
806
|
5
|
|
|
|
|
6
|
eval { POSIX::setlocale (LC_ALL, $saved_locale); } |
|
|
5
|
|
|
|
|
9
|
|
|
807
|
|
|
|
|
|
|
} |
|
808
|
5
|
100
|
|
|
|
12
|
if ($had_lc_all) { |
|
809
|
1
|
50
|
|
|
|
25
|
$ENV{LC_ALL} = $saved_lc_all if $had_lc_all; |
|
810
|
|
|
|
|
|
|
} else { |
|
811
|
4
|
|
|
|
|
14
|
delete $ENV{LC_ALL}; |
|
812
|
|
|
|
|
|
|
} |
|
813
|
5
|
|
|
|
|
13
|
return $codeset; |
|
814
|
|
|
|
|
|
|
} |
|
815
|
|
|
|
|
|
|
|
|
816
|
0
|
|
|
|
|
0
|
return; |
|
817
|
|
|
|
|
|
|
} |
|
818
|
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
sub __untaint_plural_header { |
|
820
|
3
|
|
|
3
|
|
16
|
my ($code) = @_; |
|
821
|
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
# Whitespace, locale-independent. |
|
823
|
3
|
|
|
|
|
6
|
my $s = '[ \t\r\n\013\014]'; |
|
824
|
|
|
|
|
|
|
|
|
825
|
3
|
100
|
|
|
|
169
|
if ($code =~ m{^($s* |
|
826
|
|
|
|
|
|
|
nplurals$s*=$s*[0-9]+ |
|
827
|
|
|
|
|
|
|
$s*;$s* |
|
828
|
|
|
|
|
|
|
plural$s*=$s*(?:$s|[-\?\|\&=!<>+*/\%:;a-zA-Z0-9_\(\)])+ |
|
829
|
|
|
|
|
|
|
)}xms) { |
|
830
|
2
|
|
|
|
|
14
|
return $1; |
|
831
|
|
|
|
|
|
|
} |
|
832
|
|
|
|
|
|
|
|
|
833
|
1
|
|
|
|
|
16
|
return ''; |
|
834
|
|
|
|
|
|
|
} |
|
835
|
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
sub __compile_plural_function { |
|
837
|
3
|
|
|
3
|
|
132
|
my ($code) = @_; |
|
838
|
|
|
|
|
|
|
|
|
839
|
|
|
|
|
|
|
# The leading and trailing space is necessary to be able to match |
|
840
|
|
|
|
|
|
|
# against word boundaries. |
|
841
|
3
|
|
|
|
|
8
|
my $plural_func; |
|
842
|
|
|
|
|
|
|
|
|
843
|
3
|
100
|
|
|
|
10
|
if (length $code) { |
|
844
|
2
|
|
|
|
|
9
|
my $code = ' ' . $code . ' '; |
|
845
|
2
|
|
|
|
|
34
|
$code =~ |
|
846
|
|
|
|
|
|
|
s/(?<=[^_a-zA-Z0-9])[_a-z][_A-Za-z0-9]*(?=[^_a-zA-Z0-9])/\$$&/gs; |
|
847
|
|
|
|
|
|
|
|
|
848
|
2
|
|
|
|
|
9
|
$code = "sub { my \$n = shift || 0; |
|
849
|
|
|
|
|
|
|
my (\$plural, \$nplurals); |
|
850
|
|
|
|
|
|
|
$code; |
|
851
|
|
|
|
|
|
|
return (\$nplurals, \$plural ? \$plural : 0); }"; |
|
852
|
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
# Now try to evaluate the code. There is no need to run the code in |
|
854
|
|
|
|
|
|
|
# a Safe compartment. The above substitutions should have destroyed |
|
855
|
|
|
|
|
|
|
# all evil code. Corrections are welcome! |
|
856
|
|
|
|
|
|
|
#warn $code; |
|
857
|
2
|
|
|
|
|
261
|
$plural_func = eval $code; |
|
858
|
|
|
|
|
|
|
#warn $@ if $@; |
|
859
|
2
|
50
|
|
|
|
11
|
undef $plural_func if $@; |
|
860
|
|
|
|
|
|
|
} |
|
861
|
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
# Default is Germanic plural (which is incorrect for French). |
|
863
|
3
|
100
|
|
|
|
99
|
$plural_func = eval "sub { (2, 1 != shift || 0) }" unless $plural_func; |
|
864
|
|
|
|
|
|
|
|
|
865
|
3
|
|
|
|
|
10
|
return $plural_func; |
|
866
|
|
|
|
|
|
|
} |
|
867
|
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
1; |
|
869
|
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
__END__ |