From be53a6e60c9a1d46e3797bffc604816324fdf616 Mon Sep 17 00:00:00 2001 From: Bryan Green Date: Tue, 31 Mar 2026 20:14:12 -0500 Subject: [PATCH v1] Fix stale LC_MESSAGES translations after SET on Windows. On Windows, pg_perm_setlocale() skips calling setlocale() for LC_MESSAGES because the MSVC runtime doesn't support that category. Instead it sets the LC_MESSAGES environment variable directly. This means libintl's translation cache (_nl_msg_cat_cntr) is never invalidated, so SET lc_messages at runtime returns stale translations from the previous locale. Fix by calling libintl_setlocale() directly after IsoLocaleName() has produced the POSIX locale name. Author: Bryan Green --- src/backend/utils/adt/pg_locale.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 6c5c1019e1..cea3d1e716 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -237,6 +237,17 @@ pg_perm_setlocale(int category, const char *locale) if (result == NULL) result = (char *) locale; elog(DEBUG3, "IsoLocaleName() executed; locale: \"%s\"", result); + + /* + * Use the libintl_setlocale function provided by libintl so + * it invalidates its translation cache (_nl_msg_cat_cntr) as + * needed. Without this, resetting lc_messages to a different + * locale at runtime returns stale translations from the + * previous locale. + */ +#ifdef ENABLE_NLS + (void) libintl_setlocale(LC_MESSAGES, result); +#endif #endif /* WIN32 */ break; #endif /* LC_MESSAGES */ -- 2.52.0.windows.1