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 g++. 6 7tmpfiles="" 8trap 'rm -fr $tmpfiles' 1 2 3 15 9 10# Test whether a C++ compiler is found and libasprintf is built. 11test "${CXX}" != ":" || { 12 echo "Skipping test: no C++ compiler found" 13 exit 77 14} 15test "${TESTLIBASPRINTF}" = yes || { 16 echo "Skipping test: configured with --disable-libasprintf" 17 exit 77 18} 19 20tmpfiles="$tmpfiles prog.cc" 21cat <<\EOF > prog.cc 22#include "config.h" 23 24/* Avoid deprecation warnings from g++ 3.1 or newer. */ 25#if defined __GNUG__ && defined __DEPRECATED 26# include <iostream> 27using namespace std; 28#else 29# include <iostream.h> 30#endif 31 32#include <libintl.h> 33#include <locale.h> 34#include <stdio.h> 35#include <stdlib.h> 36#include "xsetenv.h" 37#include "autosprintf.h" 38using gnu::autosprintf; 39#define _(string) gettext (string) 40 41int main (int argc, char *argv[]) 42{ 43 int n = atoi (argv[2]); 44 45 xsetenv ("LC_ALL", argv[1], 1); 46 if (setlocale (LC_ALL, "") == NULL) 47 // Couldn't set locale. 48 exit (77); 49 50 textdomain ("prog"); 51 bindtextdomain ("prog", "."); 52 53 cout << _("'Your command, please?', asked the waiter.") << endl; 54 55 cout << autosprintf (ngettext ("a piece of cake", "%d pieces of cake", n), n) 56 << endl; 57 58 cout << autosprintf (_("%s is replaced by %s."), "FF", "EUR") << endl; 59} 60EOF 61 62# Variable needed by LTLIBINTL. 63top_builddir=.. 64 65tmpfiles="$tmpfiles prog.${OBJEXT} prog${EXEEXT}" 66# Compile in two steps from .cc to .o and from .o to 'prog'. This way, 67# relinking is faster because doesn't need to redo the first step. 68# Put the -I flags before ${CXXFLAGS} ${CPPFLAGS}, to make sure that libintl.h 69# is found in the build directory, regardless of -I options present in 70# ${CXXFLAGS} or ${CPPFLAGS}. 71${CXX} -I.. -I../../gettext-runtime/libasprintf -I$top_srcdir/gnulib-lib -I../intl ${CXXFLAGS} ${CPPFLAGS} -c prog.cc \ 72 || exit 1 73${LIBTOOL} --quiet --mode=link ${CXX} ${CXXFLAGS} ${LDFLAGS} -o prog prog.${OBJEXT} ../../gettext-runtime/libasprintf/libasprintf.la ../gnulib-lib/libgettextlib.la ${LTLIBINTL} \ 74 || exit 1 75 76tmpfiles="$tmpfiles prog.pot" 77: ${XGETTEXT=xgettext} 78${XGETTEXT} -o prog.pot --omit-header --no-location -k_ prog.cc 79 80tmpfiles="$tmpfiles prog.ok" 81cat <<EOF > prog.ok 82msgid "'Your command, please?', asked the waiter." 83msgstr "" 84 85#, c-format 86msgid "a piece of cake" 87msgid_plural "%d pieces of cake" 88msgstr[0] "" 89msgstr[1] "" 90 91#, c-format 92msgid "%s is replaced by %s." 93msgstr "" 94EOF 95 96: ${DIFF=diff} 97${DIFF} prog.ok prog.pot || exit 1 98 99tmpfiles="$tmpfiles fr.po" 100cat <<\EOF > fr.po 101msgid "" 102msgstr "" 103"Content-Type: text/plain; charset=ISO-8859-1\n" 104"Plural-Forms: nplurals=2; plural=(n > 1);\n" 105 106msgid "'Your command, please?', asked the waiter." 107msgstr "�Votre commande, s'il vous plait�, dit le gar�on." 108 109# Les gateaux allemands sont les meilleurs du monde. 110#, c-format 111msgid "a piece of cake" 112msgid_plural "%d pieces of cake" 113msgstr[0] "un morceau de gateau" 114msgstr[1] "%d morceaux de gateau" 115 116# Reverse the arguments. 117#, c-format 118msgid "%s is replaced by %s." 119msgstr "%2$s remplace %1$s." 120EOF 121 122tmpfiles="$tmpfiles fr.po.new" 123: ${MSGMERGE=msgmerge} 124${MSGMERGE} -q -o fr.po.new fr.po prog.pot 125 126: ${DIFF=diff} 127${DIFF} fr.po fr.po.new || exit 1 128 129tmpfiles="$tmpfiles fr" 130test -d fr || mkdir fr 131test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES 132 133: ${MSGFMT=msgfmt} 134${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po 135 136tmpfiles="$tmpfiles prog.ok prog.oku prog.out" 137: ${DIFF=diff} 138cat <<\EOF > prog.ok 139�Votre commande, s'il vous plait�, dit le gar�on. 1402 morceaux de gateau 141EUR remplace FF. 142EOF 143cat <<\EOF > prog.oku 144��Votre commande, s'il vous plait��, dit le gar��on. 1452 morceaux de gateau 146EUR remplace FF. 147EOF 148 149: ${LOCALE_FR=fr_FR} 150: ${LOCALE_FR_UTF8=fr_FR.UTF-8} 151if test $LOCALE_FR != none; then 152 LANGUAGE= ./prog $LOCALE_FR 2 > prog.out 153 case $? in 154 0) ${DIFF} prog.ok prog.out || exit 1;; 155 77) LOCALE_FR=none;; 156 *) exit 1;; 157 esac 158fi 159if test $LOCALE_FR_UTF8 != none; then 160 LANGUAGE= ./prog $LOCALE_FR_UTF8 2 > prog.out 161 case $? in 162 0) ${DIFF} prog.oku prog.out || exit 1;; 163 77) LOCALE_FR_UTF8=none;; 164 *) exit 1;; 165 esac 166fi 167if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then 168 if test -f /usr/bin/localedef; then 169 echo "Skipping test: no french locale is installed" 170 else 171 echo "Skipping test: no french locale is supported" 172 fi 173 rm -fr $tmpfiles; exit 77 174fi 175 176rm -fr $tmpfiles 177 178exit 0 179