2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
4 # Test of Perl support.
6 cat <<\EOF > xg-pl-1.pl
7 use Locale::Messages qw (textdomain bindtextdomain gettext ngettext dngettext);
10 bindtextdomain "prog", "./";
13 # stress test for string extraction /xe;
15 print _"'Your command, please?', asked the waiter.";
17 printf ngettext ("a piece of cake", "%d pieces of cake", $n), $n;
19 printf _"%s is replaced by %s.", "FF", "EUR";
22 printf dngettext prog => ("one file deleted", "%d files deleted"), $n, $n;
24 # Should not be found.
25 printf dngettext ("prog"), ("one file created", "%d files created"), $n, $n;
27 printf dngettext "prog", <<PERL, <<PERL;
34 tied hash $__{ Bareword
36 tied hash $__->{"quoted string"}
37 tied hash $__->{ "weird
44 'Welcome to the Republic of Perl!' #
48 $! ? ?$__{"pattern match"}? : s # This is no delimiter.
49 {$__{substitution}}<$__-\>{"find me"}>;
54 # Multiple here documents invoked from the same line.
55 print gettext <<PERL; print gettext <<PERL;
61 # These are not invalid interpolations, because the dollar is backslashed.
62 printf "%s\n", gettext "abc\$def";
63 printf "%s\n", gettext "abc\\\$def";
65 # These are not interpolations.
66 printf "%s\n", gettext 'abc$defg';
67 printf "%s\n", gettext 'abc\$defg';
68 printf "%s\n", gettext 'abc\\$defg';
69 printf "%s\n", gettext 'abc\\\$defg';
71 # Two consecutive backslashes count as one inside single-quote strings.
72 printf "%s\n", gettext 'ecs\tasy';
73 printf "%s\n", gettext 'ecs\\tasy';
74 printf "%s\n", gettext 'ecs\\\tasy';
75 printf "%s\n", gettext 'ecs\\\\tasy';
76 printf "%s\n", gettext 'ecs\\\\\tasy';
77 printf "%s\n", gettext q(ecs\tasy);
78 printf "%s\n", gettext q(ecs\\tasy);
79 printf "%s\n", gettext q(ecs\\\tasy);
80 printf "%s\n", gettext q(ecs\\\\tasy);
81 printf "%s\n", gettext q(ecs\\\\\tasy);
83 # Similarly, inside double-quote strings, two consecutive backslashes count
84 # as one, but the last backslash of a sequence is combined with the following
85 # character if possible.
86 printf "%s\n", gettext "ecs\tasy";
87 printf "%s\n", gettext "ecs\\tasy";
88 printf "%s\n", gettext "ecs\\\tasy";
89 printf "%s\n", gettext "ecs\\\\tasy";
90 printf "%s\n", gettext "ecs\\\\\tasy";
91 printf "%s\n", gettext qq(ecs\tasy);
92 printf "%s\n", gettext qq(ecs\\tasy);
93 printf "%s\n", gettext qq(ecs\\\tasy);
94 printf "%s\n", gettext qq(ecs\\\\tasy);
95 printf "%s\n", gettext qq(ecs\\\\\tasy);
96 printf "%s\n", gettext "mari\huana";
97 printf "%s\n", gettext "mari\\huana";
98 printf "%s\n", gettext "mari\\\huana";
99 printf "%s\n", gettext "mari\\\\huana";
100 printf "%s\n", gettext "mari\\\\\huana";
101 printf "%s\n", gettext qq(mari\huana);
102 printf "%s\n", gettext qq(mari\\huana);
103 printf "%s\n", gettext qq(mari\\\huana);
104 printf "%s\n", gettext qq(mari\\\\huana);
105 printf "%s\n", gettext qq(mari\\\\\huana);
107 # Recognition of format strings.
108 gettext "This is {only} a brace formatstring.";
109 gettext "This is %s {mixed}.";
110 gettext "This is only %c.";
111 gettext "This is nothing at all.";
112 gettext "And this is %l also no format at all.";
114 # xgettext: no-perl-format, perl-brace-format
115 gettext "The function '{func}' expects '%c' here.";
117 # This is a contradictory case: The same string three times,
118 # with different xgettext comments.
119 # xgettext: perl-brace-format, no-perl-format
120 gettext "Left as an %exercise to {maintainer}.";
121 # xgettext: no-perl-brace-format, perl-format
122 gettext "Left as an %exercise to {maintainer}.";
123 # No xgettext comment this time.
124 gettext "Left as an %exercise to {maintainer}.";
126 # Dollars inside sub argument lists have no effect.
129 If you have gettext()'d foo bar test1'...
132 # Dollars inside sub argument lists have no effect.
133 testFunc = sub ($) { }
135 If you have gettext()'d foo bar test2'...
138 # Dollars inside sub argument lists have no effect.
139 sub testFunc($\$;*@) { }
141 If you have gettext()'d foo bar test3'...
144 gettext "Before slash-slash";
145 print $foo // 'undef';
146 gettext "After slash-slash";
149 gettext "Discarded!";
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.tmp xg-pl-1.pl || exit 1
158 LC_ALL=C tr -d '\r' < xg-pl-1.tmp.po > xg-pl-1.po || exit 1
160 cat <<\EOF > xg-pl-1.ok
162 msgid "'Your command, please?', asked the waiter."
167 msgid "a piece of cake"
168 msgid_plural "%d pieces of cake"
174 msgid "%s is replaced by %s."
179 msgid "one file deleted"
180 msgid_plural "%d files deleted"
187 msgid_plural "Plural\n"
196 msgid "quoted string"
206 msgid "Welcome to the Republic of Perl!"
210 msgid "pattern match"
222 msgid "First here document.\n"
226 msgid "Second here document.\n"
241 #: xg-pl-1.pl:61 xg-pl-1.pl:62
249 #: 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
254 #: 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
259 #: xg-pl-1.pl:70 xg-pl-1.pl:75
260 msgid "ecs\\\\\\tasy"
263 #: xg-pl-1.pl:80 xg-pl-1.pl:85
267 #: xg-pl-1.pl:82 xg-pl-1.pl:87
271 #: xg-pl-1.pl:84 xg-pl-1.pl:89
275 #: xg-pl-1.pl:90 xg-pl-1.pl:95
279 #: xg-pl-1.pl:91 xg-pl-1.pl:92 xg-pl-1.pl:96 xg-pl-1.pl:97
283 #: xg-pl-1.pl:93 xg-pl-1.pl:94 xg-pl-1.pl:98 xg-pl-1.pl:99
284 msgid "mari\\\\huana"
289 msgid "This is {only} a brace formatstring."
293 #, perl-format, perl-brace-format
294 msgid "This is %s {mixed}."
299 msgid "This is only %c."
303 msgid "This is nothing at all."
307 msgid "And this is %l also no format at all."
311 #, no-perl-format, perl-brace-format
312 msgid "The function '{func}' expects '%c' here."
315 #: xg-pl-1.pl:114 xg-pl-1.pl:116 xg-pl-1.pl:118
316 #, perl-format, no-perl-brace-format
317 msgid "Left as an %exercise to {maintainer}."
321 msgid "Before slash-slash"
325 msgid "After slash-slash"
330 ${DIFF} xg-pl-1.ok xg-pl-1.po