- nFound=i;
- nParts=num_tokens(search,',');
- if (nParts>0)
- {
- extract_token(prefers,search, 1,';',len);
- extract_token(langs,search, 0,';',len);
+/*
+ * Create a locale_t for each available language
+ */
+void initialize_locales(void) {
+ int nLocales;
+ int i;
+ char *language = NULL;
+
+#ifdef ENABLE_NLS
+ setlocale(LC_ALL, "");
+ syslog(9, "Text domain: %s", textdomain("webcit"));
+ syslog(9, "Message catalog directory: %s", bindtextdomain(textdomain(NULL), LOCALEDIR"/locale"));
+ syslog(9, "Text domain Charset: %s", bind_textdomain_codeset("webcit","UTF8"));
+#endif
+
+ nLocales = 0;
+ while (!IsEmptyStr(AvailLang[nLocales]))
+ nLocales++;
+
+ language = getenv("WEBCIT_LANG");
+ if ((language) && (!IsEmptyStr(language)) && (strcmp(language, "UNLIMITED") != 0)) {
+ syslog(9, "Nailing locale to %s", language);
+ }
+ else language = NULL;
+
+ AvailLangLoaded = malloc (sizeof(char*) * nLocales);
+ memset(AvailLangLoaded, 0, sizeof(char*) * nLocales);
+#ifdef HAVE_USELOCALE
+ wc_locales = malloc (sizeof(locale_t) * nLocales);
+ memset(wc_locales,0, sizeof(locale_t) * nLocales);
+ wc_locales[0] = newlocale(LC_ALL_MASK, NULL, NULL);
+#endif
+
+ for (i = 1; i < nLocales; ++i) {
+#ifdef HAVE_USELOCALE
+ wc_locales[nLocalesLoaded] = newlocale(
+ (LC_MESSAGES_MASK|LC_TIME_MASK),
+ AvailLang[i],
+ wc_locales[0]
+ );
+ if (wc_locales[nLocalesLoaded] == NULL) {
+ syslog(1, "locale for %s disabled: %s (domain: %s, path: %s)",
+ AvailLang[i],
+ strerror(errno),
+ textdomain(NULL),
+ bindtextdomain(textdomain(NULL), NULL)
+ );