* fix bug in locale declaration array (missing ,)
authorWilfried Göesgens <willi@citadel.org>
Sat, 1 Aug 2009 10:07:44 +0000 (10:07 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 1 Aug 2009 10:07:44 +0000 (10:07 +0000)
* 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
webcit/gettext.c
webcit/setup.c
webcit/wc_gettext.h [deleted file]
webcit/webcit.h
webcit/webserver.c

index 40419ac2e920744e091bf04e8515647477da6305..4384e7dc0a899670d2c0872f6ab1bdedf7ab508d 100644 (file)
@@ -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;
index 990ef23d034b5042fde732076257e757839825d0..fcd1f82e256ad30040bc3f1d91cb06a427b1dbb8 100644 (file)
@@ -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);
 }
 
index d4267aec932b913400500e7361a8e1660ff4605b..2eaeae5b74c193dad9e006e121090fc0b7af361d 100644 (file)
@@ -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 (file)
index dc05f0e..0000000
+++ /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);
index 45330cfb8e103513adcc7566fb9f2bf2844595cc..f7e0c121494164cae3c20f52b8a6d1debf6ed245 100644 (file)
@@ -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);
index 6d5d5c3da766f488c634205450898ec3865bfaa6..fa02e2dd473a8f5ede439a141ba467cb3fa57080 100644 (file)
@@ -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();