X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fgettext.c;h=71ede4e0ad2083f58f66a6ae57307d78f6f34758;hb=898bab06ba7d6cf04a9b5e41bfcc6319ff3bb8de;hp=6a5c3c879d372da862a7b5953900bfa123e7172d;hpb=676ce718728d6618b49505a12b595f4e46109818;p=citadel.git diff --git a/webcit/gettext.c b/webcit/gettext.c index 6a5c3c879..71ede4e0a 100644 --- a/webcit/gettext.c +++ b/webcit/gettext.c @@ -1,26 +1,20 @@ /* - * Copyright (c) 1996-2011 by the citadel.org team + * 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 as - * published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. + * 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. - * - * 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 */ #include "webcit.h" #include "webserver.h" #define SEARCH_LANG 20 /* how many langs should we parse? */ -#ifdef ENABLE_NLS +#ifdef HAVE_USELOCALE /* actual supported locales */ const char *AvailLang[] = { "C", @@ -45,23 +39,22 @@ const char *AvailLang[] = { "kk_KK", "ro_RO", "sl_SL", + "tr_TR", "" }; const char **AvailLangLoaded; long nLocalesLoaded = 0; -#ifdef HAVE_USELOCALE -locale_t *wc_locales; /**< here we keep the parsed stuff */ -#endif +locale_t *wc_locales; /* here we keep the parsed stuff */ /* Keep information about one locale */ typedef struct _lang_pref{ - 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? */ } LangStruct; /* parse browser locale header @@ -108,37 +101,40 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess) ls = &wanted_locales[i]; StrBufExtract_token(Buf, LocaleString, i, ','); - /** we are searching, if this list item has something like ;q=n*/ + /* we are searching, if this list item has something like ;q=n*/ if (StrBufNum_tokens(Buf, '=') > 1) { int sbuflen, k; StrBufExtract_token(SBuf, Buf, 1, '='); sbuflen = StrLength(SBuf); - for (k = 0; k < sbuflen; k++) - if (ChrPtr(SBuf)[k] == '.') + for (k = 0; k < sbuflen; k++) { + if (ChrPtr(SBuf)[k] == '.') { StrBufPeek(SBuf, NULL, k, '0'); + } + } ls->priority = StrTol(SBuf); } else { ls->priority = 1000; } - /** get the locale part */ + /* get the locale part */ StrBufExtract_token(SBuf, Buf, 0, ';'); - /** get the lang part, which should be allways there */ + /* 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. */ + /* get the area code if any. */ if (StrBufNum_tokens(SBuf, '-') > 1) { extract_token(&ls->region[0], ChrPtr(SBuf), 1, '-', - sizeof(ls->region)); + sizeof(ls->region) + ); } - else { /** no ara code? use lang code */ + else { /* no ara code? use lang code */ blen=strlen(&ls->lang[0]); memcpy(&ls->region[0], ls->lang, blen); ls->region[blen] = '\0'; @@ -150,7 +146,7 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess) { int chars; chars = toupper(ls->region[j]); - ls->region[j] = (char)chars;/** \todo ?! */ + ls->region[j] = (char)chars; /* todo ? */ } snprintf(&lbuf[0], sizeof(lbuf), @@ -158,18 +154,18 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess) &ls->lang[0], &ls->region[0]); - /** check if we have this lang */ + /* check if we have this lang */ ls->availability = 1; ls->selectedlang = -1; for (j = 0; j < nLocalesLoaded; j++) { int result; - /** match against the LANG part */ + /* 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 */ + /* match against lang and locale */ if (0 == strcasecmp(&lbuf[0], AvailLangLoaded[j])){ ls->availability = 0; ls->selectedlang = j; @@ -183,25 +179,27 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess) nBest = -1; for (i = 0; ((i < nParts) && (iavailability <= 0) && - (av < ls->availability) && - (prio < ls->priority) && - (ls->selectedlang != -1)) { + if ( (ls->availability <= 0) + && (av < ls->availability) + && (prio < ls->priority) + && (ls->selectedlang != -1) + ) { nBest = ls->selectedlang; av = ls->availability; prio = ls->priority; } } if (nBest == -1) { - /** fall back to C */ + /* fall back to C */ nBest=0; } sess->selected_language = nBest; - syslog(9, "language found: %s\n", AvailLangLoaded[WC->selected_language]); + syslog(9, "language found: %s", AvailLangLoaded[WC->selected_language]); FreeStrBuf(&Buf); FreeStrBuf(&SBuf); } + /* * show the language chooser on the login dialog * depending on the browser locale change the sequence of the @@ -210,25 +208,10 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess) void tmplput_offer_languages(StrBuf *Target, WCTemplputParams *TP) { int i; -#ifndef HAVE_USELOCALE - char *Lang = getenv("LANG"); - - if (Lang == NULL) - Lang = "C"; -#endif - - - if (nLocalesLoaded == 1) { - wc_printf("

%s

", AvailLangLoaded[0]); - return; - } wc_printf("