3 # Test of Perl support.
6 trap 'rm -fr $tmpfiles' 1 2 3 15
8 tmpfiles
="$tmpfiles xg-pl-1.pl"
9 cat <<\EOF
> xg-pl-1.pl
10 use Locale
::Messages qw
(textdomain bindtextdomain
gettext ngettext dngettext
);
13 bindtextdomain
"prog", "./";
16 # stress test for string extraction /xe;
18 print _
"'Your command, please?', asked the waiter.";
20 printf ngettext
("a piece of cake", "%d pieces of cake", $n), $n;
22 printf _
"%s is replaced by %s.", "FF", "EUR";
25 printf dngettext prog
=> ("one file deleted", "%d files deleted"), $n, $n;
27 # Should not be found.
28 printf dngettext
("prog"), ("one file created", "%d files created"), $n, $n;
30 printf dngettext
"prog", <<PERL, <<PERL;
37 tied hash $__{ Bareword
39 tied hash $__->{"quoted string"}
40 tied hash $__->{ "weird
47 'Welcome to the Republic of Perl!' #
51 $
! ? ?
$__{"pattern match"}?
: s
# This is no delimiter.
52 {$__{substitution
}}<$__-\
>{"find me"}>;
57 # Multiple here documents invoked from the same line.
58 print
gettext <<PERL; print gettext <<PERL;
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";
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';
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
);
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
);
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.";
117 # xgettext: no-perl-format, perl-brace-format
118 gettext "The function '{func}' expects '%c' here.";
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}.";
129 # Dollars inside sub argument lists have no effect.
132 If you have
gettext()'d foo bar test1'...
135 # Dollars inside sub argument lists have no effect.
136 testFunc
= sub
($
) { }
138 If you have
gettext()'d foo bar test2'...
141 # Dollars inside sub argument lists have no effect.
142 sub testFunc
($\$
;*@
) { }
144 If you have
gettext()'d foo bar test3'...
148 gettext "Discarded!";
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 xg-pl-1.pl
-d xg-pl-1
158 test $?
= 0 ||
{ rm -fr $tmpfiles; exit 1; }
160 tmpfiles
="$tmpfiles xg-pl-1.ok"
161 cat <<\EOF
> xg-pl-1.ok
163 msgid
"'Your command, please?', asked the waiter."
168 msgid
"a piece of cake"
169 msgid_plural
"%d pieces of cake"
175 msgid
"%s is replaced by %s."
180 msgid
"one file deleted"
181 msgid_plural
"%d files deleted"
188 msgid_plural
"Plural\n"
197 msgid
"quoted string"
207 msgid
"Welcome to the Republic of Perl!"
211 msgid
"pattern match"
223 msgid
"First here document.\n"
227 msgid
"Second here document.\n"
242 #: xg-pl-1.pl:61 xg-pl-1.pl:62
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
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
260 #: xg-pl-1.pl:70 xg-pl-1.pl:75
261 msgid
"ecs\\\\\\tasy"
264 #: xg-pl-1.pl:80 xg-pl-1.pl:85
268 #: xg-pl-1.pl:82 xg-pl-1.pl:87
272 #: xg-pl-1.pl:84 xg-pl-1.pl:89
276 #: xg-pl-1.pl:90 xg-pl-1.pl:95
280 #: xg-pl-1.pl:91 xg-pl-1.pl:92 xg-pl-1.pl:96 xg-pl-1.pl:97
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"
290 msgid
"This is {only} a brace formatstring."
294 #, perl-format, perl-brace-format
295 msgid
"This is %s {mixed}."
300 msgid
"This is only %c."
304 msgid
"This is nothing at all."
308 msgid
"And this is %l also no format at all."
312 #, no-perl-format, perl-brace-format
313 msgid
"The function '{func}' expects '%c' here."
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}."
323 ${DIFF} xg-pl-1.ok xg-pl-1.po