Set all locale categories
Hrvoje Niksic <[email protected]> Mon, 27 Jun 2005 04:06:40 +0200
| Newsgroups | gmane.comp.web.wget.patches |
|---|---|
| Message-ID | <[email protected]> |
This had to be done sooner or later, so might as well do it now -- too many people have complained about "incomplete localization". Now the numeric and date values, etc., will be printed in accordance with the locale. 2005-06-27 Hrvoje Niksic <[email protected]> * main.c (i18n_initialize): Set all locale categories. * http.c (http_atotm): Temporarily set locale to "C". Index: src/http.c =================================================================== --- src/http.c (revision 1850) +++ src/http.c (working copy) @@ -38,6 +38,7 @@ #include <assert.h> #include <errno.h> #include <time.h> +#include <locale.h> #include "wget.h" #include "utils.h" @@ -2635,8 +2636,15 @@ (used in Set-Cookie, defined in the Netscape cookie specification.) */ }; + const char *oldlocale; int i; + time_t ret = (time_t) -1; + /* Solaris strptime fails to recognize English month names in + non-English locales, which we work around by temporarily setting + locale to C before invoking strptime. */ + oldlocale = setlocale (LC_TIME, "C"); + for (i = 0; i < countof (time_formats); i++) { struct tm t; @@ -2646,19 +2654,18 @@ to prevent garbage from the stack influencing strptime. */ xzero (t); - /* Solaris strptime fails to recognize English month names in - non-English locales, which we work around by not setting the - LC_TIME category. Another way would be to temporarily set - locale to C before invoking strptime, but that's slow and - messy. GNU strptime does not have this problem because it - recognizes English month names along with the local ones. */ - if (check_end (strptime (time_string, time_formats[i], &t))) - return mktime_from_utc (&t); + { + ret = mktime_from_utc (&t); + break; + } } + /* Restore the previous locale. */ + setlocale (LC_TIME, oldlocale); + /* All formats have failed. */ - return -1; + return ret; } /* Authorization support: We support three authorization schemes: Index: src/main.c =================================================================== --- src/main.c (revision 1832) +++ src/main.c (working copy) @@ -79,20 +79,7 @@ /* HAVE_NLS implies existence of functions invoked here. */ #ifdef HAVE_NLS /* Set the current locale. */ - /* Where possible, sets only LC_MESSAGES and LC_CTYPE. Other - categories, such as numeric, time, or collation, break code that - parses data received from the network and relies on C-locale - behavior of libc functions. For example, Solaris strptime fails - to recognize English month names in non-English locales, which - breaks http_atotm. Some implementations of fnmatch perform - unwanted case folding in non-C locales. ctype macros, while they - were used, provided another example against LC_ALL. */ -#if defined(LC_MESSAGES) && defined(LC_CTYPE) - setlocale (LC_MESSAGES, ""); - setlocale (LC_CTYPE, ""); /* safe because we use safe-ctype */ -#else setlocale (LC_ALL, ""); -#endif /* Set the text message domain. */ bindtextdomain ("wget", LOCALEDIR); textdomain ("wget");