From: Álvaro Herrera Date: Thu, 11 Jun 2026 16:29:36 +0000 (+0200) Subject: Fix translatable string construction X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=3692a622d3fdf8a44af0c0b541a51163ead314f1;p=thirdparty%2Fpostgresql.git Fix translatable string construction In a few places, we were constructing translatable strings consisting of elements list by adding one element at a time and separately a comma. This is not great from a translation point of view, so rewrite to append the comma together with the corresponding element in one go. Author: Peter Smith Author: Álvaro Herrera Discussion: https://postgr.es/m/CAHut+Pvp7jYcaiZ3pXedXgLcWZWDBLXFUK05JtZpGv3Mj=UOjw@mail.gmail.com --- diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c index 1f1fdc75af6..45eff207746 100644 --- a/src/backend/catalog/pg_subscription.c +++ b/src/backend/catalog/pg_subscription.c @@ -41,6 +41,10 @@ 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) @@ -54,19 +58,21 @@ GetPublicationsStr(List *publications, StringInfo dest, bool quote_literal) { char *pubname = strVal(lfirst(lc)); - if (first) - first = false; - else - appendStringInfoString(dest, ", "); - if (quote_literal) + { + if (!first) + appendStringInfoString(dest, ", "); appendStringInfoString(dest, quote_literal_cstr(pubname)); + } else { - appendStringInfoChar(dest, '"'); - appendStringInfoString(dest, pubname); - appendStringInfoChar(dest, '"'); + if (first) + appendStringInfo(dest, _("\"%s\""), pubname); + else + appendStringInfo(dest, _(", \"%s\""), pubname); } + + first = false; } } diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index a33e22e8e61..38f9ffcd04f 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -20607,18 +20607,11 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd, { char *pubname = get_publication_name(pubid, false); - if (!first) - { - /* - * translator: This is a separator in a list of publication - * names. - */ - appendStringInfoString(&pubnames, _(", ")); - } - + if (first) + appendStringInfo(&pubnames, _("\"%s\""), pubname); + else + appendStringInfo(&pubnames, _(", \"%s\""), pubname); first = false; - - appendStringInfo(&pubnames, _("\"%s\""), pubname); } ereport(ERROR, diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c index 0b1d80b5b0f..296cbaede30 100644 --- a/src/backend/replication/logical/relation.c +++ b/src/backend/replication/logical/relation.c @@ -239,7 +239,7 @@ static char * logicalrep_get_attrs_str(LogicalRepRelation *remoterel, Bitmapset *atts) { StringInfoData attsbuf; - int attcnt = 0; + bool first = true; int i = -1; Assert(!bms_is_empty(atts)); @@ -248,12 +248,11 @@ logicalrep_get_attrs_str(LogicalRepRelation *remoterel, Bitmapset *atts) while ((i = bms_next_member(atts, i)) >= 0) { - attcnt++; - if (attcnt > 1) - /* translator: This is a separator in a list of entity names. */ - appendStringInfoString(&attsbuf, _(", ")); - - appendStringInfo(&attsbuf, _("\"%s\""), remoterel->attnames[i]); + if (first) + appendStringInfo(&attsbuf, _("\"%s\""), remoterel->attnames[i]); + else + appendStringInfo(&attsbuf, _(", \"%s\""), remoterel->attnames[i]); + first = false; } return attsbuf.data;