Re: NLS: use gettext() to translate system error messages

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: NLS: use gettext() to translate system error messages
Date: 2026-01-06 19:54:29
Message-ID: fb71dda983b28a6787d142d66704f1ee9429aaae.camel@j-davis.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Manni Wood 2026-01-06 20:05:05 Re: Speed up COPY FROM text/CSV parsing using SIMD
Previous Message Peter Eisentraut 2026-01-06 19:54:15 Re: Remaining dependency on setlocale()