* Per-session locale. For some reason it doesn't work well.
authorArt Cancro <ajc@citadel.org>
Wed, 7 Dec 2005 18:03:29 +0000 (18:03 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 7 Dec 2005 18:03:29 +0000 (18:03 +0000)
webcit/ChangeLog
webcit/auth.c
webcit/context_loop.c
webcit/gettext.c
webcit/webcit.h
webcit/webserver.c

index 6f20f054e231999cbf28e697cc3772dd77a2b70a..7fa2f2f028806bb28c6325ad9b4438e3dc2833e6 100644 (file)
@@ -1,5 +1,8 @@
 $Id$
 
+Wed Dec  7 13:03:05 EST 2005 ajc
+* Per-session locale.  For some reason it doesn't work well.
+
 Wed Dec  7 08:23:31 EST 2005 ajc
 * po/it.po: Italian localization submitted by Gabriele Tassoni
 
index d32818a59a431ae2512146c4a2c2ccad8cef6c9e..1101afec30fbee66021f76297cbd95f33f06767b 100644 (file)
@@ -20,22 +20,6 @@ void initialize_axdefs(void) {
 }
 
 
-/*
- * Offer available languages in the login box
- */
-void offer_languages(void) {
-
-#ifdef ENABLE_NLS
-
-wprintf("FIXME");
-
-#else /* ENABLE_NLS */
-
-wprintf("US English");
-
-#endif /* ENABLE_NLS */
-
-}
 
 
 /*
@@ -130,6 +114,11 @@ void do_login(void)
 {
        char buf[SIZ];
 
+       if (strlen(bstr("language")) > 0) {
+               set_selected_language(bstr("language"));
+               go_selected_language();
+       }
+
        if (strlen(bstr("exit_action")) > 0) {
                do_logout();
                return;
index 1667fdc195765f0ae6ef85c60744a5d99d752e50..a2cfad4a8c3d8c30af71835a280aa5e4ca1f45db 100644 (file)
@@ -435,7 +435,7 @@ void context_loop(int sock)
        TheSession->lastreq = time(NULL);                       /* log */
        TheSession->gzip_ok = gzip_ok;
 #ifdef ENABLE_NLS
-       httplang_to_locale(accept_language);    /* FIXME do more here */
+       go_selected_language();
 #endif /* ENABLE_NLS */
        session_loop(req);                              /* do transaction */
        pthread_mutex_unlock(&TheSession->SessionMutex);        /* unbind */
index d7f92b9d3765df51da74b749daa0afb311c88c13..4d44e533a083d3b5148d88f6ddabbe1f4ba12d18 100644 (file)
@@ -4,12 +4,15 @@
 
 #ifdef ENABLE_NLS
 
-static const char *AvailLang[] = {
+#define NUM_LANGS 3
+static const char *AvailLang[NUM_LANGS] = {
        "en_US",
        "de_DE",
        "it_IT"
 };
 
+locale_t wc_locales[NUM_LANGS];
+
 typedef struct _lang_pref{
        char lang[16];
        char region[16];
@@ -105,7 +108,6 @@ void httplang_to_locale(const char *LocaleString)
        free(search);
 }
 
-#endif
 
 
 /*
@@ -144,3 +146,74 @@ void httplang_to_locale(const char *LocaleString)
                i++;
        }
 */
+
+
+
+void offer_languages(void) {
+       int i;
+
+       wprintf("<select name=\"language\" size=\"1\">\n");
+
+       for (i=0; i < NUM_LANGS; ++i) {
+               wprintf("<option value=%s>%s</option>\n", AvailLang[i], AvailLang[i]);
+       }
+
+       wprintf("</select>\n");
+}
+
+/*
+ * Set the selected language for this session.
+ */
+void set_selected_language(char *lang) {
+       int i;
+
+       for (i=0; i<NUM_LANGS; ++i) {
+               if (!strcasecmp(lang, AvailLang[i])) {
+                       WC->selected_language = i;
+               }
+       }
+}
+
+/*
+ * Activate the selected language for this session.
+ */
+void go_selected_language(void) {
+       lprintf(9, "uselocale(%d)\n", WC->selected_language);
+       uselocale(wc_locales[WC->selected_language]);
+}
+
+
+/*
+ * Create a locale_t for each available language
+ */
+void initialize_locales(void) {
+       int i;
+       locale_t Empty_Locale;
+       char buf[32];
+
+       /* create default locale */
+       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 */ ,
+                       buf,
+                       Empty_Locale
+               );
+       }
+}
+
+
+#else  /* ENABLE_NLS */
+
+void offer_languages(void) {
+       wprintf("English (US)");
+}
+
+void set_selected_language(char *lang) {
+}
+
+void go_selected_language(void) {
+}
+
+#endif /* ENABLE_NLS */
index b78b1f85d3127dd016913ffeec085a941220506b..acc399d9f80081d2b326ea9b73ea04cac4d0128e 100644 (file)
@@ -376,6 +376,8 @@ struct wcsession {
 
        int current_iconbar;            /* What's currently in the iconbar? */
        char floordiv_expanded[32];     /* which floordiv currently expanded */
+
+       int selected_language;          /* Language selected by user */
 };
 
 /* values for WC->current_iconbar */
@@ -628,6 +630,10 @@ void check_attendee_availability(icalcomponent *supplied_vevent);
 void do_freebusy(char *req);
 #endif
 
+#ifdef ENABLE_NLS
+void initialize_locales(void);
+#endif
+
 extern char *months[];
 extern char *days[];
 void read_server_binary(char *buffer, size_t total_len);
@@ -647,6 +653,9 @@ int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
 void spawn_another_worker_thread(void);
 void display_rss(char *roomname, char *request_method);
 void set_floordiv_expanded(char *which_floordiv);
+void offer_languages(void);
+void set_selected_language(char *);
+void go_selected_language(void);
 
 void embed_room_banner(char *, int);
 /* navbar types that can be passed to embed_room_banner */
index cd16142806246d025230c65baeff117213a3e5c1..cae15d66ef4d9389c94267064cf9c87ef0b65f55 100644 (file)
@@ -461,6 +461,9 @@ 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);