X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fgettext.c;h=1402983c01865e0e15c9b80eec1cf7403df65de6;hb=47bcaaabae789a2f20de958b84714ff2e23dc5bb;hp=f044ab6ac9ac9f619f4baeee22797f2ed969c090;hpb=f4cdbd3692e2e04c711cfa1cb11d3a6dace2061f;p=citadel.git diff --git a/webcit/gettext.c b/webcit/gettext.c index f044ab6ac..1402983c0 100644 --- a/webcit/gettext.c +++ b/webcit/gettext.c @@ -11,7 +11,7 @@ #define SEARCH_LANG 20 /* how many langs should we parse? */ /* actual supported locales */ -char *AvailLang[NUM_LANGS] = { +const char *AvailLang[NUM_LANGS] = { "C", "en_US", "de_DE", @@ -24,6 +24,9 @@ char *AvailLang[NUM_LANGS] = { "pt_BR" }; +const char *AvailLangLoaded[NUM_LANGS]; +long nLocalesLoaded = 0; + #ifdef HAVE_USELOCALE locale_t wc_locales[NUM_LANGS]; /**< here we keep the parsed stuff */ #endif @@ -48,7 +51,7 @@ typedef struct _lang_pref{ * \param LocaleString the string from the browser http headers */ -void httplang_to_locale(char *LocaleString) +void httplang_to_locale(StrBuf *LocaleString) { LangStruct wanted_locales[SEARCH_LANG]; LangStruct *ls; @@ -60,70 +63,79 @@ void httplang_to_locale(char *LocaleString) int av; int nBest; int nParts; - char search[1024]; + StrBuf *Buf = NULL; + StrBuf *SBuf; - safestrncpy(search, LocaleString, sizeof search); - nParts=num_tokens(search,','); + nParts=StrBufNum_tokens(LocaleString,','); for (i=0; ((ipriority=atol(&sbuf[0]); - } - else { - ls->priority=1000; - } - /** get the locale part */ - extract_token(&sbuf[0],&buf[0],0,';',16); - /** get the lang part, which should be allways there */ - extract_token(&ls->lang[0],&sbuf[0],0,'-',16); - /** get the area code if any. */ - if (num_tokens(&sbuf[0],'-')>1) { - extract_token(&ls->region[0],&sbuf[0],1,'-',16); - } - else { /** no ara code? use lang code */ - blen=strlen(&ls->lang[0]); - memcpy(&ls->region[0], ls->lang,blen); - ls->region[blen]='\0'; - } /** area codes are uppercase */ - blen=strlen(&ls->region[0]); - for (j=0; jregion[j]); - ls->region[j]=(char)chars;/** \todo ?! */ - } - sprintf(&lbuf[0],"%s_%s",&ls->lang[0],&ls->region[0]); + if (Buf == NULL) { + Buf = NewStrBuf(); + SBuf = NewStrBuf(); + } + else { + FlushStrBuf(Buf); + FlushStrBuf(SBuf); + } + + ls=&wanted_locales[i]; + + StrBufExtract_token(Buf,LocaleString, i,','); + /** 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; kpriority=StrTol(SBuf); + } + else { + ls->priority=1000; + } + /** 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); + } + else { /** no ara code? use lang code */ + blen=strlen(&ls->lang[0]); + memcpy(&ls->region[0], ls->lang,blen); + ls->region[blen]='\0'; + } /** area codes are uppercase */ + blen=strlen(&ls->region[0]); + for (j=0; jregion[j]); + ls->region[j]=(char)chars;/** \todo ?! */ + } + sprintf(&lbuf[0],"%s_%s",&ls->lang[0],&ls->region[0]); - /** check if we have this lang */ - ls->availability=1; - ls->selectedlang=-1; - for (j=0; jlang[0], AvailLang[j]); - if ((result<0)&&(resultavailability)){ - ls->availability=result; - ls->selectedlang=j; - } - /** match against lang and locale */ - if (0==strcasecmp(&lbuf[0], AvailLang[j])){ - ls->availability=0; - ls->selectedlang=j; - j=NUM_LANGS; - } + /** check if we have this lang */ + ls->availability=1; + ls->selectedlang=-1; + for (j=0; jlang[0], AvailLangLoaded[j]); + if ((result<0)&&(resultavailability)){ + 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; + } + } } prio=0; @@ -145,7 +157,9 @@ void httplang_to_locale(char *LocaleString) nBest=0; } WC->selected_language=nBest; - lprintf(9, "language found: %s\n", AvailLang[WC->selected_language]); + lprintf(9, "language found: %s\n", AvailLangLoaded[WC->selected_language]); + FreeStrBuf(&Buf); + FreeStrBuf(&SBuf); } /* TODO: we skip the language weighting so far. */ @@ -191,7 +205,7 @@ void httplang_to_locale(char *LocaleString) * depending on the browser locale change the sequence of the * language chooser. */ -void offer_languages(void) { +void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { int i; #ifndef HAVE_USELOCALE char *Lang = getenv("LANG"); @@ -202,14 +216,14 @@ void offer_languages(void) { wprintf("