From 898bab06ba7d6cf04a9b5e41bfcc6319ff3bb8de Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 21 Feb 2012 19:20:26 -0500 Subject: [PATCH] Remove ENABLE_NLS definition. Either we HAVE_USELOCALE or we don't translate at all. --- webcit/configure.ac | 10 +------ webcit/fmt_date.c | 4 --- webcit/gettext.c | 69 +++++++++++++-------------------------------- webcit/setup.c | 27 ++++++------------ webcit/webcit.h | 2 +- 5 files changed, 30 insertions(+), 82 deletions(-) diff --git a/webcit/configure.ac b/webcit/configure.ac index 6f3a7bc77..4ce75792b 100644 --- a/webcit/configure.ac +++ b/webcit/configure.ac @@ -400,11 +400,6 @@ AC_ARG_WITH(ssldir, ) AC_DEFINE_UNQUOTED(SSL_DIR, "$ssl_dir", [were should we put our keys?]) - - - -AC_CHECK_FUNCS(strftime_l uselocale gettext) - if test "$ok_nls" != "no"; then AC_CHECK_PROG(ok_xgettext, xgettext, yes, no) ok_nls=$ok_xgettext @@ -421,11 +416,8 @@ if test "$ok_nls" != "no"; then fi if test "$ok_nls" != "no"; then - AC_MSG_RESULT(WebCit will be built with national language support.) - AC_DEFINE(ENABLE_NLS, [], [whether we have NLS support]) + AC_CHECK_FUNCS(strftime_l uselocale gettext) PROG_SUBDIRS="$PROG_SUBDIRS po/webcit/" -else - AC_MSG_RESULT(WebCit will be built without national language support.) fi AC_SUBST(SETUP_LIBS) diff --git a/webcit/fmt_date.c b/webcit/fmt_date.c index 15e5673ca..7979ecf58 100644 --- a/webcit/fmt_date.c +++ b/webcit/fmt_date.c @@ -40,7 +40,6 @@ typedef unsigned char byte; size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm) { -#ifdef ENABLE_NLS #ifdef HAVE_USELOCALE if (wc_locales[WC->selected_language] == NULL) { return strftime(s, max, format, tm); @@ -51,9 +50,6 @@ size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm) #else return strftime(s, max, format, tm); #endif -#else - return strftime(s, max, format, tm); -#endif } diff --git a/webcit/gettext.c b/webcit/gettext.c index 4df641a28..71ede4e0a 100644 --- a/webcit/gettext.c +++ b/webcit/gettext.c @@ -14,7 +14,7 @@ #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", @@ -46,9 +46,7 @@ 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{ @@ -209,7 +207,6 @@ void httplang_to_locale(StrBuf *LocaleString, wcsession *sess) */ void tmplput_offer_languages(StrBuf *Target, WCTemplputParams *TP) { -#ifdef HAVE_USELOCALE int i; wc_printf("\n"); -#else - wc_printf("%s", (getenv("LANG") ? getenv("LANG") : "C")); -#endif } /* * Set the selected language for this session. */ void set_selected_language(const char *lang) { -#ifdef HAVE_USELOCALE int i; for (i = 0; iselected_language < 0) return; uselocale(wc_locales[WCC->selected_language]); /* switch locales */ textdomain(textdomain(NULL)); /* clear the cache */ -#else - char *language; - - language = getenv("LANG"); - setlocale(LC_MESSAGES, language); -#endif } /* * Deactivate the selected language for this session. */ void stop_selected_language(void) { -#ifdef HAVE_USELOCALE uselocale(LC_GLOBAL_LOCALE); /* switch locales */ textdomain(textdomain(NULL)); /* clear the cache */ -#endif } @@ -279,12 +262,10 @@ void initialize_locales(void) { int i; char *language = NULL; -#ifdef ENABLE_NLS setlocale(LC_ALL, ""); syslog(9, "Text domain: %s", textdomain("webcit")); syslog(9, "Message catalog directory: %s", bindtextdomain(textdomain(NULL), LOCALEDIR"/locale")); syslog(9, "Text domain Charset: %s", bind_textdomain_codeset("webcit","UTF8")); -#endif nLocales = 0; while (!IsEmptyStr(AvailLang[nLocales])) @@ -298,14 +279,11 @@ void initialize_locales(void) { AvailLangLoaded = malloc (sizeof(char*) * nLocales); memset(AvailLangLoaded, 0, sizeof(char*) * nLocales); -#ifdef HAVE_USELOCALE wc_locales = malloc (sizeof(locale_t) * nLocales); memset(wc_locales,0, sizeof(locale_t) * nLocales); wc_locales[0] = newlocale(LC_ALL_MASK, NULL, NULL); -#endif for (i = 1; i < nLocales; ++i) { -#ifdef HAVE_USELOCALE wc_locales[nLocalesLoaded] = newlocale( (LC_MESSAGES_MASK|LC_TIME_MASK), AvailLang[i], @@ -324,26 +302,11 @@ void initialize_locales(void) { AvailLangLoaded[nLocalesLoaded] = AvailLang[i]; nLocalesLoaded++; } -#else - if ((language != NULL) && (strcmp(language, AvailLang[i]) == 0)) { - setenv("LANG", AvailLang[i], 1); - AvailLangLoaded[nLocalesLoaded] = AvailLang[i]; - setlocale(LC_MESSAGES, AvailLang[i]); - nLocalesLoaded++; - } - else if (nLocalesLoaded == 0) { - setenv("LANG", AvailLang[i], 1); - AvailLangLoaded[nLocalesLoaded] = AvailLang[i]; - nLocalesLoaded++; - } -#endif } if ((language != NULL) && (nLocalesLoaded == 0)) { syslog(1, "Your selected locale [%s] isn't available on your system. falling back to C", language); -#ifndef HAVE_USELOCALE setlocale(LC_MESSAGES, AvailLang[0]); setenv("LANG", AvailLang[0], 1); -#endif AvailLangLoaded[0] = AvailLang[0]; nLocalesLoaded = 1; } @@ -354,17 +317,15 @@ void ServerShutdownModule_GETTEXT (void) { -#ifdef HAVE_USELOCALE int i; for (i = 0; i < nLocalesLoaded; ++i) { freelocale(wc_locales[i]); } free(wc_locales); -#endif free(AvailLangLoaded); } -#else /* ENABLE_NLS */ +#else /* HAVE_USELOCALE */ const char *AvailLang[] = { "C", "" @@ -388,10 +349,24 @@ void go_selected_language(void) { void stop_selected_language(void) { } +/* dummy for non NLS enabled systems */ void initialize_locales(void) { } -#endif /* ENABLE_NLS */ +/* dummy for non NLS enabled systems */ +void +ServerShutdownModule_GETTEXT +(void) +{ +} + + +#endif /* HAVE_USELOCALE */ + + + + + void TmplGettext(StrBuf *Target, WCTemplputParams *TP) @@ -405,15 +380,11 @@ void TmplGettext(StrBuf *Target, WCTemplputParams *TP) * This function returns a static string, so don't do anything stupid please. */ const char *get_selected_language(void) { -#ifdef ENABLE_NLS #ifdef HAVE_USELOCALE return AvailLang[WC->selected_language]; #else return "en"; #endif -#else - return "en"; -#endif } @@ -441,7 +412,7 @@ void SessionNewModule_GETTEXT (wcsession *sess) { -#ifdef ENABLE_NLS +#ifdef HAVE_USELOCALE if ( (sess != NULL) && (!sess->Hdr->HR.Static) && (sess->Hdr->HR.browser_language != NULL) @@ -455,7 +426,7 @@ void SessionAttachModule_GETTEXT (wcsession *sess) { -#ifdef ENABLE_NLS +#ifdef HAVE_USELOCALE go_selected_language(); /* set locale */ #endif } @@ -464,7 +435,7 @@ void SessionDestroyModule_GETTEXT (wcsession *sess) { -#ifdef ENABLE_NLS +#ifdef HAVE_USELOCALE stop_selected_language(); /* unset locale */ #endif } diff --git a/webcit/setup.c b/webcit/setup.c index cfb215eb7..f4653dcac 100644 --- a/webcit/setup.c +++ b/webcit/setup.c @@ -31,15 +31,10 @@ void RegisterNS(const char *NSName, long len, void RegisterHeaderHandler(const char *Name, long Len, Header_Evaluator F){} pthread_key_t MyConKey; -#ifdef ENABLE_NLS - #ifdef HAVE_USELOCALE int localeoffset = 1; -#else -int localeoffset = 0; #endif -#endif /* * Delete an entry from /etc/inittab */ @@ -411,7 +406,7 @@ void progress(char *text, long int curr, long int cmax) */ void install_init_scripts(void) { -#ifdef ENABLE_NLS +#ifdef HAVE_USELOCALE int localechoice; #endif char question[1024]; @@ -446,10 +441,8 @@ void install_init_scripts(void) return; -#ifdef ENABLE_NLS - +#ifdef HAVE_USELOCALE localechoice = GetLocalePrefs(); - #endif /* Defaults */ sprintf(http_port, "2000"); @@ -555,22 +548,18 @@ void install_init_scripts(void) fprintf(fp, "CTDL_HOSTNAME=%s\n", hostname); fprintf(fp, "CTDL_PORTNAME=%s\n", portname); -#ifdef ENABLE_NLS - - if (localechoice == 0) { #ifdef HAVE_USELOCALE - fprintf(fp, "unset LANG\n"); -#else - fprintf(fp, "export WEBCIT_LANG=c\n"); -#endif - } - else { + if (localechoice == 0) { fprintf(fp, "export WEBCIT_LANG=%s\n", AvailLang[localechoice - localeoffset]); - } #else fprintf(fp, "# your system doesn't support locales\n"); #endif + + + + + fprintf(fp, "\n" "\n" "case \"$1\" in\n" diff --git a/webcit/webcit.h b/webcit/webcit.h index e713e75bb..67131a5eb 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -53,7 +53,7 @@ #include #endif -#ifdef ENABLE_NLS +#ifdef HAVE_USELOCALE #ifdef HAVE_XLOCALE_H #include #endif -- 2.30.2