#include "webserver.h"
#ifdef ENABLE_NLS
-
-#define NUM_LANGS 10 /* how many different locales do we know? */
-#define SEARCH_LANG 20 /* how many langs should we parse? */
-
/* actual supported locales */
const char *AvailLang[NUM_LANGS] = {
"C",
* depending on the browser locale change the sequence of the
* language chooser.
*/
-void tmplput_offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) {
+void tmplput_offer_languages(StrBuf *Target, WCTemplputParams *TP)
+{
int i;
#ifndef HAVE_USELOCALE
char *Lang = getenv("LANG");
Lang = "C";
#endif
+
+ if (nLocalesLoaded == 1) {
+ wprintf("<p>%s</p>", AvailLangLoaded[0]);
+ return;
+ }
+
wprintf("<select name=\"language\" id=\"lname\" size=\"1\">\n");
for (i=0; i < nLocalesLoaded; ++i) {
* \param lang the locale to set.
*/
void set_selected_language(const char *lang) {
- int i;
-
#ifdef HAVE_USELOCALE
+ int i;
for (i=0; i<nLocalesLoaded; ++i) {
if (!strcasecmp(lang, AvailLangLoaded[i])) {
WC->selected_language = i;
#endif
}
-void preset_locale(void)
-{
-#ifndef HAVE_USELOCALE
-#ifdef HAVE_GETTEXT
- char *language;
-
- lprintf(9, "Nailing locale to %s\n", getenv("LANG"));
- language = getenv("LANG");
- setlocale(LC_MESSAGES, language);
-#endif
-#endif
-}
-
#ifdef HAVE_USELOCALE
locale_t Empty_Locale;
#endif
void initialize_locales(void) {
int i;
char buf[32];
+ char *language = NULL;
+
+ language = getenv("WEBCIT_LANG");
+ if ((language) && (!IsEmptyStr(language)) && (strcmp(language, "UNLIMITED") != 0)) {
+ lprintf(9, "Nailing locale to %s\n", language);
+ }
+ else language = NULL;
#ifdef HAVE_USELOCALE
/* create default locale */
Empty_Locale = newlocale(LC_ALL_MASK, NULL, NULL);
#endif
+
+
+
for (i = 0; i < NUM_LANGS; ++i) {
+ if ((language != NULL) && (strcmp(AvailLang[i], language) != 0))
+ continue;
if (i == 0) {
sprintf(buf, "%s", AvailLang[i]); /* locale 0 (C) is ascii, not utf-8 */
}
AvailLangLoaded[nLocalesLoaded] = AvailLang[i];
nLocalesLoaded++;
}
+#else
+ if (language != NULL) {
+ setenv("LANG", buf, 1);
+ AvailLangLoaded[nLocalesLoaded] = AvailLang[i];
+ nLocalesLoaded++;
+ }
+ else if (nLocalesLoaded == 0) {
+ setenv("LANG", buf, 1);
+ AvailLangLoaded[nLocalesLoaded] = AvailLang[i];
+ nLocalesLoaded++;
+ }
#endif
}
+ if ((language != NULL) && (nLocalesLoaded == 0)) {
+ lprintf(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),
+ AvailLang[0],
+ Empty_Locale);
+#else
+ setlocale(LC_MESSAGES, AvailLang[0]);
+ setenv("LANG", AvailLang[0], 1);
+#endif
+ AvailLangLoaded[0] = AvailLang[0];
+ nLocalesLoaded = 1;
+ }
+#ifndef HAVE_USELOCALE
+
+
+#endif
+
}
void ShutdownLocale(void)
{
- int i;
#ifdef HAVE_USELOCALE
+ int i;
for (i = 0; i < nLocalesLoaded; ++i) {
if (Empty_Locale != wc_locales[i])
freelocale(wc_locales[i]);
}
#else /* ENABLE_NLS */
+const char *AvailLang[NUM_LANGS] = {
+ "C"};
+
/** \brief dummy for non NLS enabled systems */
-void tmplput_offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) {
+void tmplput_offer_languages(StrBuf *Target, WCTemplputParams *TP)
+{
wprintf("English (US)");
}
void stop_selected_language(void) {
}
-void preset_locale(void)
-{
-}
#endif /* ENABLE_NLS */
-void TmplGettext(StrBuf *Target, int nTokens, WCTemplateToken *Tokens)
+void TmplGettext(StrBuf *Target, WCTemplputParams *TP)
{
- StrBufAppendBufPlain(Target, _(Tokens->Params[0]->Start), -1, 0);
+ StrBufAppendBufPlain(Target, _(TP->Tokens->Params[0]->Start), -1, 0);
}
#ifdef HAVE_USELOCALE
return AvailLang[WC->selected_language];
#else
- return "en"
+ return "en";
#endif
#else
- return "en"
+ return "en";
#endif
}