1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
#!/bin/sh
# Test of Perl support.
tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15
tmpfiles="$tmpfiles xg-pl-1.pl"
cat <<\EOF > xg-pl-1.pl
use Locale::Messages qw (textdomain bindtextdomain gettext ngettext dngettext);
textdomain "prog";
bindtextdomain "prog", "./";
s/foo/
# stress test for string extraction /xe;
print _"'Your command, please?', asked the waiter.";
printf ngettext ("a piece of cake", "%d pieces of cake", $n), $n;
printf _"%s is replaced by %s.", "FF", "EUR";
# Should be found.
printf dngettext prog => ("one file deleted", "%d files deleted"), $n, $n;
# Should not be found.
printf dngettext ("prog"), ("one file created", "%d files created"), $n, $n;
printf dngettext "prog", <<PERL, <<PERL;
Singular
PERL
Plural
PERL
print <<PERL
tied hash $__{ Bareword
}
tied hash $__->{"quoted string"}
tied hash $__->{ "weird
formatting"}
PERL
print $__ # Welcome
-> # to the
{ # Republic of
'Welcome to the Republic of Perl!' #
# Perl!
};
$! ? ?$__{"pattern match"}? : s # This is no delimiter.
{$__{substitution}}<$__-\>{"find me"}>;
# No interpolation!
m'$__{secret}';
# Multiple here documents invoked from the same line.
print gettext <<PERL; print gettext <<PERL;
First here document.
PERL
Second here document.
PERL
# These are not invalid interpolations, because the dollar is backslashed.
printf "%s\n", gettext "abc\$def";
printf "%s\n", gettext "abc\\\$def";
# These are not interpolations.
printf "%s\n", gettext 'abc$defg';
printf "%s\n", gettext 'abc\$defg';
printf "%s\n", gettext 'abc\\$defg';
printf "%s\n", gettext 'abc\\\$defg';
# Two consecutive backslashes count as one inside single-quote strings.
printf "%s\n", gettext 'ecs\tasy';
printf "%s\n", gettext 'ecs\\tasy';
printf "%s\n", gettext 'ecs\\\tasy';
printf "%s\n", gettext 'ecs\\\\tasy';
printf "%s\n", gettext 'ecs\\\\\tasy';
printf "%s\n", gettext q(ecs\tasy);
printf "%s\n", gettext q(ecs\\tasy);
printf "%s\n", gettext q(ecs\\\tasy);
printf "%s\n", gettext q(ecs\\\\tasy);
printf "%s\n", gettext q(ecs\\\\\tasy);
# Similarly, inside double-quote strings, two consecutive backslashes count
# as one, but the last backslash of a sequence is combined with the following
# character if possible.
printf "%s\n", gettext "ecs\tasy";
printf "%s\n", gettext "ecs\\tasy";
printf "%s\n", gettext "ecs\\\tasy";
printf "%s\n", gettext "ecs\\\\tasy";
printf "%s\n", gettext "ecs\\\\\tasy";
printf "%s\n", gettext qq(ecs\tasy);
printf "%s\n", gettext qq(ecs\\tasy);
printf "%s\n", gettext qq(ecs\\\tasy);
printf "%s\n", gettext qq(ecs\\\\tasy);
printf "%s\n", gettext qq(ecs\\\\\tasy);
printf "%s\n", gettext "mari\huana";
printf "%s\n", gettext "mari\\huana";
printf "%s\n", gettext "mari\\\huana";
printf "%s\n", gettext "mari\\\\huana";
printf "%s\n", gettext "mari\\\\\huana";
printf "%s\n", gettext qq(mari\huana);
printf "%s\n", gettext qq(mari\\huana);
printf "%s\n", gettext qq(mari\\\huana);
printf "%s\n", gettext qq(mari\\\\huana);
printf "%s\n", gettext qq(mari\\\\\huana);
# Recognition of format strings.
gettext "This is {only} a brace formatstring.";
gettext "This is %s {mixed}.";
gettext "This is only %c.";
gettext "This is nothing at all.";
gettext "And this is %l also no format at all.";
# xgettext: no-perl-format, perl-brace-format
gettext "The function '{func}' expects '%c' here.";
# This is a contradictory case: The same string three times,
# with different xgettext comments.
# xgettext: perl-brace-format, no-perl-format
gettext "Left as an %exercise to {maintainer}.";
# xgettext: no-perl-brace-format, perl-format
gettext "Left as an %exercise to {maintainer}.";
# No xgettext comment this time.
gettext "Left as an %exercise to {maintainer}.";
# Dollars inside sub argument lists have no effect.
sub testFunc($) { }
=item TestBug1
If you have gettext()'d foo bar test1'...
=cut
# Dollars inside sub argument lists have no effect.
testFunc = sub ($) { }
=item TestBug2
If you have gettext()'d foo bar test2'...
=cut
# Dollars inside sub argument lists have no effect.
sub testFunc($\$;*@) { }
=item TestBug3
If you have gettext()'d foo bar test3'...
=cut
gettext "Before slash-slash";
print $foo // 'undef';
gettext "After slash-slash";
__END__
gettext "Discarded!";
EOF
tmpfiles="$tmpfiles xg-pl-1.tmp.po xg-pl-1.po"
: ${XGETTEXT=xgettext}
${XGETTEXT} --omit-header -n \
-k_ --flag=_:1:pass-perl-format --flag=_:1:pass-perl-brace-format \
-k%__ --flag=%__:1:pass-perl-format --flag=%__:1:pass-perl-brace-format \
-k\$__ --flag=\$__:1:pass-perl-format --flag=\$__:1:pass-perl-brace-format \
-d xg-pl-1.tmp xg-pl-1.pl
test $? = 0 || { rm -fr $tmpfiles; exit 1; }
LC_ALL=C tr -d '\r' < xg-pl-1.tmp.po > xg-pl-1.po
test $? = 0 || { rm -fr $tmpfiles; exit 1; }
tmpfiles="$tmpfiles xg-pl-1.ok"
cat <<\EOF > xg-pl-1.ok
#: xg-pl-1.pl:9
msgid "'Your command, please?', asked the waiter."
msgstr ""
#: xg-pl-1.pl:11
#, perl-format
msgid "a piece of cake"
msgid_plural "%d pieces of cake"
msgstr[0] ""
msgstr[1] ""
#: xg-pl-1.pl:13
#, perl-format
msgid "%s is replaced by %s."
msgstr ""
#: xg-pl-1.pl:16
#, perl-format
msgid "one file deleted"
msgid_plural "%d files deleted"
msgstr[0] ""
msgstr[1] ""
#: xg-pl-1.pl:22
#, perl-format
msgid "Singular\n"
msgid_plural "Plural\n"
msgstr[0] ""
msgstr[1] ""
#: xg-pl-1.pl:28
msgid "Bareword"
msgstr ""
#: xg-pl-1.pl:30
msgid "quoted string"
msgstr ""
#: xg-pl-1.pl:31
msgid ""
"weird\n"
"formatting"
msgstr ""
#: xg-pl-1.pl:38
msgid "Welcome to the Republic of Perl!"
msgstr ""
#: xg-pl-1.pl:42
msgid "pattern match"
msgstr ""
#: xg-pl-1.pl:43
msgid "substitution"
msgstr ""
#: xg-pl-1.pl:43
msgid "find me"
msgstr ""
#: xg-pl-1.pl:50
msgid "First here document.\n"
msgstr ""
#: xg-pl-1.pl:52
msgid "Second here document.\n"
msgstr ""
#: xg-pl-1.pl:56
msgid "abc$def"
msgstr ""
#: xg-pl-1.pl:57
msgid "abc\\$def"
msgstr ""
#: xg-pl-1.pl:60
msgid "abc$defg"
msgstr ""
#: xg-pl-1.pl:61 xg-pl-1.pl:62
msgid "abc\\$defg"
msgstr ""
#: xg-pl-1.pl:63
msgid "abc\\\\$defg"
msgstr ""
#: xg-pl-1.pl:66 xg-pl-1.pl:67 xg-pl-1.pl:71 xg-pl-1.pl:72 xg-pl-1.pl:81
#: xg-pl-1.pl:86
msgid "ecs\\tasy"
msgstr ""
#: xg-pl-1.pl:68 xg-pl-1.pl:69 xg-pl-1.pl:73 xg-pl-1.pl:74 xg-pl-1.pl:83
#: xg-pl-1.pl:88
msgid "ecs\\\\tasy"
msgstr ""
#: xg-pl-1.pl:70 xg-pl-1.pl:75
msgid "ecs\\\\\\tasy"
msgstr ""
#: xg-pl-1.pl:80 xg-pl-1.pl:85
msgid "ecs\tasy"
msgstr ""
#: xg-pl-1.pl:82 xg-pl-1.pl:87
msgid "ecs\\\tasy"
msgstr ""
#: xg-pl-1.pl:84 xg-pl-1.pl:89
msgid "ecs\\\\\tasy"
msgstr ""
#: xg-pl-1.pl:90 xg-pl-1.pl:95
msgid "marihuana"
msgstr ""
#: xg-pl-1.pl:91 xg-pl-1.pl:92 xg-pl-1.pl:96 xg-pl-1.pl:97
msgid "mari\\huana"
msgstr ""
#: xg-pl-1.pl:93 xg-pl-1.pl:94 xg-pl-1.pl:98 xg-pl-1.pl:99
msgid "mari\\\\huana"
msgstr ""
#: xg-pl-1.pl:102
#, perl-brace-format
msgid "This is {only} a brace formatstring."
msgstr ""
#: xg-pl-1.pl:103
#, perl-format, perl-brace-format
msgid "This is %s {mixed}."
msgstr ""
#: xg-pl-1.pl:104
#, perl-format
msgid "This is only %c."
msgstr ""
#: xg-pl-1.pl:105
msgid "This is nothing at all."
msgstr ""
#: xg-pl-1.pl:106
msgid "And this is %l also no format at all."
msgstr ""
#: xg-pl-1.pl:109
#, no-perl-format, perl-brace-format
msgid "The function '{func}' expects '%c' here."
msgstr ""
#: xg-pl-1.pl:114 xg-pl-1.pl:116 xg-pl-1.pl:118
#, perl-format, no-perl-brace-format
msgid "Left as an %exercise to {maintainer}."
msgstr ""
#: xg-pl-1.pl:138
msgid "Before slash-slash"
msgstr ""
#: xg-pl-1.pl:140
msgid "After slash-slash"
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} xg-pl-1.ok xg-pl-1.po
result=$?
rm -fr $tmpfiles
exit $result
|