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