GRASS Programmer's Manual 6.4.1(2011)
|
00001 00017 #include <grass/config.h> 00018 #include <stdlib.h> 00019 #include <string.h> 00020 #include <locale.h> 00021 #include <grass/glocale.h> 00022 00023 00024 #if defined(HAVE_LIBINTL_H) && defined(USE_NLS) 00025 static char *locale_dir(void) 00026 { 00027 static char localedir[4096]; 00028 const char *gisbase; 00029 00030 if (*localedir) 00031 return localedir; 00032 00033 gisbase = getenv("GISBASE"); 00034 if (!gisbase || !*gisbase) 00035 return ""; 00036 00037 strcpy(localedir, gisbase); 00038 strcat(localedir, "/locale"); 00039 00040 return localedir; 00041 } 00042 #endif 00043 00044 00053 char *G_gettext(const char *package, const char *msgid) 00054 { 00055 #if defined(HAVE_LIBINTL_H) && defined(USE_NLS) 00056 static char now_bound[4096]; 00057 static int initialized; 00058 00059 if (!initialized) { 00060 setlocale(LC_CTYPE, ""); 00061 setlocale(LC_MESSAGES, ""); 00062 initialized = 1; 00063 } 00064 00065 if (strcmp(now_bound, package) != 0) { 00066 strcpy(now_bound, package); 00067 bindtextdomain(package, locale_dir()); 00068 } 00069 00070 return dgettext(package, msgid); 00071 #else 00072 return (char *)msgid; 00073 #endif 00074 }