]> code.citadel.org Git - citadel.git/blobdiff - webcit/gettext.c
removed empty_locale and just use wc_locales[0] for this purpose
[citadel.git] / webcit / gettext.c
index 3639602e613aae2bc2ad1e95c3193bdca3fd77b4..25474e810c5b8f68eb2f521cdc90de0be6dbb3ad 100644 (file)
@@ -39,6 +39,7 @@ const char *AvailLang[] = {
        "kk_KK",
        "ro_RO",
        "sl_SL",
+       "tr_TR",
        ""
 };
 
@@ -279,9 +280,6 @@ void stop_selected_language(void) {
 #endif
 }
 
-#ifdef HAVE_USELOCALE
-       locale_t Empty_Locale;
-#endif
 
 /*
  * Create a locale_t for each available language
@@ -289,9 +287,15 @@ void stop_selected_language(void) {
 void initialize_locales(void) {
        int nLocales;
        int i;
-       char buf[32];
        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++;
@@ -307,42 +311,38 @@ void initialize_locales(void) {
 #ifdef HAVE_USELOCALE
        wc_locales = malloc (sizeof(locale_t) * nLocales);
        memset(wc_locales,0, sizeof(locale_t) * nLocales);
-       /* create default locale */
-       Empty_Locale = newlocale(LC_ALL_MASK, NULL, NULL);
+       wc_locales[0] = newlocale(LC_ALL_MASK, NULL, NULL);
 #endif
 
-       for (i = 0; i < nLocales; ++i) {
-               if ((language != NULL) && (strcmp(AvailLang[i], language) != 0))
-                       continue;
-               if (i == 0) {
-                       sprintf(buf, "%s", AvailLang[i]);       /* locale 0 (C) is ascii, not utf-8 */
-               }
-               else {
-                       sprintf(buf, "%s.UTF8", AvailLang[i]);
-               }
+       for (i = 1; i < nLocales; ++i) {
 #ifdef HAVE_USELOCALE
                wc_locales[nLocalesLoaded] = newlocale(
                        (LC_MESSAGES_MASK|LC_TIME_MASK),
-                       buf,
-                       (((i > 0) && (wc_locales[0] != NULL)) ? wc_locales[0] : Empty_Locale)
+                       AvailLang[i],
+                       wc_locales[0]
                );
                if (wc_locales[nLocalesLoaded] == NULL) {
-                       syslog(1, "locale for %s disabled: %s", buf, strerror(errno));
+                       syslog(1, "locale for %s disabled: %s (domain: %s, path: %s)",
+                               AvailLang[i],
+                               strerror(errno),
+                               textdomain(NULL),
+                               bindtextdomain(textdomain(NULL), NULL)
+                       );
                }
                else {
-                       syslog(3, "Found locale: %s", buf);
+                       syslog(3, "Found locale: %s", AvailLang[i]);
                        AvailLangLoaded[nLocalesLoaded] = AvailLang[i];
                        nLocalesLoaded++;
                }
 #else
                if ((language != NULL) && (strcmp(language, AvailLang[i]) == 0)) {
-                       setenv("LANG", buf, 1);
+                       setenv("LANG", AvailLang[i], 1);
                        AvailLangLoaded[nLocalesLoaded] = AvailLang[i];
                        setlocale(LC_MESSAGES, AvailLang[i]);
                        nLocalesLoaded++;
                }
                else if (nLocalesLoaded == 0) {
-                       setenv("LANG", buf, 1);
+                       setenv("LANG", AvailLang[i], 1);
                        AvailLangLoaded[nLocalesLoaded] = AvailLang[i];
                        nLocalesLoaded++;
                }
@@ -350,26 +350,13 @@ void initialize_locales(void) {
        }
        if ((language != NULL) && (nLocalesLoaded == 0)) {
                syslog(1, "Your selected locale [%s] isn't available on your system. falling back to C", language);
-#ifdef HAVE_USELOCALE
-               wc_locales[0] = newlocale(
-                       (LC_MESSAGES_MASK|LC_TIME_MASK),
-                       AvailLang[0],
-                       Empty_Locale
-               );
-#else
+#ifndef HAVE_USELOCALE
                setlocale(LC_MESSAGES, AvailLang[0]);
                setenv("LANG", AvailLang[0], 1);
 #endif
                AvailLangLoaded[0] = AvailLang[0];
                nLocalesLoaded = 1;
        }
-
-#ifdef ENABLE_NLS
-       setlocale(LC_ALL, "");
-       syslog(9, "Message catalog directory: %s", bindtextdomain("webcit", LOCALEDIR"/locale"));
-       syslog(9, "Text domain: %s", textdomain("webcit"));
-       syslog(9, "Text domain Charset: %s", bind_textdomain_codeset("webcit","UTF8"));
-#endif
 }
 
 
@@ -380,9 +367,7 @@ ServerShutdownModule_GETTEXT
 #ifdef HAVE_USELOCALE
        int i;
        for (i = 0; i < nLocalesLoaded; ++i) {
-               if (Empty_Locale != wc_locales[i]) {
-                       freelocale(wc_locales[i]);
-               }
+               freelocale(wc_locales[i]);
        }
        free(wc_locales);
 #endif