Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / lang-lua
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test of gettext facilities in the Lua language.
5 # Assumes an fr_FR locale is installed.
6 # Assumes the following packages are installed: lua, lua-gettext.
7
8 cat <<\EOF > prog.lua
9 require("gettext")
10 gettext.bindtextdomain("prog", ".")
11 gettext.textdomain("prog")
12 _ = gettext.gettext
13 n = 42
14
15 print(gettext.gettext("'Your command, please?', asked the waiter."))
16 print(string.format(gettext.ngettext('a piece of cake', [[%d pieces of cake]], n), n))
17 print(string.format(_[==[%s is replaced by %s.]==], "FF", "EUR"))
18 EOF
19
20 : ${XGETTEXT=xgettext}
21 ${XGETTEXT} -o prog.tmp --omit-header --no-location prog.lua || exit 1
22 LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || exit 1
23
24 cat <<\EOF > prog.ok
25 msgid "'Your command, please?', asked the waiter."
26 msgstr ""
27
28 #, lua-format
29 msgid "a piece of cake"
30 msgid_plural "%d pieces of cake"
31 msgstr[0] ""
32 msgstr[1] ""
33
34 #, lua-format
35 msgid "%s is replaced by %s."
36 msgstr ""
37 EOF
38
39 : ${DIFF=diff}
40 ${DIFF} prog.ok prog.pot || exit 1
41
42 cat <<\EOF > fr.po
43 msgid ""
44 msgstr ""
45 "Content-Type: text/plain; charset=ISO-8859-1\n"
46 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
47
48 msgid "'Your command, please?', asked the waiter."
49 msgstr "«Votre commande, s'il vous plait», dit le garçon."
50
51 #, lua-format
52 msgid "a piece of cake"
53 msgid_plural "%d pieces of cake"
54 msgstr[0] "un morceau de gateau"
55 msgstr[1] "%d morceaux de gateau"
56
57 #, lua-format
58 msgid "%s is replaced by %s."
59 msgstr "%s remplace %s."
60 EOF
61
62 : ${MSGMERGE=msgmerge}
63 ${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || exit 1
64 LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || exit 1
65
66 : ${DIFF=diff}
67 ${DIFF} fr.po fr.po.new || exit 1
68
69 test -d fr || mkdir fr
70 test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
71
72 : ${MSGFMT=msgfmt}
73 ${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
74
75 # Test for presence of lua version 5.0 or newer with gettext support.
76 (lua -v) >/dev/null 2>/dev/null
77 test $? -le 1 \
78   || { echo "Skipping test: lua not found"; exit 77; }
79 case `lua -v 2>&1 | sed -e 's/^[^0-9]*//'` in
80   [5-9].*) ;;
81   *) echo "Skipping test: lua version too old"; exit 77;;
82 esac
83 { lua -v -l gettext > /dev/null 2>/dev/null; } \
84   || { echo "Skipping test: lua gettext module not found"
85        exit 77
86      }
87
88 # Test which of the fr_FR locales are installed.
89 : ${LOCALE_FR=fr_FR}
90 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
91 if test $LOCALE_FR != none; then
92   LC_ALL=$LOCALE_FR ../testlocale
93   case $? in
94     0) ;;
95     77) LOCALE_FR=none;;
96     *) exit 1;;
97   esac
98 fi
99 if test $LOCALE_FR_UTF8 != none; then
100   LC_ALL=$LOCALE_FR_UTF8 ../testlocale
101   case $? in
102     0) ;;
103     77) LOCALE_FR_UTF8=none;;
104     *) exit 1;;
105   esac
106 fi
107 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
108   if test -f /usr/bin/localedef; then
109     echo "Skipping test: no french locale is installed"
110   else
111     echo "Skipping test: no french locale is supported"
112   fi
113   exit 77
114 fi
115
116 : ${DIFF=diff}
117 cat <<\EOF > prog.ok
118 «Votre commande, s'il vous plait», dit le garçon.
119 42 morceaux de gateau
120 FF remplace EUR.
121 EOF
122 cat <<\EOF > prog.oku
123 «Votre commande, s'il vous plait», dit le garçon.
124 42 morceaux de gateau
125 FF remplace EUR.
126 EOF
127
128 : ${LOCALE_FR=fr_FR}
129 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
130 if test $LOCALE_FR != none; then
131   prepare_locale_ fr $LOCALE_FR
132   LANGUAGE= LC_ALL=$LOCALE_FR lua -l gettext prog.lua > prog.out || exit 1
133   ${DIFF} prog.ok prog.out || exit 1
134 fi
135 if test $LOCALE_FR_UTF8 != none; then
136   prepare_locale_ fr $LOCALE_FR_UTF8
137   LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 lua -l gettext prog.lua > prog.out || exit 1
138   ${DIFF} prog.oku prog.out || exit 1
139 fi
140
141 exit 0