]> code.citadel.org Git - citadel.git/blobdiff - webcit/gettext.c
webcit_before_automake is now the trunk
[citadel.git] / webcit / gettext.c
index 1be5e11f03a15a59fcb8d951b979380e1e52bb86..b7f0a784b6d95c65a27a76f3e2a9ffe7c34853ed 100644 (file)
@@ -3,16 +3,15 @@
  */
 /**
  * \defgroup LocaleHeaderParser Parse the browser http locale headers and set the NLS stuff.
+ * \ingroup WebcitHttpServer 
  */
 /*@{*/
-/** we need _GNU_SOURCE for various functions arround the NLS-Stuff */
-#define _GNU_SOURCE
 #include "webcit.h"
 #include "webserver.h"
 
 #ifdef ENABLE_NLS
 
-#define NUM_LANGS 4 /**< how many different locales do we know? */
+#define NUM_LANGS 6 /**< how many different locales do we know? */
 #define SEARCH_LANG 20 /**< how many langs should we parse? */
 
 /** actual supported locales */
@@ -20,7 +19,9 @@ char *AvailLang[NUM_LANGS] = {
        "C",
        "en_US",
        "de_DE",
-       "it_IT"
+       "it_IT",
+       "es_ES",
+       "en_GB"
 };
 
 locale_t wc_locales[NUM_LANGS]; /**< here we keep the parsed stuff */
@@ -58,8 +59,6 @@ void httplang_to_locale(char *LocaleString)
        int nBest;
        int nParts;
        char *search = (char *) malloc(len);
-       // locale_t my_Locale;
-       // locale_t my_Empty_Locale;
        
        memcpy(search, LocaleString, len);
        search[len] = '\0';
@@ -145,7 +144,9 @@ void httplang_to_locale(char *LocaleString)
                nBest=0;
        WC->selected_language=nBest;
        lprintf(9, "language found: %s\n", AvailLang[WC->selected_language]);
-       //      set_selected_language(selected_locale);
+       if (search != NULL) {
+               free(search);
+       }
 }
 
 /* TODO: we skip the language weightening so far. */
@@ -251,11 +252,26 @@ void initialize_locales(void) {
        Empty_Locale = newlocale(LC_ALL_MASK, NULL, NULL);
 
        for (i = 0; i < NUM_LANGS; ++i) {
-               sprintf(buf, "%s.UTF8", AvailLang[i]);
-               wc_locales[i] = newlocale(LC_MESSAGES_MASK /* |LC_TIME_MASK FIXME */ ,
+               if (i == 0) {
+                       sprintf(buf, "%s", AvailLang[i]);       // locale 0 (C) is ascii, not utf-8
+               }
+               else {
+                       sprintf(buf, "%s.UTF8", AvailLang[i]);
+               }
+               wc_locales[i] = newlocale(
+                       (LC_MESSAGES_MASK|LC_TIME_MASK),
                        buf,
-                       Empty_Locale
+                       (((i > 0) && (wc_locales[0] != NULL)) ? wc_locales[0] : Empty_Locale)
                );
+               if (wc_locales[i] == NULL) {
+                       lprintf(1, "Error configuring locale for %s: %s\n",
+                               buf,
+                               strerror(errno)
+                       );
+               }
+               else {
+                       lprintf(3, "Configured available locale: %s\n", buf);
+               }
        }
 }