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: mono, mcs. 7 8# Note: This test fails when a GNU gettext version < 0.17 is installed with 9# the same --prefix as mcs. mcs apparently searches ${prefix}/lib before 10# searching the directory specified on the command line: 11# $ mcs -out:program.exe -lib:../../gettext-runtime/intl-csharp -reference:GNU.Gettext program.cs 12# program.cs(17,45): error CS0117: `GNU.Gettext.GettextResourceManager' does not contain a definition for `GetParticularPluralString' 13# /usr/local/lib/GNU.Gettext.dll (Location of the symbol related to previous error) 14# program.cs(18,45): error CS0117: `GNU.Gettext.GettextResourceManager' does not contain a definition for `GetParticularString' 15# /usr/local/lib/GNU.Gettext.dll (Location of the symbol related to previous error) 16# Compilation failed: 2 error(s), 0 warnings 17# The workaround is to install GNU gettext with the same --prefix, despite 18# the test failure, and run "make check" afterwards. 19 20# Test whether we can build and test C# programs. 21test "${CSHARP_CHOICE}" != no || { 22 echo "Skipping test: configured with --disable-csharp" 23 Exit 77 24} 25test "${BUILDCSHARP}" = yes || { 26 echo "Skipping test: C# compiler not found" 27 Exit 77 28} 29test "${TESTCSHARP}" = yes || { 30 echo "Skipping test: C# engine not found" 31 Exit 77 32} 33 34cat <<\EOF > program.cs 35using System; 36using GNU.Gettext; 37class Program { 38 static void Main (String[] args) { 39 #if __MonoCS__ 40 // Some systems don't set CurrentCulture and CurrentUICulture as specified 41 // by LC_ALL. So set it by hand. 42 System.Threading.Thread.CurrentThread.CurrentCulture = 43 System.Threading.Thread.CurrentThread.CurrentUICulture = 44 new System.Globalization.CultureInfo("fr-FR"); 45 #endif 46 int n = Int32.Parse(args[0]); 47 GettextResourceManager catalog = new GettextResourceManager("prog"); 48 Console.WriteLine(catalog.GetString("'Your command, please?', asked the waiter.")); 49 Console.WriteLine(String.Format(catalog.GetPluralString("a piece of cake","{0} pieces of cake",n), n)); 50 Console.WriteLine(String.Format(catalog.GetString("{0} is replaced by {1}."), "FF", "EUR")); 51 Console.WriteLine(String.Format(catalog.GetParticularPluralString("++","a piece of cake","{0} pieces of cake",n), n)); 52 Console.WriteLine(String.Format(catalog.GetParticularString("++","{0} is replaced by {1}."), "FF", "EUR")); 53 } 54} 55EOF 56 57: ${CSHARPCOMP="/bin/sh ../../csharpcomp.sh"} 58${CSHARPCOMP} -o program.exe -L ../../../gettext-runtime/intl-csharp -l GNU.Gettext program.cs || Exit 1 59 60: ${XGETTEXT=xgettext} 61${XGETTEXT} -o prog.tmp --omit-header --no-location program.cs || Exit 1 62LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1 63 64cat <<EOF > prog.ok 65msgid "'Your command, please?', asked the waiter." 66msgstr "" 67 68#, csharp-format 69msgid "a piece of cake" 70msgid_plural "{0} pieces of cake" 71msgstr[0] "" 72msgstr[1] "" 73 74#, csharp-format 75msgid "{0} is replaced by {1}." 76msgstr "" 77 78#, csharp-format 79msgctxt "++" 80msgid "a piece of cake" 81msgid_plural "{0} pieces of cake" 82msgstr[0] "" 83msgstr[1] "" 84 85#, csharp-format 86msgctxt "++" 87msgid "{0} is replaced by {1}." 88msgstr "" 89EOF 90 91: ${DIFF=diff} 92${DIFF} prog.ok prog.pot || Exit 1 93 94cat <<\EOF > fr.po 95msgid "" 96msgstr "" 97"Content-Type: text/plain; charset=ISO-8859-1\n" 98"Plural-Forms: nplurals=2; plural=(n > 1);\n" 99 100msgid "'Your command, please?', asked the waiter." 101msgstr "�Votre commande, s'il vous plait�, dit le gar�on." 102 103# Les gateaux allemands sont les meilleurs du monde. 104#, csharp-format 105msgid "a piece of cake" 106msgid_plural "{0} pieces of cake" 107msgstr[0] "un morceau de gateau" 108msgstr[1] "{0} morceaux de gateau" 109 110# Reverse the arguments. 111#, csharp-format 112msgid "{0} is replaced by {1}." 113msgstr "{1} remplace {0}." 114 115# Euphemistic formulation. 116#, csharp-format 117msgctxt "++" 118msgid "a piece of cake" 119msgid_plural "{0} pieces of cake" 120msgstr[0] "un morceau de gateau succulent" 121msgstr[1] "{0} morceaux de gateau succulent" 122 123# Euphemistic formulation. 124#, csharp-format 125msgctxt "++" 126msgid "{0} is replaced by {1}." 127msgstr "Le nouveau {1} remplace le vieux {0}." 128EOF 129 130: ${MSGMERGE=msgmerge} 131${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1 132LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || Exit 1 133 134: ${DIFF=diff} 135${DIFF} fr.po fr.po.new || Exit 1 136 137: ${MSGFMT=msgfmt} 138GETTEXTCSHARPLIBDIR=../../../gettext-runtime/intl-csharp \ 139${MSGFMT} --csharp -d . -r prog -l fr fr.po || Exit 1 140 141# Test which of the fr_FR locales are installed. 142: ${LOCALE_FR=fr_FR} 143: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 144if test $LOCALE_FR != none; then 145 LC_ALL=$LOCALE_FR ../testlocale 146 case $? in 147 0) ;; 148 77) LOCALE_FR=none;; 149 *) Exit 1;; 150 esac 151fi 152if test $LOCALE_FR_UTF8 != none; then 153 LC_ALL=$LOCALE_FR_UTF8 ../testlocale 154 case $? in 155 0) ;; 156 77) LOCALE_FR_UTF8=none;; 157 *) Exit 1;; 158 esac 159fi 160if 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 167fi 168 169: ${DIFF=diff} 170cat <<\EOF > prog.ok 171�Votre commande, s'il vous plait�, dit le gar�on. 1722 morceaux de gateau 173EUR remplace FF. 1742 morceaux de gateau succulent 175Le nouveau EUR remplace le vieux FF. 176EOF 177cat <<\EOF > prog.oku 178«Votre commande, s'il vous plait», dit le garçon. 1792 morceaux de gateau 180EUR remplace FF. 1812 morceaux de gateau succulent 182Le nouveau EUR remplace le vieux FF. 183EOF 184 185: ${LOCALE_FR=fr_FR} 186: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 187: ${CSHARPEXEC="/bin/sh ../../csharpexec.sh"} 188if test $LOCALE_FR != none; then 189 # On Mac OS X, with mono 4.2.3, this test would fail, because the Console's 190 # output encoding is System.Text.Encoding.Default, and this is UTF-8 even 191 # in the fr_FR.ISO8859-1 locale. System.Text.Encoding.Default is defined 192 # through InternalCodePage(), which uses g_get_charset(), which uses either 193 # locale_charset() or nl_langinfo(CODESET) [which is "ISO8859-1" in this case] 194 # or "UTF-8" - depending on platform or build configuration. So, allow the 195 # expected result in UTF-8 encoding here too. 196 prepare_locale_ fr $LOCALE_FR 197 LANGUAGE= LC_ALL=$LOCALE_FR ${CSHARPEXEC} -L ../../../gettext-runtime/intl-csharp program.exe 2 > prog.out || Exit 1 198 ${DIFF} prog.oku prog.out >/dev/null || ${DIFF} prog.ok prog.out || Exit 1 199fi 200if test $LOCALE_FR_UTF8 != none; then 201 prepare_locale_ fr $LOCALE_FR_UTF8 202 LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 ${CSHARPEXEC} -L ../../../gettext-runtime/intl-csharp program.exe 2 > prog.out || Exit 1 203 ${DIFF} prog.oku prog.out || Exit 1 204fi 205 206Exit 0 207