]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix translatable string construction
authorÁlvaro Herrera <alvherre@kurilemu.de>
Thu, 11 Jun 2026 16:29:36 +0000 (18:29 +0200)
committerÁlvaro Herrera <alvherre@kurilemu.de>
Thu, 11 Jun 2026 16:29:36 +0000 (18:29 +0200)
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 <smithpb2250@gmail.com>
Author: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/CAHut+Pvp7jYcaiZ3pXedXgLcWZWDBLXFUK05JtZpGv3Mj=UOjw@mail.gmail.com

src/backend/catalog/pg_subscription.c
src/backend/commands/tablecmds.c
src/backend/replication/logical/relation.c

index 1f1fdc75af6f459e94ccb8a2ce1043f20d243533..45eff207746346ef7fda57bd20c3c812da3f612f 100644 (file)
@@ -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;
        }
 }
 
index a33e22e8e61847c1dcad6bd069282d782adbfd6d..38f9ffcd04f7e7a95a4917bc7a2733ef866bb949 100644 (file)
@@ -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,
index 0b1d80b5b0fd2deb8a7058b611d7cfa4906e0c27..296cbaede3018cb782196f83b1a33f37fae44c93 100644 (file)
@@ -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;