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