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