GNU bug report logs - #24186
setlocale can't be localised

Previous Next

Package: guile;

Reported by: Zefram <zefram <at> fysh.org>

Date: Mon, 8 Aug 2016 16:33:01 UTC

Severity: normal

Full log


Message #20 received at 24186 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Zefram <zefram <at> fysh.org>
Cc: Andy Wingo <wingo <at> pobox.com>, 24186 <at> debbugs.gnu.org
Subject: Re: bug#24186: setlocale can't be localised
Date: Tue, 11 Oct 2016 10:06:15 +0200
Hi,

Zefram <zefram <at> fysh.org> skribis:

>     (define (call-with-locale cat val body)
>       (let ((oldval #f))
> 	(dynamic-wind
> 	  (lambda () (set! oldval (setlocale cat)) (setlocale cat val))
> 	  body (lambda () (setlocale cat oldval)))))
>
>     (define (day-of-week-string)
>       (strftime "%A" (localtime (current-time)))) 
>
>     (define (day-of-week-string-for-locale loc)
>       (call-with-locale LC_TIME loc day-of-week-string))
>
>     ;; user-locale is application-specific code defined elsewhere
>     (define (day-of-week-string-for-user user)
>       (day-of-week-string-for-locale (user-locale user)))

This does not really answer your question, but (ice-9 i18n) provides
first-class locale objects, which avoid the whole global locale issue
(info "(guile) Internationalization").

Currently important procedures such as ‘strftime’ or SRFI-19’s
‘date->string’ cannot use such locale objects, though.  I think it would
make sense to add an optional locale object argument to ‘srftime’ and
‘date->string’ (though we should create a (srfi srfi-19 gnu) module for
that to make it clear that this is a GNU extension.)

That wouldn’t help with the ‘setlocale’ issue you describe per se, but
this would address such use cases in a different way.

WDYT?

Ludo’.




This bug report was last modified 8 years and 248 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.