Re: NLS: use gettext() to translate system error messages - Mailing list pgsql-hackers

From Jeff Davis
Subject Re: NLS: use gettext() to translate system error messages
Date
Msg-id fb71dda983b28a6787d142d66704f1ee9429aaae.camel@j-davis.com
Whole thread Raw
In response to Re: NLS: use gettext() to translate system error messages  (Jeff Davis <pgsql@j-davis.com>)
List pgsql-hackers
On Fri, 2025-12-26 at 11:32 -0800, Jeff Davis wrote:
> Isn't LC_MESSAGES also necessary for gettext()?
>
> If it's only strerror() we care about, then we could use uselocale()
> instead, because the platforms that don't support uselocale() also
> don't seem to do translation in strerror(). (I think only glibc
> translates through strerror(), though I've seen hints that Solaris
> may
> also.)

There seems to be no thread-safe way on NetBSD to use gettext() with a
specific LC_MESSAGES setting, which is unfortunate -- except maybe
wrapping it in a mutex and using setlocale().

I'll briefly summarize the constraints (as far as I can tell), which
may be useful if we are considering changes in this area:

* Windows and NetBSD don't support uselocale(); other platforms do
(though maybe not older versions?).
  - Windows supports _configthreadlocale(_ENABLE_PER_THREAD_LOCALE)
  - On NetBSD, I think the only thread-safe option is to wrap the
    function in a mutex and setlocale().

* strerror() on glibc (and maybe one or two other implementations?)
cares about LC_CTYPE and LC_MESSAGES, but on other platforms it just
returns ASCII. strerror_l() is supported on most platforms, but not
windows. Translation is done regardless of NLS, but dependent on the
libc implementation and installed packages.

* gettext() cares about LC_MESSAGES but not LC_CTYPE (the encoding is
specified separately). Translation is done iff compiled with NLS.

Regards,
    Jeff Davis




pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Remaining dependency on setlocale()
Next
From: Manni Wood
Date:
Subject: Re: Speed up COPY FROM text/CSV parsing using SIMD