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