1#! /bin/sh
2
3# Test of gettext facilities in the C language.
4# Assumes an fr_FR locale is installed.
5# Assumes the following packages are installed: gcc.
6
7tmpfiles=""
8trap 'rm -fr $tmpfiles' 1 2 3 15
9
10tmpfiles="$tmpfiles prog.c"
11cat <<\EOF > prog.c
12#include "config.h"
13#include <libintl.h>
14#include <locale.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include "xsetenv.h"
18#define _(string) gettext (string)
19
20int main (int argc, char *argv[])
21{
22  int n = atoi (argv[2]);
23
24  xsetenv ("LC_ALL", argv[1], 1);
25  if (setlocale (LC_ALL, "") == NULL)
26    /* Couldn't set locale.  */
27    exit (77);
28
29  textdomain ("prog");
30  bindtextdomain ("prog", ".");
31
32  printf (_("'Your command, please?', asked the waiter."));
33  printf ("\n");
34
35  printf (ngettext ("a piece of cake", "%d pieces of cake", n), n);
36  printf ("\n");
37
38  printf (_("%s is replaced by %s."), "FF", "EUR");
39  printf ("\n");
40
41  exit (0);
42}
43EOF
44
45# Variable needed by LTLIBINTL.
46top_builddir=..
47
48tmpfiles="$tmpfiles prog.${OBJEXT} prog${EXEEXT}"
49# Put the -I flags before ${CFLAGS} ${CPPFLAGS}, to make sure that libintl.h
50# is found in the build directory, regardless of -I options present in
51# ${CFLAGS} or ${CPPFLAGS}.
52${LIBTOOL} --quiet --mode=link ${CC} -I.. -I$top_srcdir/gnulib-lib ../gnulib-lib/libgettextlib.la -I../intl ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -o prog prog.c ${LTLIBINTL} \
53  || exit 1
54
55tmpfiles="$tmpfiles prog.pot"
56: ${XGETTEXT=xgettext}
57${XGETTEXT} -o prog.pot --omit-header --no-location -k_ prog.c
58
59tmpfiles="$tmpfiles prog.ok"
60cat <<EOF > prog.ok
61#, c-format
62msgid "'Your command, please?', asked the waiter."
63msgstr ""
64
65#, c-format
66msgid "a piece of cake"
67msgid_plural "%d pieces of cake"
68msgstr[0] ""
69msgstr[1] ""
70
71#, c-format
72msgid "%s is replaced by %s."
73msgstr ""
74EOF
75
76: ${DIFF=diff}
77${DIFF} prog.ok prog.pot || exit 1
78
79tmpfiles="$tmpfiles fr.po"
80cat <<\EOF > fr.po
81msgid ""
82msgstr ""
83"Content-Type: text/plain; charset=ISO-8859-1\n"
84"Plural-Forms: nplurals=2; plural=(n > 1);\n"
85
86#, c-format
87msgid "'Your command, please?', asked the waiter."
88msgstr "�Votre commande, s'il vous plait�, dit le garon."
89
90# Les gateaux allemands sont les meilleurs du monde.
91#, c-format
92msgid "a piece of cake"
93msgid_plural "%d pieces of cake"
94msgstr[0] "un morceau de gateau"
95msgstr[1] "%d morceaux de gateau"
96
97# Reverse the arguments.
98#, c-format
99msgid "%s is replaced by %s."
100msgstr "%2$s remplace %1$s."
101EOF
102
103tmpfiles="$tmpfiles fr.po.new"
104: ${MSGMERGE=msgmerge}
105${MSGMERGE} -q -o fr.po.new fr.po prog.pot
106
107: ${DIFF=diff}
108${DIFF} fr.po fr.po.new || exit 1
109
110tmpfiles="$tmpfiles fr"
111test -d fr || mkdir fr
112test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
113
114: ${MSGFMT=msgfmt}
115${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
116
117tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
118: ${DIFF=diff}
119cat <<\EOF > prog.ok
120�Votre commande, s'il vous plait�, dit le gar�on.
1212 morceaux de gateau
122EUR remplace FF.
123EOF
124cat <<\EOF > prog.oku
125��Votre commande, s'il vous plait��, dit le gar��on.
1262 morceaux de gateau
127EUR remplace FF.
128EOF
129
130: ${LOCALE_FR=fr_FR}
131: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
132if test $LOCALE_FR != none; then
133  LANGUAGE= ./prog $LOCALE_FR 2 > prog.out
134  case $? in
135    0) ${DIFF} prog.ok prog.out || exit 1;;
136    77) LOCALE_FR=none;;
137    *) exit 1;;
138  esac
139fi
140if test $LOCALE_FR_UTF8 != none; then
141  LANGUAGE= ./prog $LOCALE_FR_UTF8 2 > prog.out
142  case $? in
143    0) ${DIFF} prog.oku prog.out || exit 1;;
144    77) LOCALE_FR_UTF8=none;;
145    *) exit 1;;
146  esac
147fi
148if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
149  if test -f /usr/bin/localedef; then
150    echo "Skipping test: no french locale is installed"
151  else
152    echo "Skipping test: no french locale is supported"
153  fi
154  rm -fr $tmpfiles; exit 77
155fi
156
157rm -fr $tmpfiles
158
159exit 0
160