$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
}
-/*
- * 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 */
-
-}
/*
{
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;
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 */
#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];
free(search);
}
-#endif
/*
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 */
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 */
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);
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 */
/* initialize the International Bright Young Thing */
#ifdef ENABLE_NLS
+
+ initialize_locales();
+
locale = setlocale(LC_ALL, "");
mo = malloc(strlen(webcitdir) + 20);