]> code.citadel.org Git - citadel.git/blobdiff - webcit/gettext.c
* several memoryleaks
[citadel.git] / webcit / gettext.c
index 37ef96545f418cc51afd6586be8f63aa2476f826..52332f8152b64a4db519d1e8403c808749969745 100644 (file)
@@ -1,20 +1,16 @@
 /*
- * $Id
+ * $Id$
  */
-/**
- * \defgroup LocaleHeaderParser Parse the browser http locale headers and set the NLS stuff.
- * \ingroup WebcitHttpServer 
- */
-/*@{*/
+
 #include "webcit.h"
 #include "webserver.h"
 
 #ifdef ENABLE_NLS
 
-#define NUM_LANGS 9 /**< how many different locales do we know? */
-#define SEARCH_LANG 20 /**< how many langs should we parse? */
+#define NUM_LANGS 10           /* how many different locales do we know? */
+#define SEARCH_LANG 20         /* how many langs should we parse? */
 
-/** actual supported locales */
+/* actual supported locales */
 char *AvailLang[NUM_LANGS] = {
        "C",
        "en_US",
@@ -24,10 +20,13 @@ char *AvailLang[NUM_LANGS] = {
        "en_GB",
        "da_DK",
        "fr_FR",
-       "nl_NL"
+       "nl_NL",
+       "pt_BR"
 };
 
+#ifdef HAVE_USELOCALE
 locale_t wc_locales[NUM_LANGS]; /**< here we keep the parsed stuff */
+#endif
 
 /** Keep information about one locale */
 typedef struct _lang_pref{
@@ -194,10 +193,19 @@ void httplang_to_locale(char *LocaleString)
  */
 void offer_languages(void) {
        int i;
+#ifndef HAVE_USELOCALE
+       char *Lang = getenv("LANG");
+       
+       if (Lang == NULL)
+               Lang = "C";
+#endif
 
        wprintf("<select name=\"language\" id=\"lname\" size=\"1\">\n");
 
        for (i=0; i < NUM_LANGS; ++i) {
+#ifndef HAVE_USELOCALE
+               if (strcmp(AvailLang[i], Lang) == 0)
+#endif
                wprintf("<option %s value=%s>%s</option>\n",
                        ((WC->selected_language == i) ? "selected" : ""),
                        AvailLang[i],
@@ -212,14 +220,16 @@ void offer_languages(void) {
  * \brief Set the selected language for this session.
  * \param lang the locale to set.
  */
-void set_selected_language(char *lang) {
+void set_selected_language(const char *lang) {
        int i;
 
+#ifdef HAVE_USELOCALE
        for (i=0; i<NUM_LANGS; ++i) {
                if (!strcasecmp(lang, AvailLang[i])) {
                        WC->selected_language = i;
                }
        }
+#endif
 }
 
 /**
@@ -230,6 +240,11 @@ void go_selected_language(void) {
        if (WC->selected_language < 0) return;
        uselocale(wc_locales[WC->selected_language]);   /** switch locales */
        textdomain(textdomain(NULL));                   /** clear the cache */
+#else
+       char *language;
+       
+       language = getenv("LANG");
+       setlocale(LC_MESSAGES, language);
 #endif
 }
 
@@ -249,21 +264,28 @@ void preset_locale(void)
 #ifdef HAVE_GETTEXT
        char *language;
        
+       lprintf(9, "Nailing locale to %s\n", getenv("LANG"));
        language = getenv("LANG");
        setlocale(LC_MESSAGES, language);
 #endif
 #endif
 }
+
+#ifdef HAVE_USELOCALE
+       locale_t Empty_Locale;
+#endif
+
 /**
  * \brief Create a locale_t for each available language
  */
 void initialize_locales(void) {
        int i;
-       locale_t Empty_Locale;
        char buf[32];
 
+#ifdef HAVE_USELOCALE
        /* create default locale */
        Empty_Locale = newlocale(LC_ALL_MASK, NULL, NULL);
+#endif
 
        for (i = 0; i < NUM_LANGS; ++i) {
                if (i == 0) {
@@ -272,6 +294,7 @@ void initialize_locales(void) {
                else {
                        sprintf(buf, "%s.UTF8", AvailLang[i]);
                }
+#ifdef HAVE_USELOCALE
                wc_locales[i] = newlocale(
                        (LC_MESSAGES_MASK|LC_TIME_MASK),
                        buf,
@@ -286,9 +309,21 @@ void initialize_locales(void) {
                else {
                        lprintf(3, "Configured available locale: %s\n", buf);
                }
+#endif
        }
 }
 
+void ShutdownLocale(void)
+{
+       int i;
+#ifdef HAVE_USELOCALE
+       for (i = 0; i < NUM_LANGS; ++i) {
+               if (Empty_Locale != wc_locales[i])
+                       freelocale(wc_locales[i]);
+       }
+       freelocale(Empty_Locale);
+#endif
+}
 
 #else  /* ENABLE_NLS */
 /** \brief dummy for non NLS enabled systems */
@@ -314,4 +349,3 @@ void preset_locale(void)
 #endif /* ENABLE_NLS */
 
 
-/*@}*/