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