Localized strftime() output 
Author Message
 Localized strftime() output

Hi,

I've been using gawk for some years now, but apparently until now it
didn't come to my attention that its strftime() output is not localized:

% locale
LANG=de_DE.ISO-8859-15
LC_CTYPE=de_DE
LC_NUMERIC="de_DE.ISO-8859-15"
LC_TIME="de_DE.ISO-8859-15"
LC_COLLATE=C
LC_MONETARY="de_DE.ISO-8859-15"
LC_MESSAGES="de_DE.ISO-8859-15"
LC_ALL=
% gawk  'BEGIN{ print strftime("%A, %e. %B, %Y") }'
Thursday, 27. February, 2003

I ran that little test with several gawk versions (3.0.3 .. 3.1.1l) on
Linux systems with glibc-2.1.3 and glibc-2.3.1; same results everywhere.

I now wonder why gawk doesn't use setlocale(LC_TIME,""), while it does
use several other setlocale() calls in main.c. Probably this was on
purpose, e.g. because too many existing scripts rely on English-only
strftime() output?

Regards...
                Michael



Tue, 16 Aug 2005 06:44:14 GMT  
 Localized strftime() output

Quote:

>Hi,

>I've been using gawk for some years now, but apparently until now it
>didn't come to my attention that its strftime() output is not localized:

> [......]

>I now wonder why gawk doesn't use setlocale(LC_TIME,""), while it does
>use several other setlocale() calls in main.c. Probably this was on
>purpose, e.g. because too many existing scripts rely on English-only
>strftime() output?

No, not on purpose.  Until 3.1.1, the supplied strftime didn't do locales,
which would be an issue on systems without strftime in the library. Since
such systems probably don't have locales, it wouldn't matter there.

With 3.1.1, the supplied strftime is from glibc, and it's used only on systems
that don't have it, or if requested at configure time.  The question then
becomes, shouldn't the C library be paying attention to the environment
variable? Or does the code have to explicitly request it via

        set_locale(LC_TIME, "");

(I'm showing the combination of my ignorance and my American parochialism
here. :-).  It sounds like the latter is the case.  I'll fix it for
the upcoming release.

Thanks,

Arnold
--

P.O. Box 354            Home Phone: +972  8 979-0381    Fax: +1 928 569 9018
Nof Ayalon              Cell Phone: +972 51  297-545
D.N. Shimshon 99785     ISRAEL



Tue, 16 Aug 2005 16:58:48 GMT  
 Localized strftime() output
On Fri, 28 Feb 2003 08:58:48 GMT in comp.lang.awk,

Quote:



>>Hi,

>>I've been using gawk for some years now, but apparently until now it
>>didn't come to my attention that its strftime() output is not localized:

>> [......]

>>I now wonder why gawk doesn't use setlocale(LC_TIME,""), while it does
>>use several other setlocale() calls in main.c. Probably this was on
>>purpose, e.g. because too many existing scripts rely on English-only
>>strftime() output?

>No, not on purpose.  Until 3.1.1, the supplied strftime didn't do locales,
>which would be an issue on systems without strftime in the library. Since
>such systems probably don't have locales, it wouldn't matter there.

>With 3.1.1, the supplied strftime is from glibc, and it's used only on systems
>that don't have it, or if requested at configure time.  The question then
>becomes, shouldn't the C library be paying attention to the environment
>variable? Or does the code have to explicitly request it via

>    set_locale(LC_TIME, "");

>(I'm showing the combination of my ignorance and my American parochialism
>here. :-).  It sounds like the latter is the case.  I'll fix it for
>the upcoming release.

IIRC setlocale( LC_ALL, ""); should set any relevant current
locale settings, if supported by the library and there are any to
set (from the environment or equivalent), and your library
routines must then use the entries returned by localeconv() in
struct lconv wherever appropriate.

Thanks. Take care, Brian Inglis         Calgary, Alberta, Canada
--

    fake address                use address above to reply






Wed, 17 Aug 2005 15:35:06 GMT  
 Localized strftime() output

Quote:

> On Fri, 28 Feb 2003 08:58:48 GMT in comp.lang.awk,

>>With 3.1.1, the supplied strftime is from glibc, and it's used only on systems
>>that don't have it, or if requested at configure time.  The question then
>>becomes, shouldn't the C library be paying attention to the environment
>>variable?

The C library does not automatically use the locale settings from the
environment, because then locale-unaware programs would write (and read)
localized strings everywhere, even in program sources. This would lead
to a lot of trouble. For example here we use a comma as decimal "point",
so

  printf("%f", 1,2);

would be "correct" - but obviously real fun for the parser. [1]

Quote:
>> Or does the code have to explicitly request it via

>>       set_locale(LC_TIME, "");

>>(I'm showing the combination of my ignorance and my American parochialism
>>here. :-).  It sounds like the latter is the case.  I'll fix it for
>>the upcoming release.

> IIRC setlocale( LC_ALL, ""); should set any relevant current
> locale settings, if supported by the library and there are any to
> set (from the environment or equivalent),

Yes, with setlocale(LC_ALL, "") all of the locale settings would get
used. But gawk's main.c already has a couple of setlocale() calls, and
it explicitly sets LC_NUMERIC to the normal C locale:

        /*
         * Force the issue here. On some systems, gawk ends up
         * printing output with commas for the decimal point.
         */
        setlocale(LC_NUMERIC, "C");

which is a good thing IMHO.

Quote:
> and your library
> routines must then use the entries returned by localeconv() in
> struct lconv wherever appropriate.

Just using an additional

  setlocale(LC_TIME, "");

is enough in gawk - strftime() then uses the locale set in the
environment.

Thanks...
                Michael

[1]: There are/were already localized programming languages, mostly
coming from Redmond. Based on the locale, the meaning of almost anything
is changed, e.g. if the decimal "point" is a comma, the argument
separator will become a semicolon (and then probably the command
separator a point(?)). Even the names of the builtin functions are
localized, so you'll end up with something like

  druckef("%f"; 1,2).



Wed, 17 Aug 2005 19:49:04 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. strftime() invalid output

2. GAWK: strftime("%z") and portability (which version of strftime is used in compile?)

3. unix time and strftime

4. strftime * date calculations

5. Q: inverse of strftime

6. strftime weirdness

7. strftime year

8. time.strftime BUG?

9. strftime: %Z, timezone, and all that

10. strftime ?

11. strftime and windows

12. bug in time.strftime on linux???

 

 
Powered by phpBB® Forum Software