Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / lang-sh
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src ${top_srcdir=..}/../gettext-runtime/src
3
4 # Test of gettext facilities in the sh language.
5 # Assumes an fr_FR locale is installed.
6 # Assumes the following packages are installed: bash.
7
8 # Note: This test fails on BeOS because there all locales use the UTF-8
9 # encoding, even the locale fr_FR, thus the output comes out in UTF-8.
10
11 cat <<\EOF > prog.sh
12 #! /bin/sh
13
14 n=$1
15
16 . gettext.sh
17
18 TEXTDOMAIN=prog
19 export TEXTDOMAIN
20 TEXTDOMAINDIR=.
21 export TEXTDOMAINDIR
22
23 $echo "`gettext \"'Your command, please?', asked the waiter.\"`"
24
25 $echo "`eval_ngettext \"a piece of cake\" \"\\$n pieces of cake\" $n`"
26 EOF
27
28 : ${XGETTEXT=xgettext}
29 ${XGETTEXT} -o prog.tmp --omit-header --no-location prog.sh || exit 1
30 LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || exit 1
31
32 cat <<\EOF > prog.ok
33 msgid "'Your command, please?', asked the waiter."
34 msgstr ""
35
36 #, sh-format
37 msgid "a piece of cake"
38 msgid_plural "$n pieces of cake"
39 msgstr[0] ""
40 msgstr[1] ""
41 EOF
42
43 : ${DIFF=diff}
44 ${DIFF} prog.ok prog.pot || exit 1
45
46 cat <<\EOF > fr.po
47 msgid ""
48 msgstr ""
49 "Content-Type: text/plain; charset=ISO-8859-1\n"
50 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
51
52 msgid "'Your command, please?', asked the waiter."
53 msgstr "«Votre commande, s'il vous plait», dit le garçon."
54
55 # Les gateaux allemands sont les meilleurs du monde.
56 #, sh-format
57 msgid "a piece of cake"
58 msgid_plural "$n pieces of cake"
59 msgstr[0] "un morceau de gateau"
60 msgstr[1] "$n morceaux de gateau"
61 EOF
62
63 : ${MSGMERGE=msgmerge}
64 ${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || exit 1
65 LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || exit 1
66
67 : ${DIFF=diff}
68 ${DIFF} fr.po fr.po.new || exit 1
69
70 test -d fr || mkdir fr
71 test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
72
73 : ${MSGFMT=msgfmt}
74 ${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
75
76 # Test which of the fr_FR locales are installed.
77 : ${LOCALE_FR=fr_FR}
78 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
79 if test $LOCALE_FR != none; then
80   LC_ALL=$LOCALE_FR ../testlocale
81   case $? in
82     0) ;;
83     77) LOCALE_FR=none;;
84     *) exit 1;;
85   esac
86 fi
87 if test $LOCALE_FR_UTF8 != none; then
88   LC_ALL=$LOCALE_FR_UTF8 ../testlocale
89   case $? in
90     0) ;;
91     77) LOCALE_FR_UTF8=none;;
92     *) exit 1;;
93   esac
94 fi
95 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
96   if test -f /usr/bin/localedef; then
97     echo "Skipping test: no french locale is installed"
98   else
99     echo "Skipping test: no french locale is supported"
100   fi
101   exit 77
102 fi
103
104 : ${DIFF=diff}
105 cat <<\EOF > prog.ok
106 «Votre commande, s'il vous plait», dit le garçon.
107 2 morceaux de gateau
108 EOF
109 cat <<\EOF > prog.oku
110 «Votre commande, s'il vous plait», dit le garçon.
111 2 morceaux de gateau
112 EOF
113
114 : ${LOCALE_FR=fr_FR}
115 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
116 if test $LOCALE_FR != none; then
117   prepare_locale_ fr $LOCALE_FR
118   LANGUAGE= LC_ALL=$LOCALE_FR sh ./prog.sh 2 > prog.out || exit 1
119   ${DIFF} prog.ok prog.out || exit 1
120 fi
121 if test $LOCALE_FR_UTF8 != none; then
122   prepare_locale_ fr $LOCALE_FR_UTF8
123   LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 sh ./prog.sh 2 > prog.out || exit 1
124   ${DIFF} prog.oku prog.out || exit 1
125 fi
126
127 exit 0