X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fgettext.c;h=1bc40c8f40a5dbe18f08331d85dd8a8ccf46578f;hb=HEAD;hp=71ede4e0ad2083f58f66a6ae57307d78f6f34758;hpb=898bab06ba7d6cf04a9b5e41bfcc6319ff3bb8de;p=citadel.git diff --git a/webcit/gettext.c b/webcit/gettext.c index 71ede4e0a..8c749cb27 100644 --- a/webcit/gettext.c +++ b/webcit/gettext.c @@ -11,13 +11,14 @@ */ #include "webcit.h" -#include "webserver.h" + #define SEARCH_LANG 20 /* how many langs should we parse? */ -#ifdef HAVE_USELOCALE +#ifdef ENABLE_NLS /* actual supported locales */ const char *AvailLang[] = { - "C", + "en_US", + "ar_AE", "bg_BG", "cs_CZ", "en_US", @@ -31,7 +32,9 @@ const char *AvailLang[] = { "fr_FR", "hu_HU", "it_IT", + "ko_KO", "nl_NL", + "pl_PL", "pt_BR", "ru_RU", "zh_CN", @@ -46,10 +49,12 @@ const char *AvailLang[] = { const char **AvailLangLoaded; long nLocalesLoaded = 0; +#ifdef HAVE_USELOCALE locale_t *wc_locales; /* here we keep the parsed stuff */ +#endif /* Keep information about one locale */ -typedef struct _lang_pref{ +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 */ @@ -73,6 +78,7 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess) LangStruct wanted_locales[SEARCH_LANG]; LangStruct *ls; + long len; int i = 0; int j = 0; /* size_t len = strlen(LocaleString); */ @@ -121,22 +127,22 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess) StrBufExtract_token(SBuf, Buf, 0, ';'); /* get the lang part, which should be allways there */ - extract_token(&ls->lang[0], + extract_token(ls->lang, ChrPtr(SBuf), 0, '-', sizeof(ls->lang)); /* get the area code if any. */ if (StrBufNum_tokens(SBuf, '-') > 1) { - extract_token(&ls->region[0], + extract_token(ls->region, ChrPtr(SBuf), 1, '-', sizeof(ls->region) ); } else { /* no ara code? use lang code */ - blen=strlen(&ls->lang[0]); - memcpy(&ls->region[0], ls->lang, blen); + blen = strlen(ls->lang); + memcpy(ls->region, ls->lang, blen); ls->region[blen] = '\0'; } @@ -148,25 +154,26 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess) chars = toupper(ls->region[j]); ls->region[j] = (char)chars; /* todo ? */ } - snprintf(&lbuf[0], + snprintf(lbuf, sizeof(lbuf), "%s_%s", - &ls->lang[0], - &ls->region[0]); + ls->lang, + ls->region); /* check if we have this lang */ ls->availability = 1; ls->selectedlang = -1; + len = strlen(ls->lang); for (j = 0; j < nLocalesLoaded; j++) { int result; /* match against the LANG part */ - result = strcasecmp(&ls->lang[0], AvailLangLoaded[j]); - if ((result < 0) && (result < ls->availability)){ + result = strncasecmp(ls->lang, AvailLangLoaded[j], len); + if ((result == 0) && (result < ls->availability)){ ls->availability = result; ls->selectedlang = j; } /* match against lang and locale */ - if (0 == strcasecmp(&lbuf[0], AvailLangLoaded[j])){ + if (0 == strcasecmp(lbuf, AvailLangLoaded[j])){ ls->availability = 0; ls->selectedlang = j; j = nLocalesLoaded; @@ -194,7 +201,7 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess) nBest=0; } sess->selected_language = nBest; - syslog(9, "language found: %s", AvailLangLoaded[WC->selected_language]); + syslog(LOG_DEBUG, "language found: %s", AvailLangLoaded[sess->selected_language]); FreeStrBuf(&Buf); FreeStrBuf(&SBuf); } @@ -208,10 +215,24 @@ 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("