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

Поиск
Список
Период
Сортировка
От Jeff Davis
Тема Re: NLS: use gettext() to translate system error messages
Дата
Msg-id fb71dda983b28a6787d142d66704f1ee9429aaae.camel@j-davis.com
обсуждение исходный текст
Ответ на Re: NLS: use gettext() to translate system error messages  (Jeff Davis <pgsql@j-davis.com>)
Список 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 по дате отправления: