On Fri, Jun 12, 2015 at 08:59:14AM +0200, Sébastien Marie wrote:
> If this change is desirable, I will propose patchs for programs in base
> in order to call setlocale(LC_ALL, "") at program initilisation.

Calling setlocale() with LC_ALL will have other side effects apart from
messages. I think, for now, we should only call setlocale() in programs
that have been made fully local-aware. For example, calling setlocale()
while not making the application handle multi-byte sequences properly
might not be such a good idea.

Localising error messages is not all that important at present. What's much
more important, for example, is interactive editing of UTF-8 in the shell and
in editors. Before that works, extensive localisation is rather pointless.
Currently, localisation and multibyte only work with tools installed from
ports, with very few exceptions (e.g. tmux and less).

catopen() is an interface which isn't widely used. It seems to be an old relic
of posix. So I don't see much point in extending it. Nowadays, everyone uses
gettext() for localisation instead.  

Whether or not full message localisation of the base system should happen
at all is likely a contentious question :-)

> Index: nls/catopen.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/nls/catopen.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 catopen.c
> --- nls/catopen.c     16 Jan 2015 16:48:51 -0000      1.16
> +++ nls/catopen.c     12 Jun 2015 06:37:22 -0000
> @@ -39,6 +39,7 @@
>  #include <unistd.h>
>  #include <fcntl.h>
>  #include <nl_types.h>
> +#include <locale.h>
>  
>  #define NLS_DEFAULT_PATH 
> "/usr/share/nls/%L/%N.cat:/usr/share/nls/%l.%c/%N.cat:/usr/share/nls/%l/%N.cat"
>  #define NLS_DEFAULT_LANG "C"
> @@ -68,9 +69,7 @@ _catopen(const char *name, int oflag)
>  
>       lang = NULL;
>       if (oflag & NL_CAT_LOCALE) {
> -             lang = getenv("LC_ALL");
> -             if (lang == NULL)
> -                     lang = getenv("LC_MESSAGES");
> +             lang = setlocale(LC_MESSAGES, NULL);

An important question to ask yourself here is:
Is catopen() supposed to be thread-safe? setlocale() is not, so it can't
be called from contexts which are supposed to be thread-safe.

I don't think we should be calling setlocale() in libc at all.
Applications should decide whether setlocale() is called, not libraries.
Libraries can't know if they're in a threaded context, and also the application
itself or other libraries used by the application might not be prepared to
handle side effects of setlocale().

libc's strftime() calls setlocale(). This should be fixed eventually.
I believe it should call some internal thread-safe interface instead,
which we don't have yet.

>       }
>       if (lang == NULL)
>               lang = getenv("LANG");

Reply via email to