Обсуждение: Redundant/mis-use of _(x) gettext macro?

Поиск
Список
Период
Сортировка

Redundant/mis-use of _(x) gettext macro?

От
Peter Smith
Дата:
Hi.

As originally reported [1] in the EXCEPT (TABLE ...) thread, I felt
the _() gettext macro is mis-used when it contains nothing but a
quoted format string.

AFAIK the purpose of using gettext (e.g. the "_(x)" macro) is for
marking the string for i18n translation. But there's nothing even to
translate here.

Only 2 examples were found like this. Granted, this is probably not
very harmful, but IMO it's better to patch the mis-use to prevent it
from propagating.

PSA the patch for more details.

======
[1] https://www.postgresql.org/message-id/CAHut%2BPtVaOYVP1R0TOoNh5G9CUBurrP%3D6i7fJCdfWEZiqVCRvw%40mail.gmail.com

Kind Regards,
Peter Smith.
Fujitsu Australia

Вложения

Re: Redundant/mis-use of _(x) gettext macro?

От
Chao Li
Дата:

> On Apr 1, 2026, at 11:48, Peter Smith <smithpb2250@gmail.com> wrote:
>
> Hi.
>
> As originally reported [1] in the EXCEPT (TABLE ...) thread, I felt
> the _() gettext macro is mis-used when it contains nothing but a
> quoted format string.
>
> AFAIK the purpose of using gettext (e.g. the "_(x)" macro) is for
> marking the string for i18n translation. But there's nothing even to
> translate here.

Indeed.

>
> Only 2 examples were found like this. Granted, this is probably not
> very harmful, but IMO it's better to patch the mis-use to prevent it
> from propagating.

+1

>
> PSA the patch for more details.
>
> ======
> [1] https://www.postgresql.org/message-id/CAHut%2BPtVaOYVP1R0TOoNh5G9CUBurrP%3D6i7fJCdfWEZiqVCRvw%40mail.gmail.com
>
> Kind Regards,
> Peter Smith.
> Fujitsu Australia
> <v1-0001-misuse-of-gettext-macro.patch>

LGTM.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/







Re: Redundant/mis-use of _(x) gettext macro?

От
Álvaro Herrera
Дата:
On 2026-Apr-01, Peter Smith wrote:

> Hi.
> 
> As originally reported [1] in the EXCEPT (TABLE ...) thread, I felt
> the _() gettext macro is mis-used when it contains nothing but a
> quoted format string.

No, you feel wrong -- this is necessary so that the translator has
control over the quoting style of a list of items.  Not all translations
use double quoting.  Some examples from different language files:

msgstr "unbekannte Komprimierungsoption: »%s«"
msgstr "opción de compresión no reconocida: «%s»"
msgstr "option de compression inconnue : « %s »"
msgstr "tidak dapat menentukan encoding untuk lokal « %s » : codesetnya adalah « %s »"

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"In fact, the basic problem with Perl 5's subroutines is that they're not
crufty enough, so the cruft leaks out into user-defined code instead, by
the Conservation of Cruft Principle."  (Larry Wall, Apocalypse 6)



Re: Redundant/mis-use of _(x) gettext macro?

От
Peter Smith
Дата:
On Wed, Apr 1, 2026 at 10:52 PM Álvaro Herrera <alvherre@kurilemu.de> wrote:
>
> On 2026-Apr-01, Peter Smith wrote:
>
> > Hi.
> >
> > As originally reported [1] in the EXCEPT (TABLE ...) thread, I felt
> > the _() gettext macro is mis-used when it contains nothing but a
> > quoted format string.
>
> No, you feel wrong -- this is necessary so that the translator has
> control over the quoting style of a list of items.  Not all translations
> use double quoting.  Some examples from different language files:
>
> msgstr "unbekannte Komprimierungsoption: »%s«"
> msgstr "opción de compresión no reconocida: «%s»"
> msgstr "option de compression inconnue : « %s »"
> msgstr "tidak dapat menentukan encoding untuk lokal « %s » : codesetnya adalah « %s »"
>

OK. Thanks for your explanation.

======
Kind Regards,
Peter Smith.
Fujitsu Australia



Re: Redundant/mis-use of _(x) gettext macro?

От
Chao Li
Дата:

> On Apr 2, 2026, at 10:55, Peter Smith <smithpb2250@gmail.com> wrote:
>
> On Wed, Apr 1, 2026 at 10:52 PM Álvaro Herrera <alvherre@kurilemu.de> wrote:
>>
>> On 2026-Apr-01, Peter Smith wrote:
>>
>>> Hi.
>>>
>>> As originally reported [1] in the EXCEPT (TABLE ...) thread, I felt
>>> the _() gettext macro is mis-used when it contains nothing but a
>>> quoted format string.
>>
>> No, you feel wrong -- this is necessary so that the translator has
>> control over the quoting style of a list of items.  Not all translations
>> use double quoting.  Some examples from different language files:
>>
>> msgstr "unbekannte Komprimierungsoption: »%s«"
>> msgstr "opción de compresión no reconocida: «%s»"
>> msgstr "option de compression inconnue : « %s »"
>> msgstr "tidak dapat menentukan encoding untuk lokal « %s » : codesetnya adalah « %s »"
>>
>
> OK. Thanks for your explanation.
>

Yep, good to learn. Noted.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/







Re: Redundant/mis-use of _(x) gettext macro?

От
Tom Lane
Дата:
Chao Li <li.evan.chao@gmail.com> writes:
> On Apr 2, 2026, at 10:55, Peter Smith <smithpb2250@gmail.com> wrote:
>> On Wed, Apr 1, 2026 at 10:52 PM Álvaro Herrera <alvherre@kurilemu.de> wrote:
>>> No, you feel wrong -- this is necessary so that the translator has
>>> control over the quoting style of a list of items.  Not all translations
>>> use double quoting.  Some examples from different language files:

> Yep, good to learn. Noted.

This and related message style matters are covered in our docs, in

https://www.postgresql.org/docs/devel/error-style-guide.html

            regards, tom lane



Re: Redundant/mis-use of _(x) gettext macro?

От
Peter Smith
Дата:
On Wed, Apr 1, 2026 at 10:52 PM Álvaro Herrera <alvherre@kurilemu.de> wrote:
>
> On 2026-Apr-01, Peter Smith wrote:
>
> > Hi.
> >
> > As originally reported [1] in the EXCEPT (TABLE ...) thread, I felt
> > the _() gettext macro is mis-used when it contains nothing but a
> > quoted format string.
>
> No, you feel wrong -- this is necessary so that the translator has
> control over the quoting style of a list of items.  Not all translations
> use double quoting.  Some examples from different language files:
>
> msgstr "unbekannte Komprimierungsoption: »%s«"
> msgstr "opción de compresión no reconocida: «%s»"
> msgstr "option de compression inconnue : « %s »"
> msgstr "tidak dapat menentukan encoding untuk lokal « %s » : codesetnya adalah « %s »"
>

The explanation [1] that even the comma separators and the quotes are
translatable parts of the message reminded me to revisit the
`GetPublicationsStr` function.

This function builds a comma-separated list of publication names.

It is called in 2 scenarios:
1. to construct a pubname list to be included in some SQL (here,
parameter quote_literal=true)
2. to construct a pubname list to be included in some error message
(here, parameter quote_literal=false).

In hindsight, it looks like this function has been broken since it was
originally implemented 4 yrs ago (8f2e2bb), because it does not allow
translation of commas and quotes when the result is being used for
error messages.

PSA a patch to fix that.

======
[1] https://www.postgresql.org/message-id/202604011144.jeo56tazdx6z%40alvherre.pgsql

Kind Regards,
Peter Smith.
Fujitsu Australia

Вложения