*/
/**
* \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 */
"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 */
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';
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. */
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);
+ }
}
}