Обсуждение: Chinese translations not applied correctly on PostgreSQL 18 Windows
Hi there,
Here I'd like to report an issue encountered during my use of PG18.
Description:
Chinese translations exist in the .mo file but are not being used at runtime for error messages on PostgreSQL 18 Windows.
Environment:
- PostgreSQL version: 18.0
- OS: Windows 10 x64 (Build 17763)
- Installation: EnterpriseDB installer (postgresql-18.0-1-windows-x64.exe)
- Locale: zh_CN (Chinese Simplified)
- Database encoding: UTF8
Steps to reproduce:
1. Install PostgreSQL 18 on Windows
2. Set environment: LANG=zh_CN, chcp 936
3. Run psql and execute: INSERT INTO tb (c) VALUES ('a\O\0');
Expected output (based on .mo file translations):
错误: 无效的 "UTF8" 编码的字节顺序: 0x00
Actual output:
WARNING: nonstandard use of escape in a string literal
第1行INSERT INTO tb (c) VALUES ('a\O\0');
^
提示: Use the escape string syntax for escapes, e.g., E'\r\n'.
ERROR: invalid byte sequence for encoding "UTF8": 0x00
Observations:
- Some parts ARE translated: "第1行" (line 1), "提示" (HINT)
- Main messages are NOT translated: "WARNING", "ERROR", error text
- The .mo file at C:\Program Files\PostgreSQL\18\share\locale\zh_CN\LC_MESSAGES\postgres-18.mo contains 5214 translations including:
- "ERROR" → "错误"
- "WARNING" → "警告"
- "nonstandard use of escape in a string literal" → "字符串常量中以非标准的方法使用转义字符"
- "invalid byte sequence for encoding \"%s\": %s" → "无效的 \"%s\" 编码的字节顺序: %s"
Translation file verified:
The translations exist in the .mo file but are not being applied at runtime.
Possible cause:
This appears to be a bug in PostgreSQL 18's gettext internationalization on Windows, where some message types are not being correctly localized.
---
Please let me know if you need any additional information.
Thanks and Best Regards!
Elodie Fu
"=?utf-8?B?ZWxvZGll?=" <beifu23@foxmail.com> writes:
> Steps to reproduce:
> 1. Install PostgreSQL 18 on Windows
> 2. Set environment: LANG=zh_CN, chcp 936
> 3. Run psql and execute: INSERT INTO tb (c) VALUES ('a\O\0');
Setting that environment variable isn't sufficient. It'll cause
psql to translate messages that it generates locally, but to get
translated messages from the server, you need to set the server's
lc_messages parameter. I speak no Chinese, so I can't really
read your example, but here's an example using French:
$ LANG=fr_FR.utf8 psql
psql (19devel)
Saisissez « help » pour l'aide.
postgres=# select 1/0;
ERROR: division by zero
postgres=# set lc_messages = 'fr_FR';
SET
postgres=# select 1/0;
ERREUR: division par zéro
You can use any of the various ways of setting a server parameter
to install that setting on a more permanent basis.
regards, tom lane
Thanks Tom! Setting
lc_messages = 'zh_CN' fixed the issue. The Chinese translations are now working well.Thanks and Best Regards!
Elodie Fu
Original
From: Tom Lane <tgl@sss.pgh.pa.us> Date: 2026-04-24 05:28 To: elodie <beifu23@foxmail.com> Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org> Subject: Re: Chinese translations not applied correctly on PostgreSQL 18 Windows |
> Steps to reproduce:
> 1. Install PostgreSQL 18 on Windows
> 2. Set environment: LANG=zh_CN, chcp 936
> 3. Run psql and execute: INSERT INTO tb (c) VALUES ('a\O\0');
Setting that environment variable isn't sufficient. It'll cause
psql to translate messages that it generates locally, but to get
translated messages from the server, you need to set the server's
lc_messages parameter. I speak no Chinese, so I can't really
read your example, but here's an example using French:
$ LANG=fr_FR.utf8 psql
psql (19devel)
Saisissez « help » pour l'aide.
postgres=# select 1/0;
ERROR: division by zero
postgres=# set lc_messages = 'fr_FR';
SET
postgres=# select 1/0;
ERREUR: division par zéro
You can use any of the various ways of setting a server parameter
to install that setting on a more permanent basis.
regards, tom lane