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