Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / lang-csharp
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test of gettext facilities in the C# language.
5 # Assumes an fr_FR locale is installed.
6 # Assumes the following packages are installed: pnet, pnetlib.
7
8 # Note: This test fails with mono-0.28 because the CultureInfo.Parent pointers
9 # are wrong for locales containing a language and a territory. This is fixed
10 # in mono-0.29.
11
12 # Test whether we can build and test C# programs.
13 test "${CSHARP_CHOICE}" != no || {
14   echo "Skipping test: configured with --disable-csharp"
15   exit 77
16 }
17 test "${BUILDCSHARP}" = yes || {
18   echo "Skipping test: C# compiler not found"
19   exit 77
20 }
21 test "${TESTCSHARP}" = yes || {
22   echo "Skipping test: C# engine not found"
23   exit 77
24 }
25
26 cat <<\EOF > program.cs
27 using System;
28 using GNU.Gettext;
29 class Program {
30   static void Main (String[] args) {
31     #if __MonoCS__
32     // Some systems don't set CurrentCulture and CurrentUICulture as specified
33     // by LC_ALL. So set it by hand.
34     System.Threading.Thread.CurrentThread.CurrentCulture =
35     System.Threading.Thread.CurrentThread.CurrentUICulture =
36       new System.Globalization.CultureInfo("fr-FR");
37     #endif
38     int n = Int32.Parse(args[0]);
39     GettextResourceManager catalog = new GettextResourceManager("prog");
40     Console.WriteLine(catalog.GetString("'Your command, please?', asked the waiter."));
41     Console.WriteLine(String.Format(catalog.GetPluralString("a piece of cake","{0} pieces of cake",n), n));
42     Console.WriteLine(String.Format(catalog.GetString("{0} is replaced by {1}."), "FF", "EUR"));
43     Console.WriteLine(String.Format(catalog.GetParticularPluralString("++","a piece of cake","{0} pieces of cake",n), n));
44     Console.WriteLine(String.Format(catalog.GetParticularString("++","{0} is replaced by {1}."), "FF", "EUR"));
45   }
46 }
47 EOF
48
49 : ${CSHARPCOMP="/bin/sh ../../csharpcomp.sh"}
50 ${CSHARPCOMP} -o program.exe -L ../../../gettext-runtime/intl-csharp -l GNU.Gettext program.cs || exit 1
51
52 : ${XGETTEXT=xgettext}
53 ${XGETTEXT} -o prog.tmp --omit-header --no-location program.cs || exit 1
54 LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || exit 1
55
56 cat <<EOF > prog.ok
57 msgid "'Your command, please?', asked the waiter."
58 msgstr ""
59
60 #, csharp-format
61 msgid "a piece of cake"
62 msgid_plural "{0} pieces of cake"
63 msgstr[0] ""
64 msgstr[1] ""
65
66 #, csharp-format
67 msgid "{0} is replaced by {1}."
68 msgstr ""
69
70 #, csharp-format
71 msgctxt "++"
72 msgid "a piece of cake"
73 msgid_plural "{0} pieces of cake"
74 msgstr[0] ""
75 msgstr[1] ""
76
77 #, csharp-format
78 msgctxt "++"
79 msgid "{0} is replaced by {1}."
80 msgstr ""
81 EOF
82
83 : ${DIFF=diff}
84 ${DIFF} prog.ok prog.pot || exit 1
85
86 cat <<\EOF > fr.po
87 msgid ""
88 msgstr ""
89 "Content-Type: text/plain; charset=ISO-8859-1\n"
90 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
91
92 msgid "'Your command, please?', asked the waiter."
93 msgstr "«Votre commande, s'il vous plait», dit le garçon."
94
95 # Les gateaux allemands sont les meilleurs du monde.
96 #, csharp-format
97 msgid "a piece of cake"
98 msgid_plural "{0} pieces of cake"
99 msgstr[0] "un morceau de gateau"
100 msgstr[1] "{0} morceaux de gateau"
101
102 # Reverse the arguments.
103 #, csharp-format
104 msgid "{0} is replaced by {1}."
105 msgstr "{1} remplace {0}."
106
107 # Euphemistic formulation.
108 #, csharp-format
109 msgctxt "++"
110 msgid "a piece of cake"
111 msgid_plural "{0} pieces of cake"
112 msgstr[0] "un morceau de gateau succulent"
113 msgstr[1] "{0} morceaux de gateau succulent"
114
115 # Euphemistic formulation.
116 #, csharp-format
117 msgctxt "++"
118 msgid "{0} is replaced by {1}."
119 msgstr "Le nouveau {1} remplace le vieux {0}."
120 EOF
121
122 : ${MSGMERGE=msgmerge}
123 ${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || exit 1
124 LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || exit 1
125
126 : ${DIFF=diff}
127 ${DIFF} fr.po fr.po.new || exit 1
128
129 : ${MSGFMT=msgfmt}
130 GETTEXTCSHARPLIBDIR=../../../gettext-runtime/intl-csharp \
131 ${MSGFMT} --csharp -d . -r prog -l fr fr.po || exit 1
132
133 # Test which of the fr_FR locales are installed.
134 : ${LOCALE_FR=fr_FR}
135 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
136 if test $LOCALE_FR != none; then
137   LC_ALL=$LOCALE_FR ../testlocale
138   case $? in
139     0) ;;
140     77) LOCALE_FR=none;;
141     *) exit 1;;
142   esac
143 fi
144 if test $LOCALE_FR_UTF8 != none; then
145   LC_ALL=$LOCALE_FR_UTF8 ../testlocale
146   case $? in
147     0) ;;
148     77) LOCALE_FR_UTF8=none;;
149     *) exit 1;;
150   esac
151 fi
152 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
153   if test -f /usr/bin/localedef; then
154     echo "Skipping test: no french locale is installed"
155   else
156     echo "Skipping test: no french locale is supported"
157   fi
158   exit 77
159 fi
160
161 : ${DIFF=diff}
162 cat <<\EOF > prog.ok
163 «Votre commande, s'il vous plait», dit le garçon.
164 2 morceaux de gateau
165 EUR remplace FF.
166 2 morceaux de gateau succulent
167 Le nouveau EUR remplace le vieux FF.
168 EOF
169 cat <<\EOF > prog.oku
170 «Votre commande, s'il vous plait», dit le garçon.
171 2 morceaux de gateau
172 EUR remplace FF.
173 2 morceaux de gateau succulent
174 Le nouveau EUR remplace le vieux FF.
175 EOF
176
177 : ${LOCALE_FR=fr_FR}
178 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
179 : ${CSHARPEXEC="/bin/sh ../../csharpexec.sh"}
180 if test $LOCALE_FR != none; then
181   prepare_locale_ fr $LOCALE_FR
182   LANGUAGE= LC_ALL=$LOCALE_FR ${CSHARPEXEC} -L ../../../gettext-runtime/intl-csharp program.exe 2 > prog.out || exit 1
183   ${DIFF} prog.ok prog.out || exit 1
184 fi
185 if test $LOCALE_FR_UTF8 != none; then
186   prepare_locale_ fr $LOCALE_FR_UTF8
187   LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 ${CSHARPEXEC} -L ../../../gettext-runtime/intl-csharp program.exe 2 > prog.out || exit 1
188   ${DIFF} prog.oku prog.out || exit 1
189 fi
190
191 exit 0