lang-perl-1 revision 1.1 1 #! /bin/sh
2
3 # Test of gettext facilities in the Perl language,
4 # using printf format strings.
5 # Assumes an fr_FR locale is installed.
6 # Assumes the following packages are installed: perl.
7
8 tmpfiles=""
9 trap 'rm -fr $tmpfiles' 1 2 3 15
10
11 tmpfiles="$tmpfiles program.pl"
12 cat <<\EOF > program.pl
13 use strict;
14
15 use Locale::Messages qw (textdomain bindtextdomain gettext ngettext);
16 textdomain "prog";
17 bindtextdomain "prog", "./";
18 my $n = 2;
19 print gettext "'Your command, please?', asked the waiter.";
20 print "\n";
21 printf ngettext ("a piece of cake", "%d pieces of cake", $n), $n;
22 print "\n";
23 printf gettext "%s is replaced by %s.", "FF", "EUR";
24 print "\n";
25 EOF
26
27 tmpfiles="$tmpfiles prog.pot"
28 : ${XGETTEXT=xgettext}
29 ${XGETTEXT} \
30 -k__ --flag=__:1:pass-perl-format --flag=__:1:pass-perl-brace-format \
31 -o prog.pot --omit-header --no-location program.pl
32
33 tmpfiles="$tmpfiles prog.ok"
34 cat <<EOF > prog.ok
35 msgid "'Your command, please?', asked the waiter."
36 msgstr ""
37
38 #, perl-format
39 msgid "a piece of cake"
40 msgid_plural "%d pieces of cake"
41 msgstr[0] ""
42 msgstr[1] ""
43
44 #, perl-format
45 msgid "%s is replaced by %s."
46 msgstr ""
47 EOF
48
49 : ${DIFF=diff}
50 ${DIFF} prog.ok prog.pot || exit 1
51
52 tmpfiles="$tmpfiles fr.po"
53 cat <<\EOF > fr.po
54 msgid ""
55 msgstr ""
56 "Content-Type: text/plain; charset=ISO-8859-1\n"
57 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
58
59 msgid "'Your command, please?', asked the waiter."
60 msgstr "Votre commande, s'il vous plait, dit le garon."
61
62 # Les gateaux allemands sont les meilleurs du monde.
63 #, perl-format
64 msgid "a piece of cake"
65 msgid_plural "%d pieces of cake"
66 msgstr[0] "un morceau de gateau"
67 msgstr[1] "%d morceaux de gateau"
68
69 # Reverse the arguments.
70 #, perl-format
71 msgid "%s is replaced by %s."
72 msgstr "%2$s remplace %1$s."
73 EOF
74
75 tmpfiles="$tmpfiles fr.po.new"
76 : ${MSGMERGE=msgmerge}
77 ${MSGMERGE} -q -o fr.po.new fr.po prog.pot
78
79 : ${DIFF=diff}
80 ${DIFF} fr.po fr.po.new || exit 1
81
82 tmpfiles="$tmpfiles fr"
83 test -d fr || mkdir fr
84 test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
85
86 : ${MSGFMT=msgfmt}
87 ${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
88
89 tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
90 : ${DIFF=diff}
91 cat <<\EOF > prog.ok
92 Votre commande, s'il vous plait, dit le garon.
93 2 morceaux de gateau
94 EUR remplace FF.
95 EOF
96 cat <<\EOF > prog.oku
97 Votre commande, s'il vous plait, dit le garon.
98 2 morceaux de gateau
99 EUR remplace FF.
100 EOF
101
102 # Test for perl with Locale::Messages package.
103 perl -e 'use Locale::Messages;' 2>/dev/null \
104 || { echo "Skipping test: perl package Locale::Messages is not installed"
105 rm -fr $tmpfiles; exit 77
106 }
107
108 : ${LOCALE_FR=fr_FR}
109 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
110 if test $LOCALE_FR != none; then
111 LANGUAGE= LANG=$LOCALE_FR LC_MESSAGES= LC_CTYPE= LC_ALL= perl program.pl > prog.out || exit 1
112 ${DIFF} prog.ok prog.out || exit 1
113 fi
114 if test $LOCALE_FR_UTF8 != none; then
115 LANGUAGE= LANG=$LOCALE_FR_UTF8 LC_MESSAGES= LC_CTYPE= LC_ALL= perl program.pl > prog.out || exit 1
116 ${DIFF} prog.oku prog.out || exit 1
117 fi
118 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
119 if test -f /usr/bin/localedef; then
120 echo "Skipping test: no french locale is installed"
121 else
122 echo "Skipping test: no french locale is supported"
123 fi
124 rm -fr $tmpfiles; exit 77
125 fi
126
127 rm -fr $tmpfiles
128
129 exit 0
130