--- /dev/null
+#! /bin/sh
+
+# Test that on glibc systems, gettext() works right even with intermediate
+# setlocale() calls.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+# This test works only on glibc systems.
+grep '@GLIBC2@.*yes' ../config.status >/dev/null || exit 77
+
+# This test works only on systems that have a de_DE and fr_FR locale installed.
+LC_ALL=de_DE ./testlocale || exit 77
+LC_ALL=fr_FR ./testlocale || exit 77
+
+tmpfiles="$tmpfiles de_DE fr_FR"
+test -d de_DE || mkdir de_DE
+test -d de_DE/LC_MESSAGES || mkdir de_DE/LC_MESSAGES
+test -d fr_FR || mkdir fr_FR
+test -d fr_FR/LC_MESSAGES || mkdir fr_FR/LC_MESSAGES
+
+: ${MSGFMT=msgfmt}
+${MSGFMT} -o de_DE/LC_MESSAGES/tstlang.mo ${top_srcdir}/tests/gettext-3-1.po
+${MSGFMT} -o fr_FR/LC_MESSAGES/tstlang.mo ${top_srcdir}/tests/gettext-3-2.po
+
+tmpfiles="$tmpfiles gt-3.ok"
+cat <<EOF > gt-3.ok
+String1 - Lang1: 1st string
+String2 - Lang1: 2nd string
+String1 - Lang2: 1st string
+String2 - Lang2: 2nd string
+String1 - First string for testing.
+String2 - Another string for testing.
+EOF
+
+tmpfiles="$tmpfiles gt-3.out"
+./gettext-3-prg > gt-3.out || exit 1
+
+: ${DIFF=diff}
+${DIFF} gt-3.ok gt-3.out || exit 1
+
+rm -fr $tmpfiles
+
+exit 0
--- /dev/null
+/* Test program, used by the gettext-3 test.
+ Copyright (C) 2000, 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Contributed to the GNU C Library by
+ Thorsten Kukuk <kukuk@suse.de> and Andreas Jaeger <aj@suse.de>, 2000. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <locale.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "setenv.h"
+
+/* Make sure we use the included libintl, not the system's one. */
+#undef _LIBINTL_H
+#include "libgnuintl.h"
+
+#define N_(string) string
+
+struct data_t
+{
+ const char *selection;
+ const char *description;
+};
+
+struct data_t strings[] =
+{
+ { "String1", N_("First string for testing.") },
+ { "String2", N_("Another string for testing.") }
+};
+const int data_cnt = sizeof (strings) / sizeof (strings[0]);
+
+const char *lang[] = { "de_DE", "fr_FR", "ll_CC" };
+const int lang_cnt = sizeof (lang) / sizeof (lang[0]);
+
+int
+main (void)
+{
+ int i;
+
+ /* Clean up environment. */
+ unsetenv ("LANGUAGE");
+ unsetenv ("LC_ALL");
+ unsetenv ("LC_MESSAGES");
+ unsetenv ("LC_CTYPE");
+ unsetenv ("LANG");
+ unsetenv ("OUTPUT_CHARSET");
+
+ textdomain ("tstlang");
+
+ for (i = 0; i < lang_cnt; ++i)
+ {
+ int j;
+
+ if (setlocale (LC_ALL, lang[i]) == NULL)
+ setlocale (LC_ALL, "C");
+
+ bindtextdomain ("tstlang", ".");
+
+ for (j = 0; j < data_cnt; ++j)
+ printf ("%s - %s\n", strings[j].selection,
+ gettext (strings[j].description));
+ }
+
+ return 0;
+}