line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::PO; |
2
|
6
|
|
|
6
|
|
115145
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
229
|
|
3
|
6
|
|
|
6
|
|
28
|
use warnings; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
264
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
34
|
use Carp; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
22754
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
1044
|
|
|
1044
|
1
|
55592
|
my $this = shift; |
10
|
1044
|
|
|
|
|
1789
|
my %options = @_; |
11
|
1044
|
|
33
|
|
|
2809
|
my $class = ref($this) || $this; |
12
|
1044
|
|
|
|
|
1277
|
my $self = {}; |
13
|
1044
|
|
|
|
|
2202
|
bless $self, $class; |
14
|
1044
|
|
|
|
|
1862
|
$self->_flags([]); |
15
|
1044
|
100
|
|
|
|
1927
|
$self->fuzzy_msgid($options{'-fuzzy_msgid'}) if defined($options{'-fuzzy_msgid'}); |
16
|
1044
|
100
|
|
|
|
1554
|
$self->fuzzy_msgid_plural($options{'-fuzzy_msgid_plural'}) |
17
|
|
|
|
|
|
|
if defined($options{'-fuzzy_msgid_plural'}); |
18
|
1044
|
100
|
|
|
|
1444
|
$self->msgid($options{'-msgid'}) if defined($options{'-msgid'}); |
19
|
1044
|
100
|
|
|
|
1483
|
$self->msgid_plural($options{'-msgid_plural'}) |
20
|
|
|
|
|
|
|
if defined($options{'-msgid_plural'}); |
21
|
1044
|
100
|
|
|
|
1728
|
$self->msgstr($options{'-msgstr'}) if defined($options{'-msgstr'}); |
22
|
1044
|
100
|
|
|
|
1562
|
$self->msgstr_n($options{'-msgstr_n'}) |
23
|
|
|
|
|
|
|
if defined($options{'-msgstr_n'}); |
24
|
1044
|
50
|
|
|
|
1544
|
$self->msgctxt($options{'-msgctxt'}) if defined($options{'-msgctxt'}); |
25
|
1044
|
50
|
|
|
|
1392
|
$self->fuzzy_msgctxt($options{'-fuzzy_msgctxt'}) |
26
|
|
|
|
|
|
|
if defined($options{'-fuzzy_msgctxt'}); |
27
|
1044
|
100
|
|
|
|
1443
|
$self->comment($options{'-comment'}) if defined($options{'-comment'}); |
28
|
1044
|
100
|
|
|
|
1356
|
$self->fuzzy($options{'-fuzzy'}) if defined($options{'-fuzzy'}); |
29
|
1044
|
50
|
|
|
|
1437
|
$self->automatic($options{'-automatic'}) |
30
|
|
|
|
|
|
|
if defined($options{'-automatic'}); |
31
|
1044
|
50
|
|
|
|
1398
|
$self->reference($options{'-reference'}) |
32
|
|
|
|
|
|
|
if defined($options{'-reference'}); |
33
|
1044
|
50
|
|
|
|
1455
|
$self->c_format(1) if defined($options{'-c-format'}); |
34
|
1044
|
50
|
|
|
|
1456
|
$self->c_format(1) if defined($options{'-c_format'}); |
35
|
1044
|
50
|
|
|
|
1525
|
$self->c_format(0) if defined($options{'-no-c-format'}); |
36
|
1044
|
50
|
|
|
|
1353
|
$self->c_format(0) if defined($options{'-no_c_format'}); |
37
|
1044
|
100
|
|
|
|
2784
|
$self->loaded_line_number($options{'-loaded_line_number'}) |
38
|
|
|
|
|
|
|
if defined($options{'-loaded_line_number'}); |
39
|
1044
|
|
|
|
|
1817
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub fuzzy_msgctxt { |
43
|
1051
|
|
|
1051
|
1
|
825
|
my $self = shift; |
44
|
1051
|
100
|
|
|
|
2645
|
@_ ? $self->{'fuzzy_msgctxt'} = $self->quote(shift) : $self->{'fuzzy_msgctxt'}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub fuzzy_msgid { |
48
|
1067
|
|
|
1067
|
1
|
885
|
my $self = shift; |
49
|
1067
|
100
|
|
|
|
2242
|
@_ ? $self->{'fuzzy_msgid'} = $self->quote(shift) : $self->{'fuzzy_msgid'}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub fuzzy_msgid_plural { |
53
|
1054
|
|
|
1054
|
1
|
832
|
my $self = shift; |
54
|
|
|
|
|
|
|
@_ |
55
|
1054
|
100
|
|
|
|
2282
|
? $self->{'fuzzy_msgid_plural'} = $self->quote(shift) |
56
|
|
|
|
|
|
|
: $self->{'fuzzy_msgid_plural'}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub msgctxt { |
60
|
1057
|
|
|
1057
|
1
|
857
|
my $self = shift; |
61
|
1057
|
100
|
|
|
|
2270
|
@_ ? $self->{'msgctxt'} = $self->quote(shift) : $self->{'msgctxt'}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub msgid { |
65
|
2095
|
|
|
2095
|
1
|
2646
|
my $self = shift; |
66
|
2095
|
100
|
|
|
|
4608
|
@_ ? $self->{'msgid'} = $self->quote(shift) : $self->{'msgid'}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub msgid_plural { |
70
|
1065
|
|
|
1065
|
1
|
947
|
my $self = shift; |
71
|
|
|
|
|
|
|
@_ |
72
|
1065
|
100
|
|
|
|
2631
|
? $self->{'msgid_plural'} = $self->quote(shift) |
73
|
|
|
|
|
|
|
: $self->{'msgid_plural'}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub msgstr { |
77
|
3125
|
|
|
3125
|
1
|
5535
|
my $self = shift; |
78
|
3125
|
100
|
|
|
|
7275
|
@_ ? $self->{'msgstr'} = $self->quote(shift) : $self->{'msgstr'}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub msgstr_n { |
82
|
1057
|
|
|
1057
|
1
|
986
|
my $self = shift; |
83
|
1057
|
100
|
|
|
|
1621
|
if (@_) { |
84
|
8
|
|
|
|
|
9
|
my $hashref = shift; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# check that we have a hashref. |
87
|
8
|
50
|
|
|
|
29
|
croak 'Argument to msgstr_n must be a hashref: { n => "string n", ... }.' |
88
|
|
|
|
|
|
|
unless ref($hashref) eq 'HASH'; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Check that the keys are all numbers. |
91
|
15
|
|
|
|
|
58
|
croak 'Keys to msgstr_n hashref must be numbers' |
92
|
8
|
50
|
|
|
|
28
|
if grep {m/\D/} keys %$hashref; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Quote all the values in the hashref. |
95
|
8
|
|
|
|
|
36
|
$self->{'msgstr_n'}{$_} = $self->quote($$hashref{$_}) for keys %$hashref; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
1057
|
|
|
|
|
2048
|
return $self->{'msgstr_n'}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub comment { |
103
|
1112
|
|
|
1112
|
1
|
933
|
my $self = shift; |
104
|
1112
|
100
|
|
|
|
2974
|
@_ ? $self->{'comment'} = shift : $self->{'comment'}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub automatic { |
108
|
1049
|
|
|
1049
|
1
|
867
|
my $self = shift; |
109
|
1049
|
50
|
|
|
|
2232
|
@_ ? $self->{'automatic'} = shift : $self->{'automatic'}; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub reference { |
113
|
4126
|
|
|
4126
|
1
|
3440
|
my $self = shift; |
114
|
4126
|
100
|
|
|
|
12907
|
@_ ? $self->{'reference'} = shift : $self->{'reference'}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub obsolete { |
118
|
2108
|
|
|
2108
|
1
|
2246
|
my $self = shift; |
119
|
2108
|
100
|
|
|
|
4591
|
@_ ? $self->{'obsolete'} = shift : $self->{'obsolete'}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub fuzzy { |
123
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
124
|
|
|
|
|
|
|
|
125
|
1
|
50
|
|
|
|
3
|
if (@_) { |
126
|
1
|
|
|
|
|
1
|
my $value = shift; |
127
|
1
|
50
|
|
|
|
4
|
$value ? $self->add_flag('fuzzy') : $self->remove_flag('fuzzy'); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
1
|
|
|
|
|
3
|
return $self->has_flag('fuzzy'); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub c_format { |
134
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
0
|
return $self->_tri_value_flag('c-format', @_); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub php_format { |
140
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
0
|
return $self->_tri_value_flag('php-format', @_); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub _flags { |
146
|
2119
|
|
|
2119
|
|
1754
|
my $self = shift; |
147
|
2119
|
100
|
|
|
|
5823
|
@_ ? $self->{'_flags'} = shift : $self->{'_flags'}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _tri_value_flag { |
151
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
152
|
0
|
|
|
|
|
0
|
my $flag_name = shift; |
153
|
0
|
0
|
|
|
|
0
|
if (@_) { # set or clear the flags |
154
|
0
|
|
|
|
|
0
|
my $value = shift; |
155
|
0
|
0
|
0
|
|
|
0
|
if (!defined($value) || $value eq "") { |
|
|
0
|
|
|
|
|
|
156
|
0
|
|
|
|
|
0
|
$self->remove_flag("$flag_name"); |
157
|
0
|
|
|
|
|
0
|
$self->remove_flag("no-$flag_name"); |
158
|
0
|
|
|
|
|
0
|
return undef; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
elsif ($value) { |
161
|
0
|
|
|
|
|
0
|
$self->add_flag("$flag_name"); |
162
|
0
|
|
|
|
|
0
|
$self->remove_flag("no-$flag_name"); |
163
|
0
|
|
|
|
|
0
|
return 1; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
else { |
166
|
0
|
|
|
|
|
0
|
$self->add_flag("no-$flag_name"); |
167
|
0
|
|
|
|
|
0
|
$self->remove_flag("$flag_name"); |
168
|
0
|
|
|
|
|
0
|
return 0; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
else { # check the flags |
172
|
0
|
0
|
|
|
|
0
|
return 1 if $self->has_flag("$flag_name"); |
173
|
0
|
0
|
|
|
|
0
|
return 0 if $self->has_flag("no-$flag_name"); |
174
|
0
|
|
|
|
|
0
|
return undef; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub add_flag { |
179
|
25
|
|
|
25
|
1
|
66
|
my ($self, $flag_name) = @_; |
180
|
25
|
|
|
|
|
23
|
push @{$self->_flags}, $flag_name; |
|
25
|
|
|
|
|
44
|
|
181
|
25
|
|
|
|
|
123
|
return; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub remove_flag { |
185
|
0
|
|
|
0
|
1
|
0
|
my ($self, $flag_name) = @_; |
186
|
0
|
|
|
|
|
0
|
my @new_flags; |
187
|
0
|
|
|
|
|
0
|
foreach my $flag (@{$self->_flags}) { |
|
0
|
|
|
|
|
0
|
|
188
|
0
|
0
|
|
|
|
0
|
push @new_flags, $flag unless $flag eq $flag_name; |
189
|
|
|
|
|
|
|
} |
190
|
0
|
|
|
|
|
0
|
$self->_flags(\@new_flags); |
191
|
0
|
|
|
|
|
0
|
return; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub has_flag { |
195
|
1
|
|
|
1
|
1
|
1
|
my ($self, $flag_name) = @_; |
196
|
1
|
|
|
|
|
2
|
foreach my $flag (@{$self->_flags}) { |
|
1
|
|
|
|
|
2
|
|
197
|
1
|
50
|
|
|
|
3
|
return 1 if $flag eq $flag_name; |
198
|
|
|
|
|
|
|
} |
199
|
0
|
|
|
|
|
0
|
return; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub loaded_line_number { |
203
|
1041
|
|
|
1041
|
1
|
1593
|
my $self = shift; |
204
|
1041
|
100
|
|
|
|
1940
|
@_ ? $self->{'loaded_line_number'} = shift : $self->{'loaded_line_number'}; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub _normalize_str { |
208
|
2131
|
|
|
2131
|
|
1772
|
my $self = shift; |
209
|
2131
|
|
|
|
|
1839
|
my $string = shift; |
210
|
2131
|
|
|
|
|
2984
|
my $dequoted = $self->dequote($string); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# Multiline: this isn't quite perfect, but fast and easy |
213
|
2131
|
100
|
66
|
|
|
7948
|
if (defined $dequoted && $dequoted =~ /\n/) { |
214
|
188
|
|
|
|
|
175
|
my $output; |
215
|
|
|
|
|
|
|
my @lines; |
216
|
188
|
|
|
|
|
623
|
@lines = split(/\n/, $dequoted, -1); |
217
|
188
|
|
|
|
|
239
|
my $lastline = pop @lines; # special treatment for this one |
218
|
188
|
100
|
|
|
|
384
|
$output = qq{""\n} if ($#lines != 0); |
219
|
188
|
|
|
|
|
284
|
foreach (@lines) { |
220
|
309
|
|
|
|
|
650
|
$output .= $self->quote("$_\n") . "\n"; |
221
|
|
|
|
|
|
|
} |
222
|
188
|
100
|
|
|
|
388
|
$output .= $self->quote($lastline) . "\n" if $lastline ne ""; |
223
|
188
|
|
|
|
|
467
|
return $output; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
# Single line |
226
|
|
|
|
|
|
|
else { |
227
|
1943
|
|
50
|
|
|
5371
|
return ($string || "") . "\n"; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub _fuzzy_normalize_str { |
232
|
13
|
|
|
13
|
|
8
|
my $self = shift; |
233
|
13
|
|
|
|
|
12
|
my $string = shift; |
234
|
13
|
|
|
|
|
7
|
my $prefix = shift; |
235
|
|
|
|
|
|
|
|
236
|
13
|
|
|
|
|
15
|
my $normalized = $self->_normalize_str($string); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# on newlines, start them with "#| " or "#~| " |
239
|
13
|
|
|
|
|
22
|
$normalized =~ s/\n"/\n$prefix"/g; |
240
|
|
|
|
|
|
|
|
241
|
13
|
|
|
|
|
20
|
return $normalized; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub dump { |
245
|
1049
|
|
|
1049
|
1
|
6289
|
my $self = shift; |
246
|
1049
|
100
|
|
|
|
1327
|
my $obsolete = $self->obsolete ? '#~ ' : ''; |
247
|
1049
|
100
|
|
|
|
1315
|
my $fuzzy_prefix = $self->obsolete ? '#~| ' : '#| '; |
248
|
1049
|
|
|
|
|
772
|
my $dump; |
249
|
|
|
|
|
|
|
|
250
|
1049
|
100
|
|
|
|
1702
|
$dump = $self->_dump_multi_comment($self->comment, "# ") |
251
|
|
|
|
|
|
|
if ($self->comment); |
252
|
1049
|
50
|
|
|
|
1367
|
$dump .= $self->_dump_multi_comment($self->automatic, "#. ") |
253
|
|
|
|
|
|
|
if ($self->automatic); |
254
|
1049
|
100
|
|
|
|
1582
|
$dump .= $self->_dump_multi_comment($self->reference, "#: ") |
255
|
|
|
|
|
|
|
if ($self->reference); |
256
|
|
|
|
|
|
|
|
257
|
1049
|
|
|
|
|
1131
|
my $flags = ''; |
258
|
|
|
|
|
|
|
|
259
|
1049
|
|
|
|
|
866
|
foreach my $flag (@{$self->_flags}) { |
|
1049
|
|
|
|
|
1453
|
|
260
|
29
|
|
|
|
|
70
|
$flags .= ", $flag"; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
1049
|
100
|
|
|
|
1955
|
$dump .= "#$flags\n" |
264
|
|
|
|
|
|
|
if length $flags; |
265
|
|
|
|
|
|
|
|
266
|
1049
|
100
|
|
|
|
1372
|
$dump |
267
|
|
|
|
|
|
|
.= "${fuzzy_prefix}msgctxt " |
268
|
|
|
|
|
|
|
. $self->_fuzzy_normalize_str($self->fuzzy_msgctxt, $fuzzy_prefix) |
269
|
|
|
|
|
|
|
if $self->fuzzy_msgctxt; |
270
|
1049
|
100
|
|
|
|
1368
|
$dump |
271
|
|
|
|
|
|
|
.= "${fuzzy_prefix}msgid " |
272
|
|
|
|
|
|
|
. $self->_fuzzy_normalize_str($self->fuzzy_msgid, $fuzzy_prefix) |
273
|
|
|
|
|
|
|
if $self->fuzzy_msgid; |
274
|
1049
|
100
|
|
|
|
1343
|
$dump |
275
|
|
|
|
|
|
|
.= "${fuzzy_prefix}msgid_plural " |
276
|
|
|
|
|
|
|
. $self->_fuzzy_normalize_str($self->fuzzy_msgid_plural, $fuzzy_prefix) |
277
|
|
|
|
|
|
|
if $self->fuzzy_msgid_plural; |
278
|
|
|
|
|
|
|
|
279
|
1049
|
100
|
|
|
|
1294
|
$dump .= "${obsolete}msgctxt " . $self->_normalize_str($self->msgctxt) |
280
|
|
|
|
|
|
|
if $self->msgctxt; |
281
|
1049
|
|
|
|
|
1617
|
$dump .= "${obsolete}msgid " . $self->_normalize_str($self->msgid); |
282
|
1049
|
100
|
|
|
|
1780
|
$dump .= "${obsolete}msgid_plural " . $self->_normalize_str($self->msgid_plural) |
283
|
|
|
|
|
|
|
if $self->msgid_plural; |
284
|
|
|
|
|
|
|
|
285
|
1049
|
100
|
|
|
|
1480
|
$dump .= "${obsolete}msgstr " . $self->_normalize_str($self->msgstr) if $self->msgstr; |
286
|
|
|
|
|
|
|
|
287
|
1049
|
100
|
|
|
|
1855
|
if (my $msgstr_n = $self->msgstr_n) { |
288
|
9
|
|
|
|
|
63
|
$dump .= "${obsolete}msgstr[$_] " . $self->_normalize_str($$msgstr_n{$_}) |
289
|
9
|
|
|
|
|
68
|
for sort { $a <=> $b } keys %$msgstr_n; |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
1049
|
|
|
|
|
977
|
$dump .= "\n"; |
293
|
1049
|
|
|
|
|
3539
|
return $dump; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
sub _dump_multi_comment { |
297
|
1032
|
|
|
1032
|
|
906
|
my $self = shift; |
298
|
1032
|
|
|
|
|
833
|
my $comment = shift; |
299
|
1032
|
|
|
|
|
801
|
my $leader = shift; |
300
|
1032
|
|
|
|
|
837
|
my $chopped = $leader; |
301
|
1032
|
|
|
|
|
960
|
chop($chopped); |
302
|
1032
|
|
|
|
|
1131
|
my $result = $leader . $comment; |
303
|
1032
|
|
|
|
|
1264
|
$result =~ s/\n/\n$leader/g; |
304
|
1032
|
|
|
|
|
2558
|
$result =~ s/^$leader$/$chopped/gm; |
305
|
1032
|
|
|
|
|
942
|
$result .= "\n"; |
306
|
1032
|
|
|
|
|
1887
|
return $result; |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
# Quote a string properly |
310
|
|
|
|
|
|
|
sub quote { |
311
|
2429
|
|
|
2429
|
1
|
1963
|
my $self = shift; |
312
|
2429
|
|
|
|
|
2107
|
my $string = shift; |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
return undef |
315
|
2429
|
50
|
|
|
|
3921
|
unless defined $string; |
316
|
|
|
|
|
|
|
|
317
|
2429
|
|
|
|
|
2529
|
$string =~ s/\\(?!t)/\\\\/g; # \t is a tab |
318
|
2429
|
|
|
|
|
1963
|
$string =~ s/"/\\"/g; |
319
|
2429
|
|
|
|
|
2614
|
$string =~ s/\n/\\n/g; |
320
|
2429
|
|
|
|
|
5820
|
return "\"$string\""; |
321
|
|
|
|
|
|
|
} |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
sub dequote { |
324
|
4343
|
|
|
4343
|
1
|
3998
|
my $self = shift; |
325
|
4343
|
|
|
|
|
5468
|
my $string = shift; |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
return undef |
328
|
4343
|
50
|
|
|
|
6747
|
unless defined $string; |
329
|
|
|
|
|
|
|
|
330
|
4343
|
|
|
|
|
14118
|
$string =~ s/^"(.*)"/$1/; |
331
|
4343
|
|
|
|
|
4972
|
$string =~ s/\\"/"/g; |
332
|
4343
|
|
|
|
|
4426
|
$string =~ s/(?
|
333
|
4343
|
|
|
|
|
3784
|
$string =~ s/(?
|
334
|
4343
|
|
|
|
|
3363
|
$string =~ s/(?
|
335
|
4343
|
|
|
|
|
3459
|
$string =~ s/\\{4}n/\\\\n/g; # \ followed by inline newline |
336
|
4343
|
|
|
|
|
3526
|
$string =~ s/\\\\(?!n)/\\/g; # all slashes not related to a newline |
337
|
4343
|
|
|
|
|
7763
|
return $string; |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
sub save_file_fromarray { |
341
|
8
|
|
|
8
|
1
|
3520
|
my $self = shift; |
342
|
8
|
|
|
|
|
64
|
$self->_save_file(0, @_); |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
sub save_file_fromhash { |
346
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
347
|
0
|
|
|
|
|
0
|
$self->_save_file(1, @_); |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
sub _save_file { |
351
|
8
|
|
|
8
|
|
20
|
my $self = shift; |
352
|
8
|
|
|
|
|
17
|
my $ashash = shift; |
353
|
8
|
|
|
|
|
12
|
my $file = shift; |
354
|
8
|
|
|
|
|
13
|
my $entries = shift; |
355
|
8
|
|
|
|
|
13
|
my $encoding = shift; |
356
|
|
|
|
|
|
|
|
357
|
8
|
100
|
|
|
|
22721
|
open(OUT, defined($encoding) ? ">:encoding($encoding)" : ">", $file) |
|
|
50
|
|
|
|
|
|
358
|
|
|
|
|
|
|
or return undef; |
359
|
8
|
50
|
|
|
|
92
|
if ($ashash) { |
360
|
0
|
|
|
|
|
0
|
foreach (sort keys %$entries) { |
361
|
0
|
|
|
|
|
0
|
print OUT $entries->{$_}->dump; |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
else { |
365
|
8
|
|
|
|
|
29
|
foreach (@$entries) { |
366
|
1037
|
|
|
|
|
1634
|
print OUT $_->dump; |
367
|
|
|
|
|
|
|
} |
368
|
|
|
|
|
|
|
} |
369
|
|
|
|
|
|
|
|
370
|
8
|
|
|
|
|
558
|
close OUT; |
371
|
|
|
|
|
|
|
} |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
sub load_file_asarray { |
374
|
9
|
|
|
9
|
1
|
2190
|
my $self = shift; |
375
|
9
|
|
|
|
|
48
|
$self->_load_file(0, @_); |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
sub load_file_ashash { |
379
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
380
|
0
|
|
|
|
|
0
|
$self->_load_file(1, @_); |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
sub _load_file { |
384
|
9
|
|
|
9
|
|
19
|
my $self = shift; |
385
|
9
|
|
|
|
|
16
|
my $ashash = shift; |
386
|
9
|
|
|
|
|
17
|
my $file = shift; |
387
|
9
|
|
|
|
|
14
|
my $encoding = shift; |
388
|
9
|
|
33
|
|
|
80
|
my $class = ref $self || $self; |
389
|
9
|
|
|
|
|
15
|
my (@entries, %entries); |
390
|
9
|
|
|
|
|
70
|
my $line_number = 0; |
391
|
9
|
|
|
|
|
17
|
my $po; |
392
|
|
|
|
|
|
|
my %buffer; |
393
|
0
|
|
|
|
|
0
|
my $last_buffer; |
394
|
|
|
|
|
|
|
|
395
|
9
|
100
|
|
1
|
|
393
|
open(IN, defined($encoding) ? "<:encoding($encoding)" : "<", $file) |
|
1
|
50
|
|
|
|
11
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
396
|
|
|
|
|
|
|
or return undef; |
397
|
|
|
|
|
|
|
|
398
|
9
|
|
|
|
|
12293
|
while () { |
399
|
4314
|
|
|
|
|
4018
|
chomp; |
400
|
4314
|
|
|
|
|
3080
|
$line_number++; |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
# |
403
|
|
|
|
|
|
|
# Strip trailing \r\n chars |
404
|
|
|
|
|
|
|
# |
405
|
|
|
|
|
|
|
# This can possibly have an effect only on msys (on which chomp |
406
|
|
|
|
|
|
|
# seems to leave some trailing \r chars) and on MacOS that has |
407
|
|
|
|
|
|
|
# reversed newline (\n\r). |
408
|
|
|
|
|
|
|
# Note that our stripping of those trailing chars is only going to be |
409
|
|
|
|
|
|
|
# useful when writing from one platform and reading on another. |
410
|
4314
|
|
|
|
|
18886
|
s{[\r\n]*$}{}; |
411
|
|
|
|
|
|
|
|
412
|
4314
|
100
|
100
|
|
|
33574
|
if (/^$/) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
# Empty line. End of an entry. |
415
|
|
|
|
|
|
|
|
416
|
1037
|
50
|
|
|
|
1705
|
if (defined($po)) { |
417
|
1037
|
100
|
|
|
|
1673
|
$po->fuzzy_msgctxt($buffer{fuzzy_msgctxt}) |
418
|
|
|
|
|
|
|
if defined $buffer{fuzzy_msgctxt}; |
419
|
1037
|
100
|
|
|
|
1592
|
$po->fuzzy_msgid($buffer{fuzzy_msgid}) if defined $buffer{fuzzy_msgid}; |
420
|
1037
|
100
|
|
|
|
1462
|
$po->fuzzy_msgid_plural($buffer{fuzzy_msgid_plural}) |
421
|
|
|
|
|
|
|
if defined $buffer{fuzzy_msgid_plural}; |
422
|
1037
|
100
|
|
|
|
1431
|
$po->msgctxt($buffer{msgctxt}) if defined $buffer{msgctxt}; |
423
|
1037
|
50
|
|
|
|
2610
|
$po->msgid($buffer{msgid}) if defined $buffer{msgid}; |
424
|
1037
|
100
|
|
|
|
1835
|
$po->msgid_plural($buffer{msgid_plural}) if defined $buffer{msgid_plural}; |
425
|
1037
|
100
|
|
|
|
2287
|
$po->msgstr($buffer{msgstr}) if defined $buffer{msgstr}; |
426
|
1037
|
100
|
|
|
|
1706
|
$po->msgstr_n($buffer{msgstr_n}) if defined $buffer{msgstr_n}; |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
# ashash |
430
|
1037
|
50
|
|
|
|
1273
|
if ($ashash) { |
431
|
0
|
0
|
|
|
|
0
|
$entries{$po->msgid} = $po |
432
|
|
|
|
|
|
|
if ($po->_hash_key_ok(\%entries)); |
433
|
|
|
|
|
|
|
} |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
# asarray |
436
|
|
|
|
|
|
|
else { |
437
|
1037
|
|
|
|
|
1180
|
push(@entries, $po); |
438
|
|
|
|
|
|
|
} |
439
|
|
|
|
|
|
|
|
440
|
1037
|
|
|
|
|
1003
|
undef $po; |
441
|
1037
|
|
|
|
|
767
|
undef $last_buffer; |
442
|
1037
|
|
|
|
|
4234
|
%buffer = (); |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
} |
445
|
|
|
|
|
|
|
elsif (/^#\s+(.*)/ or /^#()$/) { |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
# Translator comments |
448
|
19
|
100
|
|
|
|
66
|
$po = $class->new(-loaded_line_number => $line_number) unless defined($po); |
449
|
19
|
100
|
|
|
|
47
|
if (defined($po->comment)) { |
450
|
15
|
|
|
|
|
26
|
$po->comment($po->comment . "\n$1"); |
451
|
|
|
|
|
|
|
} |
452
|
|
|
|
|
|
|
else { |
453
|
4
|
|
|
|
|
18
|
$po->comment($1); |
454
|
|
|
|
|
|
|
} |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
elsif (/^#\.\s*(.*)/) { |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
# Automatic comments |
459
|
0
|
0
|
|
|
|
0
|
$po = $class->new(-loaded_line_number => $line_number) unless defined($po); |
460
|
0
|
0
|
|
|
|
0
|
if (defined($po->automatic)) { |
461
|
0
|
|
|
|
|
0
|
$po->automatic($po->automatic . "\n$1"); |
462
|
|
|
|
|
|
|
} |
463
|
|
|
|
|
|
|
else { |
464
|
0
|
|
|
|
|
0
|
$po->automatic($1); |
465
|
|
|
|
|
|
|
} |
466
|
|
|
|
|
|
|
} |
467
|
|
|
|
|
|
|
elsif (/^#:\s+(.*)/) { |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
# reference |
470
|
1026
|
100
|
|
|
|
3759
|
$po = $class->new(-loaded_line_number => $line_number) unless defined($po); |
471
|
1026
|
100
|
|
|
|
1658
|
if (defined($po->reference)) { |
472
|
2
|
|
|
|
|
6
|
$po->reference($po->reference . "\n$1"); |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
else { |
475
|
1024
|
|
|
|
|
1269
|
$po->reference($1); |
476
|
|
|
|
|
|
|
} |
477
|
|
|
|
|
|
|
} |
478
|
|
|
|
|
|
|
elsif (/^#,\s+(.*)/) { |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
# flags |
481
|
20
|
|
|
|
|
90
|
my @flags = split /\s*[,]\s*/, $1; |
482
|
20
|
100
|
|
|
|
64
|
$po = $class->new(-loaded_line_number => $line_number) unless defined($po); |
483
|
20
|
|
|
|
|
37
|
foreach my $flag (@flags) { |
484
|
24
|
|
|
|
|
81
|
$po->add_flag($flag); |
485
|
|
|
|
|
|
|
} |
486
|
|
|
|
|
|
|
} |
487
|
|
|
|
|
|
|
elsif (/^#(~)?\|\s+msgctxt\s+(.*)/) { |
488
|
1
|
50
|
|
|
|
7
|
$po = $class->new(-loaded_line_number => $line_number) unless defined($po); |
489
|
1
|
|
|
|
|
2
|
$buffer{fuzzy_msgctxt} = $self->dequote($2); |
490
|
1
|
|
|
|
|
1
|
$last_buffer = \$buffer{fuzzy_msgctxt}; |
491
|
1
|
50
|
|
|
|
4
|
$po->obsolete(1) if $1; |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
elsif (/^#(~)?\|\s+msgid\s+(.*)/) { |
494
|
7
|
50
|
|
|
|
12
|
$po = $class->new(-loaded_line_number => $line_number) unless defined($po); |
495
|
7
|
|
|
|
|
12
|
$buffer{fuzzy_msgid} = $self->dequote($2); |
496
|
7
|
|
|
|
|
7
|
$last_buffer = \$buffer{fuzzy_msgid}; |
497
|
7
|
100
|
|
|
|
21
|
$po->obsolete(1) if $1; |
498
|
|
|
|
|
|
|
} |
499
|
|
|
|
|
|
|
elsif (/^#(~)?\|\s+msgid_plural\s+(.*)/) { |
500
|
1
|
50
|
|
|
|
2
|
$po = $class->new(-loaded_line_number => $line_number) unless defined($po); |
501
|
1
|
|
|
|
|
3
|
$buffer{fuzzy_msgid_plural} = $self->dequote($2); |
502
|
1
|
|
|
|
|
1
|
$last_buffer = \$buffer{fuzzy_msgid_plural}; |
503
|
1
|
50
|
|
|
|
4
|
$po->obsolete(1) if $1; |
504
|
|
|
|
|
|
|
} |
505
|
|
|
|
|
|
|
elsif (/^(#~\s+)?msgctxt\s+(.*)/) { |
506
|
4
|
50
|
|
|
|
13
|
$po = $class->new(-loaded_line_number => $line_number) unless defined($po); |
507
|
4
|
|
|
|
|
10
|
$buffer{msgctxt} = $self->dequote($2); |
508
|
4
|
|
|
|
|
8
|
$last_buffer = \$buffer{msgctxt}; |
509
|
4
|
50
|
|
|
|
29
|
$po->obsolete(1) if $1; |
510
|
|
|
|
|
|
|
} |
511
|
|
|
|
|
|
|
elsif (/^(#~\s+)?msgid\s+(.*)/) { |
512
|
1039
|
100
|
|
|
|
1799
|
$po = $class->new(-loaded_line_number => $line_number) unless defined($po); |
513
|
1039
|
|
|
|
|
1941
|
$buffer{msgid} = $self->dequote($2); |
514
|
1039
|
|
|
|
|
1179
|
$last_buffer = \$buffer{msgid}; |
515
|
1039
|
100
|
|
|
|
4254
|
$po->obsolete(1) if $1; |
516
|
|
|
|
|
|
|
} |
517
|
|
|
|
|
|
|
elsif (/^(#~\s+)?msgid_plural\s+(.*)/) { |
518
|
5
|
50
|
|
|
|
14
|
$po = $class->new(-loaded_line_number => $line_number) unless defined($po); |
519
|
5
|
|
|
|
|
12
|
$buffer{msgid_plural} = $self->dequote($2); |
520
|
5
|
|
|
|
|
9
|
$last_buffer = \$buffer{msgid_plural}; |
521
|
5
|
100
|
|
|
|
29
|
$po->obsolete(1) if $1; |
522
|
|
|
|
|
|
|
} |
523
|
|
|
|
|
|
|
elsif (/^(?:#~\s+)?msgstr\s+(.*)/) { |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
# translated string |
526
|
1033
|
|
|
|
|
1681
|
$buffer{msgstr} = $self->dequote($1); |
527
|
1033
|
|
|
|
|
3348
|
$last_buffer = \$buffer{msgstr}; |
528
|
|
|
|
|
|
|
} |
529
|
|
|
|
|
|
|
elsif (/^(?:#~\s+)?msgstr\[(\d+)\]\s+(.*)/) { |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
# translated string |
532
|
10
|
|
|
|
|
26
|
$buffer{msgstr_n}{$1} = $self->dequote($2); |
533
|
10
|
|
|
|
|
50
|
$last_buffer = \$buffer{msgstr_n}{$1}; |
534
|
|
|
|
|
|
|
} |
535
|
|
|
|
|
|
|
elsif (/^(?:#(?:~|~\||\|)\s+)?(".*)/) { |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
# continued string. Accounts for: |
538
|
|
|
|
|
|
|
# normal : "string" |
539
|
|
|
|
|
|
|
# obsolete : #~ "string" |
540
|
|
|
|
|
|
|
# fuzzy : #| "string" |
541
|
|
|
|
|
|
|
# fuzzy+obsolete : #~| "string" |
542
|
112
|
|
|
|
|
288
|
$$last_buffer .= $self->dequote($1); |
543
|
|
|
|
|
|
|
} |
544
|
|
|
|
|
|
|
else { |
545
|
0
|
|
|
|
|
0
|
warn "Strange line at $file line $line_number: [$_]\n"; |
546
|
|
|
|
|
|
|
} |
547
|
|
|
|
|
|
|
} |
548
|
9
|
100
|
|
|
|
52
|
if (defined($po)) { |
549
|
|
|
|
|
|
|
|
550
|
2
|
50
|
|
|
|
9
|
$po->msgctxt($buffer{msgctxt}) |
551
|
|
|
|
|
|
|
if defined $buffer{msgctxt}; |
552
|
2
|
50
|
|
|
|
14
|
$po->msgid($buffer{msgid}) |
553
|
|
|
|
|
|
|
if defined $buffer{msgid}; |
554
|
2
|
50
|
|
|
|
9
|
$po->msgid_plural($buffer{msgid_plural}) |
555
|
|
|
|
|
|
|
if defined $buffer{msgid_plural}; |
556
|
2
|
50
|
|
|
|
13
|
$po->msgstr($buffer{msgstr}) |
557
|
|
|
|
|
|
|
if defined $buffer{msgstr}; |
558
|
2
|
50
|
|
|
|
7
|
$po->msgstr_n($buffer{msgstr_n}) |
559
|
|
|
|
|
|
|
if defined $buffer{msgstr_n}; |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
# ashash |
562
|
2
|
50
|
|
|
|
8
|
if ($ashash) { |
563
|
0
|
0
|
|
|
|
0
|
if ($po->_hash_key_ok(\%entries)) { |
564
|
0
|
|
|
|
|
0
|
$entries{$po->msgid} = $po; |
565
|
|
|
|
|
|
|
} |
566
|
|
|
|
|
|
|
} |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
# asarray |
569
|
|
|
|
|
|
|
else { |
570
|
2
|
|
|
|
|
4
|
push(@entries, $po); |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
} |
573
|
9
|
|
|
|
|
161
|
close IN; |
574
|
9
|
50
|
|
|
|
94
|
return ($ashash ? \%entries : \@entries); |
575
|
|
|
|
|
|
|
} |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
sub _hash_key_ok { |
578
|
0
|
|
|
0
|
|
0
|
my ($self, $entries) = @_; |
579
|
|
|
|
|
|
|
|
580
|
0
|
|
|
|
|
0
|
my $key = $self->msgid; |
581
|
|
|
|
|
|
|
|
582
|
0
|
0
|
|
|
|
0
|
if ($entries->{$key}) { |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
# don't overwrite non-obsolete entries with obsolete ones |
585
|
0
|
0
|
0
|
|
|
0
|
return if (($self->obsolete) && (not $entries->{$key}->obsolete)); |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
# don't overwrite translated entries with untranslated ones |
588
|
0
|
0
|
0
|
|
|
0
|
return if (($self->msgstr !~ /\w/) && ($entries->{$key}->msgstr =~ /\w/)); |
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
|
591
|
0
|
|
|
|
|
0
|
return 1; |
592
|
|
|
|
|
|
|
} |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
1; |
597
|
|
|
|
|
|
|
__END__ |