From 0e30ee7b09f0e29d0ce731417ec121c635d96bf8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sat, 1 Aug 2009 10:07:44 +0000 Subject: [PATCH] * fix bug in locale declaration array (missing ,) * remove define with number of available langs and run till the empty element shows up; people tend to mess this up on adding new locales * move all gettext related initialization stuff into its module startup (rerun bootstrap..) --- webcit/fmt_date.c | 2 +- webcit/gettext.c | 44 +++++++++++++++++++++++++++++++++++--------- webcit/setup.c | 9 +++++++-- webcit/wc_gettext.h | 17 ----------------- webcit/webcit.h | 6 ++++++ webcit/webserver.c | 19 ------------------- 6 files changed, 49 insertions(+), 48 deletions(-) delete mode 100644 webcit/wc_gettext.h diff --git a/webcit/fmt_date.c b/webcit/fmt_date.c index 40419ac2e..4384e7dc0 100644 --- a/webcit/fmt_date.c +++ b/webcit/fmt_date.c @@ -6,7 +6,7 @@ #include "webserver.h" #ifdef HAVE_USELOCALE -extern locale_t wc_locales[]; +extern locale_t *wc_locales; #endif typedef unsigned char byte; diff --git a/webcit/gettext.c b/webcit/gettext.c index 990ef23d0..fcd1f82e2 100644 --- a/webcit/gettext.c +++ b/webcit/gettext.c @@ -4,10 +4,11 @@ #include "webcit.h" #include "webserver.h" +#define SEARCH_LANG 20 /* how many langs should we parse? */ #ifdef ENABLE_NLS /* actual supported locales */ -const char *AvailLang[NUM_LANGS] = { +const char *AvailLang[] = { "C", "en_US", "de_DE", @@ -17,15 +18,16 @@ const char *AvailLang[NUM_LANGS] = { "da_DK", "fr_FR", "nl_NL", - "pt_BR" - "hu_HU" + "pt_BR", + "hu_HU", + "" }; -const char *AvailLangLoaded[NUM_LANGS]; +const char **AvailLangLoaded; long nLocalesLoaded = 0; #ifdef HAVE_USELOCALE -locale_t wc_locales[NUM_LANGS]; /**< here we keep the parsed stuff */ +locale_t *wc_locales; /**< here we keep the parsed stuff */ #endif /** Keep information about one locale */ @@ -246,17 +248,28 @@ void stop_selected_language(void) { * \brief Create a locale_t for each available language */ void initialize_locales(void) { + int nLocales; int i; char buf[32]; char *language = NULL; - + char *locale; + + + nLocales = 0; + while (!IsEmptyStr(AvailLang[nLocales])) + nLocales++; + language = getenv("WEBCIT_LANG"); if ((language) && (!IsEmptyStr(language)) && (strcmp(language, "UNLIMITED") != 0)) { lprintf(9, "Nailing locale to %s\n", language); } else language = NULL; + AvailLangLoaded = malloc (sizeof(char*) * nLocales); + memset(AvailLangLoaded, 0, sizeof(char*) * nLocales); #ifdef HAVE_USELOCALE + wc_locales = malloc (sizeof(locale_t) * nLocales); + memset(wc_locales,0, sizeof(locale_t) * nLocales); /* create default locale */ Empty_Locale = newlocale(LC_ALL_MASK, NULL, NULL); #endif @@ -264,7 +277,7 @@ void initialize_locales(void) { - for (i = 0; i < NUM_LANGS; ++i) { + for (i = 0; i < nLocales; ++i) { if ((language != NULL) && (strcmp(AvailLang[i], language) != 0)) continue; if (i == 0) { @@ -280,7 +293,7 @@ void initialize_locales(void) { (((i > 0) && (wc_locales[0] != NULL)) ? wc_locales[0] : Empty_Locale) ); if (wc_locales[nLocalesLoaded] == NULL) { - lprintf(1, "Error configuring locale for %s: %s\n", + lprintf(1, "Error configuring locale for "LOCALEDIR"locale/%s: %s\n", buf, strerror(errno) ); @@ -322,10 +335,20 @@ void initialize_locales(void) { #endif +#ifdef ENABLE_NLS + locale = setlocale(LC_ALL, ""); + + lprintf(9, "Message catalog directory: %s\n", bindtextdomain("webcit", LOCALEDIR"/locale")); + lprintf(9, "Text domain: %s\n", textdomain("webcit")); + lprintf(9, "Text domain Charset: %s\n", bind_textdomain_codeset("webcit","UTF8")); + +#endif } -void ShutdownLocale(void) +void +ServerShutdownModule_GETTEXT +(void) { #ifdef HAVE_USELOCALE int i; @@ -333,6 +356,8 @@ void ShutdownLocale(void) if (Empty_Locale != wc_locales[i]) freelocale(wc_locales[i]); } + free(wc_locales); + free(AvailLangLoaded); #endif } @@ -387,6 +412,7 @@ void InitModule_GETTEXT (void) { + initialize_locales(); RegisterNamespace("LANG:SELECT", 0, 0, tmplput_offer_languages, CTX_NONE); } diff --git a/webcit/setup.c b/webcit/setup.c index d4267aec9..2eaeae5b7 100644 --- a/webcit/setup.c +++ b/webcit/setup.c @@ -252,9 +252,10 @@ void set_value(char *prompt, char str[]) } - +extern char **AvailLang; int GetLocalePrefs(void) { + int nLocales; StrBuf *Buf; char buf[SIZ]; char dialog_result[PATH_MAX]; @@ -263,6 +264,10 @@ int GetLocalePrefs(void) int offs = 0; + nLocales = 0; + while (!IsEmptyStr(AvailLang[nLocales])) + nLocales++; + Buf = NewStrBuf(); StrBufAppendBufPlain(Buf, HKEY("Select the locale webcit should use : \n"), 0); @@ -270,7 +275,7 @@ int GetLocalePrefs(void) StrBufAppendBufPlain(Buf, HKEY(" 0 Let the user select it at the login prompt (default)\n"), 0); offs ++; #endif - for (i = 0; i < NUM_LANGS; i++) { + for (i = 0; i < nLocales; i++) { StrBufAppendPrintf(Buf, " %ld: %s\n", i + offs, AvailLang[i]); } diff --git a/webcit/wc_gettext.h b/webcit/wc_gettext.h deleted file mode 100644 index dc05f0e16..000000000 --- a/webcit/wc_gettext.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifdef ENABLE_NLS -void initialize_locales(void); -void ShutdownLocale(void); - -#define NUM_LANGS 10 /* how many different locales do we know? */ -#define SEARCH_LANG 20 /* how many langs should we parse? */ - -/* actual supported locales */ -extern const char *AvailLang[NUM_LANGS]; -#else -#define NUM_LANGS 1 /* how many different locales do we know? */ -#endif -void TmplGettext(StrBuf *Target, WCTemplputParams *TP); -void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType); -void set_selected_language(const char *); -void go_selected_language(void); -void stop_selected_language(void); diff --git a/webcit/webcit.h b/webcit/webcit.h index 45330cfb8..f7e0c1214 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -877,6 +877,12 @@ enum { navbar_default }; +/* actual supported locales */ +void TmplGettext(StrBuf *Target, WCTemplputParams *TP); +void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType); +void set_selected_language(const char *); +void go_selected_language(void); +void stop_selected_language(void); #ifdef HAVE_OPENSSL void init_ssl(void); diff --git a/webcit/webserver.c b/webcit/webserver.c index 6d5d5c3da..fa02e2dd4 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -329,10 +329,6 @@ int main(int argc, char **argv) char *pidfile = NULL; char *hdir; const char *basedir = NULL; -#ifdef ENABLE_NLS - char *locale = NULL; - char *mo = NULL; -#endif /* ENABLE_NLS */ char uds_listen_path[PATH_MAX]; /* listen on a unix domain socket? */ const char *I18nDumpFile = NULL; @@ -477,18 +473,6 @@ int main(int argc, char **argv) /* initialize the International Bright Young Thing */ -#ifdef ENABLE_NLS - initialize_locales(); - - - locale = setlocale(LC_ALL, ""); - - mo = malloc(strlen(webcitdir) + 20); - lprintf(9, "Message catalog directory: %s\n", bindtextdomain("webcit", LOCALEDIR"/locale")); - free(mo); - lprintf(9, "Text domain: %s\n", textdomain("webcit")); - lprintf(9, "Text domain Charset: %s\n", bind_textdomain_codeset("webcit","UTF8")); -#endif initialise_modules(); initialize_viewdefs(); @@ -602,9 +586,6 @@ void ShutDownWebcit(void) icalmemory_free_ring (); ShutDownLibCitadel (); shutdown_modules (); -#ifdef ENABLE_NLS - ShutdownLocale(); -#endif #ifdef HAVE_OPENSSL if (is_https) { shutdown_ssl(); -- 2.30.2