Back to index

glibc  2.9
tst-gettext2.c
Go to the documentation of this file.
00001 /* Test of the gettext functions.
00002    Copyright (C) 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Thorsten Kukuk <kukuk@suse.de> and
00005    Andreas Jaeger <aj@suse.de>, 2000.
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 
00023 #include <locale.h>
00024 #include <libintl.h>
00025 #include <stdlib.h>
00026 #include <stdio.h>
00027 
00028 struct data_t
00029 {
00030   const char *selection;
00031   const char *description;
00032 };
00033 
00034 int data_cnt = 2;
00035 struct data_t strings[] =
00036 {
00037   { "String1", N_("First string for testing.") },
00038   { "String2", N_("Another string for testing.") }
00039 };
00040 
00041 const int lang_cnt = 3;
00042 const char *lang[] = {"lang1", "lang2", "lang3"};
00043 
00044 int
00045 main (void)
00046 {
00047   int i;
00048 
00049   /* Clean up environment.  */
00050   unsetenv ("LANGUAGE");
00051   unsetenv ("LC_ALL");
00052   unsetenv ("LC_MESSAGES");
00053   unsetenv ("LC_CTYPE");
00054   unsetenv ("LANG");
00055   unsetenv ("OUTPUT_CHARSET");
00056 
00057   textdomain ("tstlang");
00058 
00059   for (i = 0; i < lang_cnt; ++i)
00060     {
00061       int j;
00062 
00063       if (setlocale (LC_ALL, lang[i]) == NULL)
00064        setlocale (LC_ALL, "C");
00065       bindtextdomain ("tstlang", OBJPFX "domaindir");
00066 
00067       for (j = 0; j < data_cnt; ++j)
00068        printf ("%s - %s\n", strings[j].selection,
00069               gettext (strings[j].description));
00070     }
00071 
00072   return 0;
00073 }