On 19.11.25 04:15, Tom Lane wrote:
Thomas Munro <[email protected]> writes:
Perhaps meson/configure should do a po -> mo -> gettext() check with a
canned test message? That'd also make sure your msgfmt and libintl
are compatible, something I worried about when I wrote about musl
recently.
No, I don't think that's a good approach. That is testing the library
available at configure time, not the one you are actually running
with (possibly years later and on a different machine, even without
considering cross-compilation cases). I think we should do it
honestly with a regression test. It doesn't need to be very
complicated --- I think checking one message in one translation is
sufficient, so long as it includes a PRI?64 usage.
We could generate an English message catalog that translates all
messages unchanged, and run the whole test suite with that. This would
exercise the whole gettext run-time machinery.
Generating the message catalog is easy, gettext provides a tool for
that. What's a little tricky is convincing all our testing
infrastructure to *not* disable NLS-related locale settings. See
attached for a rough, incomplete demo.
From a4d5f001880d057e8692cfad49abf4a87096a88c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Wed, 19 Nov 2025 10:13:28 +0100
Subject: [PATCH] Create English message catalog for testing
---
src/Makefile.global.in | 2 +-
src/nls-global.mk | 11 ++++++++++-
src/test/regress/pg_regress.c | 3 ++-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 0aa389bc710..63b25cd8db6 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -439,7 +439,7 @@ ifeq ($(MAKELEVEL),0)
$(MAKE) -C '$(top_builddir)' DESTDIR='$(abs_top_builddir)'/tmp_install
install >'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1
$(MAKE) -j1 $(if $(CHECKPREP_TOP),-C $(CHECKPREP_TOP),) checkprep
>>'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1
- $(with_temp_install) initdb --auth trust --no-sync --no-instructions
--lc-messages=C --no-clean '$(abs_top_builddir)'/tmp_install/initdb-template
>>'$(abs_top_builddir)'/tmp_install/log/initdb-template.log 2>&1
+ $(with_temp_install) initdb --auth trust --no-sync --no-instructions
--lc-messages=en_US.UTF-8 --no-clean
'$(abs_top_builddir)'/tmp_install/initdb-template
>>'$(abs_top_builddir)'/tmp_install/log/initdb-template.log 2>&1
endif
endif
endif
diff --git a/src/nls-global.mk b/src/nls-global.mk
index 73a6db10a1d..481a50af701 100644
--- a/src/nls-global.mk
+++ b/src/nls-global.mk
@@ -34,7 +34,7 @@ AVAIL_LANGUAGES := $(shell cat $(srcdir)/po/LINGUAS)
# If user specified the languages he wants in --enable-nls=LANGUAGES,
# filter out the rest. Else use all available ones.
ifdef WANTED_LANGUAGES
-LANGUAGES = $(filter $(WANTED_LANGUAGES), $(AVAIL_LANGUAGES))
+LANGUAGES = $(filter $(WANTED_LANGUAGES), $(AVAIL_LANGUAGES) en)
else
LANGUAGES = $(AVAIL_LANGUAGES)
endif
@@ -51,6 +51,11 @@ ifdef MSGMERGE
MSGMERGE += --no-wrap --previous --sort-by-file
endif
+MSGEN = msgen
+ifdef MSGEN
+MSGEN += --no-wrap --sort-by-file
+endif
+
# _ is defined in c.h, so it's global
GETTEXT_TRIGGERS += _
GETTEXT_FLAGS += _:1:pass-c-format
@@ -90,6 +95,10 @@ FRONTEND_COMMON_GETTEXT_FLAGS = \
all-po: $(MO_FILES)
+po/en.po: po/$(CATALOG_NAME).pot
+ $(MSGEN) --lang=en -o [email protected] $<
+ sed -e '/Plural-Forms:/s/INTEGER/2/' -e '/Plural-Forms:/s/EXPRESSION/(n
!= 1)/' [email protected] > $@
+
%.mo: %.po
$(MSGFMT) $(MSGFMT_FLAGS) -o $@ $<
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index efc41fca2ba..0d32bc44335 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -768,8 +768,9 @@ initialize_environment(void)
* is actually called.)
*/
unsetenv("LANGUAGE");
+ setenv("LANGUAGE", "en", 1);
unsetenv("LC_ALL");
- setenv("LC_MESSAGES", "C", 1);
+ setenv("LC_MESSAGES", "en_US.UTF-8", 1);
/*
* Set encoding as requested
--
2.51.0