Configuring messages language on Windows

Started by Nonamealmost 8 years ago3 messages
#1Noname
a.parfenov@postgrespro.ru
1 attachment(s)

Hello hackers,

As it mentioned in pg_locale.c, the variable LC_MESSAGES is ignored in
Windows(pg_locale.c:162). In other systems, this variable is
used to select a messages language. But in Windows, the language is
selected based on system locale and couldn't be changed via
configuration. Additionally, this affects regress tests, since language
for messages generated by psql is also configured via LC_MESSAGES and
ignored on Windows installations and cause failure of tests on
non-English Windows installations.

I've done a little patch to fix that problem via usage of LANGUAGE
variable on Windows systems. To get more information about LC_MESSAGES,
LANGUAGE and other variable used in GNU gettext look at documentation
[1]: https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html
IMHO that patch is more like a workaround and I'm not sure that it is
safe for all combination of systems/compilers. I think we can find a
better way to solve the problem.

Also, there is a problem of mixing encoding in the log in case of
databases with different encoding on one server. I didn't find any good
solution how to work in such a case because each backend should use its
own encoding in order to work with data and client properly. This
problem is not Windows specific, but most of the OS use one Unicode
encoding for all languages (e.g. UTF-8).

The main point of this message is to say about the problem, try to
find an appropriate solution and ask community's opinion about the
problem.

[1]: https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html
https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html

Attachments:

windows-messages-language-bugfix.patchtext/x-diffDownload
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index a3dc3be5a8..2548f6bbd2 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -216,6 +216,11 @@ pg_perm_setlocale(int category, const char *locale)
 			envvar = "LC_MESSAGES";
 			envbuf = lc_messages_envbuf;
 #ifdef WIN32
+			/*
+			 * Use LANGUAGE instead of LC_MESSAGES since Windows doesn't support
+			 * LC_MESSAGES environment variable.
+			 */
+			envvar = "LANGUAGE";
 			result = IsoLocaleName(locale);
 			if (result == NULL)
 				result = (char *) locale;
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index a1ee1041b4..631f31729e 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -760,6 +760,13 @@ initialize_environment(void)
 	unsetenv("LANGUAGE");
 	unsetenv("LC_ALL");
 	putenv("LC_MESSAGES=C");
+#ifdef WIN32
+	/*
+	 * Use LANGUAGE instead of LC_MESSAGES since Windows doesn't support
+	 * LC_MESSAGES environment variable.
+	 */
+	putenv("LANGUAGE=C");
+#endif
 
 	/*
 	 * Set encoding as requested
#2Noah Misch
noah@leadboat.com
In reply to: Noname (#1)
Re: Configuring messages language on Windows

On Fri, Jan 26, 2018 at 04:54:08PM +0300, a.parfenov@postgrespro.ru wrote:

As it mentioned in pg_locale.c, the variable LC_MESSAGES is ignored in
Windows(pg_locale.c:162).

That comment says "On Windows, setlocale(LC_MESSAGES) does not work". It says
nothing about the LC_MESSAGES environment variable.

Additionally, this affects regress tests, since language
for messages generated by psql is also configured via LC_MESSAGES and
ignored on Windows installations and cause failure of tests on
non-English Windows installations.

I vaguely recall having seen such a problem with an old version of GNU
gettext. On Windows Server 2016, with binaries from
https://get.enterprisedb.com/postgresql/postgresql-11.0-beta3-windows-x64-binaries.zip,
in an account having its Windows display language set to "Espa�ol (Espa�a)", I
get this behavior:

$ for lang in '' it C; do LC_MESSAGES=$lang ./psql.exe --help; done | grep -e --output
-o, --output=ARCHIVO enviar resultados de consultas a archivo (u |orden)
-o, --output=NOME_FILE reindirizza i risultati al file specificato
-o, --output=FILENAME send query results to file (or |pipe)

If you run those commands without your patch, what do you see? What do you
see with your patch? What does your environment have for each of the
following characteristics?

- Windows version
- gettext version
- user's Windows display language
- user's locale ("Format" in "Region" control panel)
- Windows ANSI code page
("Language for non-Unicode programs" in "Region" control panel)

#3Dmitry Dolgov
9erthalion6@gmail.com
In reply to: Noah Misch (#2)
Re: Configuring messages language on Windows

On Sun, Sep 2, 2018 at 12:50 AM Noah Misch <noah@leadboat.com> wrote:

On Fri, Jan 26, 2018 at 04:54:08PM +0300, a.parfenov@postgrespro.ru wrote:

As it mentioned in pg_locale.c, the variable LC_MESSAGES is ignored in
Windows(pg_locale.c:162).

That comment says "On Windows, setlocale(LC_MESSAGES) does not work". It says
nothing about the LC_MESSAGES environment variable.

Additionally, this affects regress tests, since language
for messages generated by psql is also configured via LC_MESSAGES and
ignored on Windows installations and cause failure of tests on
non-English Windows installations.

I vaguely recall having seen such a problem with an old version of GNU
gettext. On Windows Server 2016, with binaries from
https://get.enterprisedb.com/postgresql/postgresql-11.0-beta3-windows-x64-binaries.zip,
in an account having its Windows display language set to "Español (España)", I
get this behavior:

$ for lang in '' it C; do LC_MESSAGES=$lang ./psql.exe --help; done | grep -e --output
-o, --output=ARCHIVO enviar resultados de consultas a archivo (u |orden)
-o, --output=NOME_FILE reindirizza i risultati al file specificato
-o, --output=FILENAME send query results to file (or |pipe)

If you run those commands without your patch, what do you see? What do you
see with your patch? What does your environment have for each of the
following characteristics?

- Windows version
- gettext version
- user's Windows display language
- user's locale ("Format" in "Region" control panel)
- Windows ANSI code page
("Language for non-Unicode programs" in "Region" control panel)

Due to age and lack of answers to the reviewers feedback, I think it's right to
mark this patch as "Returned with feedback", unless someone is interested and
wants to take over it.