• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8cat <<\EOF > prog.lua
9require("gettext")
10gettext.bindtextdomain("prog", ".")
11gettext.textdomain("prog")
12_ = gettext.gettext
13n = 42
14
15print(gettext.gettext("'Your command, please?', asked the waiter."))
16print(string.format(gettext.ngettext('a piece of cake', [[%d pieces of cake]], n), n))
17print(string.format(_[==[%s is replaced by %s.]==], "FF", "EUR"))
18EOF
19
20: ${XGETTEXT=xgettext}
21${XGETTEXT} -o prog.tmp --omit-header --no-location prog.lua || Exit 1
22LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1
23
24cat <<\EOF > prog.ok
25msgid "'Your command, please?', asked the waiter."
26msgstr ""
27
28#, lua-format
29msgid "a piece of cake"
30msgid_plural "%d pieces of cake"
31msgstr[0] ""
32msgstr[1] ""
33
34#, lua-format
35msgid "%s is replaced by %s."
36msgstr ""
37EOF
38
39: ${DIFF=diff}
40${DIFF} prog.ok prog.pot || Exit 1
41
42cat <<\EOF > fr.po
43msgid ""
44msgstr ""
45"Content-Type: text/plain; charset=ISO-8859-1\n"
46"Plural-Forms: nplurals=2; plural=(n > 1);\n"
47
48msgid "'Your command, please?', asked the waiter."
49msgstr "�Votre commande, s'il vous plait�, dit le gar�on."
50
51#, lua-format
52msgid "a piece of cake"
53msgid_plural "%d pieces of cake"
54msgstr[0] "un morceau de gateau"
55msgstr[1] "%d morceaux de gateau"
56
57#, lua-format
58msgid "%s is replaced by %s."
59msgstr "%s remplace %s."
60EOF
61
62: ${MSGMERGE=msgmerge}
63${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1
64LC_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
69test -d fr || mkdir fr
70test -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
77test $? -le 1 \
78  || { echo "Skipping test: lua not found"; Exit 77; }
79case `lua -v 2>&1 | sed -e 's/^[^0-9]*//'` in
80  [5-9].*) ;;
81  *) echo "Skipping test: lua version too old"; Exit 77;;
82esac
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}
91if 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
98fi
99if 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
106fi
107if 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
114fi
115
116: ${DIFF=diff}
117cat <<\EOF > prog.ok
118Votre commande, s'il vous plait�, dit le gar�on.
11942 morceaux de gateau
120FF remplace EUR.
121EOF
122cat <<\EOF > prog.oku
123«Votre commande, s'il vous plait», dit le garçon.
12442 morceaux de gateau
125FF remplace EUR.
126EOF
127
128: ${LOCALE_FR=fr_FR}
129: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
130if 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
134fi
135if 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
139fi
140
141Exit 0
142