#!/bin/sh
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/
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";
printf dngettext prog => ("one file deleted", "%d files deleted"), $n, $n;
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 Perl!' };
$! ? ?$__{"pattern match"}? : s {$__{substitution}}<$__-\>{"find me"}>;
m'$__{secret}';
print gettext <<PERL; print gettext <<PERL;
First here document.
PERL
Second here document.
PERL
printf "%s\n", gettext "abc\$def";
printf "%s\n", gettext "abc\\\$def";
printf "%s\n", gettext 'abc$defg';
printf "%s\n", gettext 'abc\$defg';
printf "%s\n", gettext 'abc\\$defg';
printf "%s\n", gettext 'abc\\\$defg';
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);
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);
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.";
gettext "The function '{func}' expects '%c' here.";
gettext "Left as an %exercise to {maintainer}.";
gettext "Left as an %exercise to {maintainer}.";
gettext "Left as an %exercise to {maintainer}.";
sub testFunc($) { }
=item TestBug1
If you have gettext()'d foo bar test1'...
=cut
testFunc = sub ($) { }
=item TestBug2
If you have gettext()'d foo bar test2'...
=cut
sub testFunc($\$;*@) { }
=item TestBug3
If you have gettext()'d foo bar test3'...
=cut
__END__
gettext "Discarded!";
EOF
tmpfiles="$tmpfiles 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 \
xg-pl-1.pl -d xg-pl-1
test $? = 0 || { rm -fr $tmpfiles; exit 1; }
tmpfiles="$tmpfiles xg-pl-1.ok"
cat <<\EOF > xg-pl-1.ok
msgid "'Your command, please?', asked the waiter."
msgstr ""
msgid "a piece of cake"
msgid_plural "%d pieces of cake"
msgstr[0] ""
msgstr[1] ""
msgid "%s is replaced by %s."
msgstr ""
msgid "one file deleted"
msgid_plural "%d files deleted"
msgstr[0] ""
msgstr[1] ""
msgid "Singular\n"
msgid_plural "Plural\n"
msgstr[0] ""
msgstr[1] ""
msgid "Bareword"
msgstr ""
msgid "quoted string"
msgstr ""
msgid ""
"weird\n"
"formatting"
msgstr ""
msgid "Welcome to the Republic of Perl!"
msgstr ""
msgid "pattern match"
msgstr ""
msgid "substitution"
msgstr ""
msgid "find me"
msgstr ""
msgid "First here document.\n"
msgstr ""
msgid "Second here document.\n"
msgstr ""
msgid "abc$def"
msgstr ""
msgid "abc\\$def"
msgstr ""
msgid "abc$defg"
msgstr ""
msgid "abc\\$defg"
msgstr ""
msgid "abc\\\\$defg"
msgstr ""
msgid "ecs\\tasy"
msgstr ""
msgid "ecs\\\\tasy"
msgstr ""
msgid "ecs\\\\\\tasy"
msgstr ""
msgid "ecs\tasy"
msgstr ""
msgid "ecs\\\tasy"
msgstr ""
msgid "ecs\\\\\tasy"
msgstr ""
msgid "marihuana"
msgstr ""
msgid "mari\\huana"
msgstr ""
msgid "mari\\\\huana"
msgstr ""
msgid "This is {only} a brace formatstring."
msgstr ""
msgid "This is %s {mixed}."
msgstr ""
msgid "This is only %c."
msgstr ""
msgid "This is nothing at all."
msgstr ""
msgid "And this is %l also no format at all."
msgstr ""
msgid "The function '{func}' expects '%c' here."
msgstr ""
msgid "Left as an %exercise to {maintainer}."
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} xg-pl-1.ok xg-pl-1.po
result=$?
rm -fr $tmpfiles
exit $result