+ * Copyright (c) 1996-2012 by the citadel.org team
+ *
+ * This program is open source software. You can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
- char lang[16]; /**< the language locale string */
- char region[16]; /**< the region locale string */
- long priority; /**< which priority does it have */
- int availability; /**< do we know it? */
- int selectedlang; /**< is this the selected language? */
+ char lang[16]; /* the language locale string */
+ char region[16]; /* the region locale string */
+ long priority; /* which priority does it have */
+ int availability; /* do we know it? */
+ int selectedlang; /* is this the selected language? */
-/* \brief parse browser locale header
- * seems as most browsers just do a one after coma value even if more than 10 locales are available. Sample strings:
+/* parse browser locale header
+ *
+ * seems as most browsers just do a one after comma value even if more than 10 locales are available. Sample strings:
* opera:
* Accept-Language: sq;q=1.0,de;q=0.9,as;q=0.8,ar;q=0.7,bn;q=0.6,zh-cn;q=0.5,kn;q=0.4,ch;q=0.3,fo;q=0.2,gn;q=0.1,ce;q=0.1,ie;q=0.1
* Firefox
* Accept-Language: 'de-de,en-us;q=0.7,en;q=0.3'
* Accept-Language: de,en-ph;q=0.8,en-us;q=0.5,de-at;q=0.3
* Accept-Language: de,en-us;q=0.9,it;q=0.9,de-de;q=0.8,en-ph;q=0.7,de-at;q=0.7,zh-cn;q=0.6,cy;q=0.5,ar-om;q=0.5,en-tt;q=0.4,xh;q=0.3,nl-be;q=0.3,cs;q=0.2,sv;q=0.1,tk;q=0.1
* opera:
* Accept-Language: sq;q=1.0,de;q=0.9,as;q=0.8,ar;q=0.7,bn;q=0.6,zh-cn;q=0.5,kn;q=0.4,ch;q=0.3,fo;q=0.2,gn;q=0.1,ce;q=0.1,ie;q=0.1
* Firefox
* Accept-Language: 'de-de,en-us;q=0.7,en;q=0.3'
* Accept-Language: de,en-ph;q=0.8,en-us;q=0.5,de-at;q=0.3
* Accept-Language: de,en-us;q=0.9,it;q=0.9,de-de;q=0.8,en-ph;q=0.7,de-at;q=0.7,zh-cn;q=0.6,cy;q=0.5,ar-om;q=0.5,en-tt;q=0.4,xh;q=0.3,nl-be;q=0.3,cs;q=0.2,sv;q=0.1,tk;q=0.1
- nParts=StrBufNum_tokens(LocaleString,',');
- for (i=0; ((i<nParts)&&(i<SEARCH_LANG)); i++)
+ nParts = StrBufNum_tokens(LocaleString, ',');
+ for (i=0; ((i<nParts) && (i < SEARCH_LANG)); i++)
- StrBufExtract_token(Buf,LocaleString, i,',');
- /** we are searching, if this list item has something like ;q=n*/
- if (StrBufNum_tokens(Buf,'=')>1) {
+ StrBufExtract_token(Buf, LocaleString, i, ',');
+ /* we are searching, if this list item has something like ;q=n*/
+ if (StrBufNum_tokens(Buf, '=') > 1) {
- StrBufExtract_token(SBuf,Buf, 1,'=');
- sbuflen=StrLength(SBuf);
- for (k=0; k<sbuflen; k++)
- if (ChrPtr(SBuf)[k]=='.')
+ StrBufExtract_token(SBuf, Buf, 1, '=');
+ sbuflen = StrLength(SBuf);
+ for (k = 0; k < sbuflen; k++) {
+ if (ChrPtr(SBuf)[k] == '.') {
StrBufPeek(SBuf, NULL, k, '0');
StrBufPeek(SBuf, NULL, k, '0');
- /** get the locale part */
- StrBufExtract_token(SBuf ,Buf, 0, ';');
- /** get the lang part, which should be allways there */
- extract_token(&ls->lang[0], ChrPtr(SBuf), 0, '-', 16);
- /** get the area code if any. */
- if (StrBufNum_tokens(SBuf,'-') > 1) {
- extract_token(&ls->region[0],ChrPtr(SBuf),1,'-',16);
+
+ /* get the locale part */
+ StrBufExtract_token(SBuf, Buf, 0, ';');
+
+ /* get the lang part, which should be allways there */
+ extract_token(&ls->lang[0],
+ ChrPtr(SBuf),
+ 0, '-',
+ sizeof(ls->lang));
+
+ /* get the area code if any. */
+ if (StrBufNum_tokens(SBuf, '-') > 1) {
+ extract_token(&ls->region[0],
+ ChrPtr(SBuf),
+ 1, '-',
+ sizeof(ls->region)
+ );
- memcpy(&ls->region[0], ls->lang,blen);
- ls->region[blen]='\0';
- } /** area codes are uppercase */
- blen=strlen(&ls->region[0]);
- for (j=0; j<blen; j++)
+ memcpy(&ls->region[0], ls->lang, blen);
+ ls->region[blen] = '\0';
+ }
+
+ /* area codes are uppercase */
+ blen = strlen(&ls->region[0]);
+ for (j = 0; j < blen; j++)
- /** match against the LANG part */
- result=strcasecmp(&ls->lang[0], AvailLangLoaded[j]);
- if ((result<0)&&(result<ls->availability)){
- ls->availability=result;
- ls->selectedlang=j;
+ /* match against the LANG part */
+ result = strcasecmp(&ls->lang[0], AvailLangLoaded[j]);
+ if ((result < 0) && (result < ls->availability)){
+ ls->availability = result;
+ ls->selectedlang = j;
- /** match against lang and locale */
- if (0==strcasecmp(&lbuf[0], AvailLangLoaded[j])){
- ls->availability=0;
- ls->selectedlang=j;
- j=nLocalesLoaded;
+ /* match against lang and locale */
+ if (0 == strcasecmp(&lbuf[0], AvailLangLoaded[j])){
+ ls->availability = 0;
+ ls->selectedlang = j;
+ j = nLocalesLoaded;
- prio=0;
- av=-1000;
- nBest=-1;
- for (i=0; ((i<nParts)&&(i<SEARCH_LANG)); i++) {
- ls=&wanted_locales[i];
- if ((ls->availability<=0)&&
- (av<ls->availability)&&
- (prio<ls->priority)&&
- (ls->selectedlang!=-1)) {
- nBest=ls->selectedlang;
- av=ls->availability;
- prio=ls->priority;
+ prio = 0;
+ av = -1000;
+ nBest = -1;
+ for (i = 0; ((i < nParts) && (i<SEARCH_LANG)); i++) {
+ ls = &wanted_locales[i];
+ if ( (ls->availability <= 0)
+ && (av < ls->availability)
+ && (prio < ls->priority)
+ && (ls->selectedlang != -1)
+ ) {
+ nBest = ls->selectedlang;
+ av = ls->availability;
+ prio = ls->priority;
- sess->selected_language=nBest;
- lprintf(9, "language found: %s\n", AvailLangLoaded[WC->selected_language]);
+ sess->selected_language = nBest;
+ syslog(9, "language found: %s", AvailLangLoaded[WC->selected_language]);
for (i=0; i < nLocalesLoaded; ++i) {
#ifndef HAVE_USELOCALE
if (strcmp(AvailLangLoaded[i], Lang) == 0)
#endif
for (i=0; i < nLocalesLoaded; ++i) {
#ifndef HAVE_USELOCALE
if (strcmp(AvailLangLoaded[i], Lang) == 0)
#endif
if (!strcasecmp(lang, AvailLangLoaded[i])) {
WC->selected_language = i;
if (!strcasecmp(lang, AvailLangLoaded[i])) {
WC->selected_language = i;
- uselocale(wc_locales[WCC->selected_language]); /** switch locales */
- textdomain(textdomain(NULL)); /** clear the cache */
+ uselocale(wc_locales[WCC->selected_language]); /* switch locales */
+ textdomain(textdomain(NULL)); /* clear the cache */
- uselocale(LC_GLOBAL_LOCALE); /** switch locales */
- textdomain(textdomain(NULL)); /** clear the cache */
+ uselocale(LC_GLOBAL_LOCALE); /* switch locales */
+ textdomain(textdomain(NULL)); /* clear the cache */
+#ifdef ENABLE_NLS
+ setlocale(LC_ALL, "");
+ syslog(9, "Text domain: %s", textdomain("webcit"));
+ syslog(9, "Message catalog directory: %s", bindtextdomain(textdomain(NULL), LOCALEDIR));
+ syslog(9, "Text domain Charset: %s", bind_textdomain_codeset("webcit","UTF8"));
+#endif
language = getenv("WEBCIT_LANG");
if ((language) && (!IsEmptyStr(language)) && (strcmp(language, "UNLIMITED") != 0)) {
language = getenv("WEBCIT_LANG");
if ((language) && (!IsEmptyStr(language)) && (strcmp(language, "UNLIMITED") != 0)) {
for (i = 0; i < nLocales; ++i) {
if ((language != NULL) && (strcmp(AvailLang[i], language) != 0))
continue;
for (i = 0; i < nLocales; ++i) {
if ((language != NULL) && (strcmp(AvailLang[i], language) != 0))
continue;
(((i > 0) && (wc_locales[0] != NULL)) ? wc_locales[0] : Empty_Locale)
);
if (wc_locales[nLocalesLoaded] == NULL) {
(((i > 0) && (wc_locales[0] != NULL)) ? wc_locales[0] : Empty_Locale)
);
if (wc_locales[nLocalesLoaded] == NULL) {
- lprintf(1, "Error configuring locale for "LOCALEDIR"locale/%s: %s\n",
+ syslog(1, "locale for %s disabled: %s (domain: %s, path: %s)",
- 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", language);
#ifdef HAVE_USELOCALE
wc_locales[0] = newlocale(
(LC_MESSAGES_MASK|LC_TIME_MASK),
AvailLang[0],
#ifdef HAVE_USELOCALE
wc_locales[0] = newlocale(
(LC_MESSAGES_MASK|LC_TIME_MASK),
AvailLang[0],
#else
setlocale(LC_MESSAGES, AvailLang[0]);
setenv("LANG", AvailLang[0], 1);
#else
setlocale(LC_MESSAGES, AvailLang[0]);
setenv("LANG", AvailLang[0], 1);
-#ifndef HAVE_USELOCALE
-
-
-#endif
-
-#ifdef ENABLE_NLS
- 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"));
-
-#endif
- RegisterNamespace("LANG:SELECT", 0, 0, tmplput_offer_languages, CTX_NONE);
+
+ RegisterHeaderHandler(HKEY("ACCEPT-LANGUAGE"),
+ Header_HandleAcceptLanguage);
+
+ RegisterNamespace("LANG:SELECT", 0, 0,
+ tmplput_offer_languages, NULL, CTX_NONE);
- OneHttpHeader *vLine = NULL;
-
- if ( (sess->Hdr->HTTPHeaders != NULL)
- && GetHash(sess->Hdr->HTTPHeaders, HKEY("ACCEPT-LANGUAGE"), (void *)&vLine)
- && (vLine != NULL)
- && (vLine->Val != NULL)
+ if ( (sess != NULL)
+ && (!sess->Hdr->HR.Static)
+ && (sess->Hdr->HR.browser_language != NULL)