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