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