add changes from ubuntu launchpad
[citadel.git] / webcit / gettext.c
index 7713ce70dc1ce98a34c4936cd95e36073a7caf9a..f1b2f8a2713b109aa2912da3ddfd37e9c34fd179 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * Copyright (c) 1996-2010 by the citadel.org team
+ * Copyright (c) 1996-2011 by the citadel.org team
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
+ * This program is open source software.  You can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,7 +13,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
 #include "webcit.h"
 /* actual supported locales */
 const char *AvailLang[] = {
        "C",
+       "bg_BG",
+       "cs_CZ",
        "en_US",
+       "da_DK",
        "de_DE",
-       "it_IT",
-       "es_ES",
+       "el_GR",
        "en_GB",
-       "da_DK",
+       "es_ES",
+       "et_EE",
+       "fi_FI",
        "fr_FR",
+       "hu_HU",
+       "it_IT",
        "nl_NL",
        "pt_BR",
-       "hu_HU",
-       "et_EE",
        "ru_RU",
+       "zh_CN",
+       "he_IL",
+       "kk_KK",
+       "ro_RO",
+       "sl_SL",
        ""
 };
 
@@ -188,7 +197,7 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess)
                nBest=0;
        }
        sess->selected_language = nBest;
-       lprintf(9, "language found: %s\n", AvailLangLoaded[WC->selected_language]);
+       syslog(9, "language found: %s\n", AvailLangLoaded[WC->selected_language]);
        FreeStrBuf(&Buf);
        FreeStrBuf(&SBuf);
 }
@@ -214,7 +223,7 @@ void tmplput_offer_languages(StrBuf *Target, WCTemplputParams *TP)
                return;
        }
 
-       wc_printf("<select name=\"language\" id=\"lname\" size=\"1\">\n");
+       wc_printf("<select name=\"language\" id=\"lname\" size=\"1\" onChange=\"switch_to_lang($('lname').value);\">\n");
 
        for (i=0; i < nLocalesLoaded; ++i) {
 #ifndef HAVE_USELOCALE
@@ -283,8 +292,6 @@ void initialize_locales(void) {
        int i;
        char buf[32];
        char *language = NULL;
-       char *locale;
-
 
        nLocales = 0; 
        while (!IsEmptyStr(AvailLang[nLocales]))
@@ -292,7 +299,7 @@ void initialize_locales(void) {
 
        language = getenv("WEBCIT_LANG");
        if ((language) && (!IsEmptyStr(language)) && (strcmp(language, "UNLIMITED") != 0)) {
-               lprintf(9, "Nailing locale to %s\n", language);
+               syslog(9, "Nailing locale to %s\n", language);
        }
        else language = NULL;
 
@@ -324,13 +331,13 @@ void initialize_locales(void) {
                        (((i > 0) && (wc_locales[0] != NULL)) ? wc_locales[0] : Empty_Locale)
                );
                if (wc_locales[nLocalesLoaded] == NULL) {
-                       lprintf(1, "locale for "LOCALEDIR"locale/%s: %s; disabled\n",
+                       syslog(1, "locale for "LOCALEDIR"locale/%s: %s; disabled\n",
                                buf,
                                strerror(errno)
                        );
                }
                else {
-                       lprintf(3, "Found locale: %s\n", buf);
+                       syslog(3, "Found locale: %s\n", buf);
                        AvailLangLoaded[nLocalesLoaded] = AvailLang[i];
                        nLocalesLoaded++;
                }
@@ -349,7 +356,7 @@ void initialize_locales(void) {
 #endif
        }
        if ((language != NULL) && (nLocalesLoaded == 0)) {
-               lprintf(1, "Your selected locale [%s] isn't available on your system. falling back to C\n", language);
+               syslog(1, "Your selected locale [%s] isn't available on your system. falling back to C\n", language);
 #ifdef HAVE_USELOCALE
                wc_locales[0] = newlocale(
                        (LC_MESSAGES_MASK|LC_TIME_MASK),
@@ -364,11 +371,11 @@ void initialize_locales(void) {
        }
 
 #ifdef ENABLE_NLS
-       locale = setlocale(LC_ALL, "");
+       /*locale = */setlocale(LC_ALL, "");
 
-       lprintf(9, "Message catalog directory: %s\n", bindtextdomain("webcit", LOCALEDIR"/locale"));
-       lprintf(9, "Text domain: %s\n", textdomain("webcit"));
-       lprintf(9, "Text domain Charset: %s\n", bind_textdomain_codeset("webcit","UTF8"));
+       syslog(9, "Message catalog directory: %s\n", bindtextdomain("webcit", LOCALEDIR"/locale"));
+       syslog(9, "Text domain: %s\n", textdomain("webcit"));
+       syslog(9, "Text domain Charset: %s\n", bind_textdomain_codeset("webcit","UTF8"));
 
 #endif
 }
@@ -445,6 +452,7 @@ void Header_HandleAcceptLanguage(StrBuf *Line, ParsedHttpHdrs *hdr)
        hdr->HR.browser_language = Line;
 }
 
+
 void 
 InitModule_GETTEXT
 (void)
@@ -464,8 +472,10 @@ SessionNewModule_GETTEXT
 (wcsession *sess)
 {
 #ifdef ENABLE_NLS
-       if (!sess->Hdr->HR.Static && 
-           (sess->Hdr->HR.browser_language != NULL)) {
+       if (    (sess != NULL)
+               && (!sess->Hdr->HR.Static)
+               && (sess->Hdr->HR.browser_language != NULL)
+       ) {
                httplang_to_locale(sess->Hdr->HR.browser_language, sess);
        }
 #endif