locale.c

Go to the documentation of this file.
00001 
00002 #include <grass/config.h>
00003 #include <grass/glocale.h>
00004 
00005 #include <stdlib.h>
00006 #include <string.h>
00007 #include <locale.h>
00008 
00009 #if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
00010 static char *
00011 locale_dir(void)
00012 {
00013         static char localedir[4096];
00014 
00015         const char *gisbase;
00016 
00017         if (*localedir)
00018                 return localedir;
00019 
00020         gisbase = getenv("GISBASE");
00021         if (!gisbase || !*gisbase)
00022                 return "";
00023 
00024         strcpy(localedir, gisbase);
00025         strcat(localedir, "/locale");
00026 
00027         return localedir;
00028 }
00029 #endif
00030 
00031 char *
00032 G_gettext(const char *package, const char *msgid)
00033 {
00034 #if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
00035         static char now_bound[4096];
00036         static int initialized;
00037 
00038         if (!initialized)
00039         {
00040                 setlocale(LC_CTYPE, "");
00041                 setlocale(LC_MESSAGES, "");
00042                 initialized = 1;
00043         }
00044 
00045         if (strcmp(now_bound, package) != 0)
00046         {
00047                 strcpy(now_bound, package);
00048                 bindtextdomain(package, locale_dir());
00049         }
00050 
00051         return dgettext(package, msgid);
00052 #else
00053         return (char *) msgid;
00054 #endif
00055 }
00056 

Generated on Wed Dec 19 14:59:06 2007 for GRASS by  doxygen 1.5.4