public inbox for [email protected]
help / color / mirror / Atom feedFrom: Peter Smith <[email protected]>
To: Álvaro Herrera <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: Redundant/mis-use of _(x) gettext macro?
Date: Fri, 24 Apr 2026 13:10:03 +1000
Message-ID: <CAHut+Pu7LWQB+m9HTf4nf3BQu8bC_-N5c=kuOf=EHHZE_Ctj9Q@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAHut+PuD2pGMEKmk2dFA+guzxBEOas5+=LAm5E+SM2LU35KOnQ@mail.gmail.com>
<[email protected]>
On Thu, Apr 23, 2026 at 7:25 PM Álvaro Herrera <[email protected]> wrote:
>
> On 2026-Apr-23, Peter Smith wrote:
>
> > v2 removes translation of the comma separator, due to the discussion
> > over at [1].
>
> Hmm, at least Japanese uses a different character for commas, and
> apparently French likes to add a space, so I think this is a bad move.
> I think we could handle these things by including the comma together
> with the literal in each element of the list being constructed, as in
> the attached.
>
OK. Including the comma within a larger translated string seems like a
better idea.
Since you now have the list `length`, I wondered why not simplify
further to use list_nth indexing? Then you can remove
`foreach_current_index` and `lc`.
PSA.
~~~~
Also, why did you choose to implement `last` versus `first` logic?
e.g. How about this?
------
GetPublicationsStr(List *publications, StringInfo dest, bool quote_literal)
{
ListCell *lc;
bool first = true;
Assert(publications != NIL);
foreach(lc, publications)
{
char *pubname = strVal(lfirst(lc));
if (quote_literal)
{
if (!first)
appendStringInfoString(dest, ", ");
appendStringInfoString(dest, quote_literal_cstr(pubname));
}
else
{
if (first)
appendStringInfo(dest, _("\"%s\""), pubname);
else
appendStringInfo(dest, _(", \"%s\""), pubname);
}
first = false;
}
}
------
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachments:
[application/octet-stream] 0001-change-translation-markers-in-GetPublicationStr-PS.diff (1.5K, 2-0001-change-translation-markers-in-GetPublicationStr-PS.diff)
download | inline diff:
diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c
index 5a733585490..7749ec380de 100644
--- a/src/backend/catalog/pg_subscription.c
+++ b/src/backend/catalog/pg_subscription.c
@@ -41,31 +41,35 @@ static List *textarray_to_stringlist(ArrayType *textarray);
/*
* Add a comma-separated list of publication names to the 'dest' string.
+ *
+ * If quote_literal is true, the returned list can be used to construct an SQL
+ * command, thus no translation is applied. Otherwise, the string can be used
+ * to create a user-facing message, so translatable quote marks are added.
*/
void
GetPublicationsStr(List *publications, StringInfo dest, bool quote_literal)
{
- ListCell *lc;
- bool first = true;
+ int length = list_length(publications);
Assert(publications != NIL);
- foreach(lc, publications)
+ for (int i = 0; i < length; i++)
{
- char *pubname = strVal(lfirst(lc));
-
- if (first)
- first = false;
- else
- appendStringInfoString(dest, ", ");
+ char *pubname = strVal(list_nth(publications, i));
+ bool last = i >= length - 1;
if (quote_literal)
+ {
appendStringInfoString(dest, quote_literal_cstr(pubname));
+ if (!last)
+ appendStringInfoString(dest, ", ");
+ }
else
{
- appendStringInfoChar(dest, '"');
- appendStringInfoString(dest, pubname);
- appendStringInfoChar(dest, '"');
+ if (last)
+ appendStringInfo(dest, _("\"%s\""), pubname);
+ else
+ appendStringInfo(dest, _("\"%s\", "), pubname);
}
}
}
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Redundant/mis-use of _(x) gettext macro?
In-Reply-To: <CAHut+Pu7LWQB+m9HTf4nf3BQu8bC_-N5c=kuOf=EHHZE_Ctj9Q@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox