Re: GUC names in messages

Alvaro Herrera <alvherre@alvh.no-ip.org>

From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Michael Paquier <michael@paquier.xyz>
Cc: Peter Smith <smithpb2250@gmail.com>, Nathan Bossart <nathandbossart@gmail.com>, Laurenz Albe <laurenz.albe@cybertec.at>, Peter Eisentraut <peter@eisentraut.org>, Tom Lane <tgl@sss.pgh.pa.us>, Daniel Gustafsson <daniel@yesql.se>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-11-30T10:57:05Z
Lists: pgsql-hackers
> +/*
> + * Return whether the GUC name should be enclosed in double-quotes.
> + *
> + * Quoting is intended for names which could be mistaken for normal English
> + * words.  Quotes are only applied to GUC names that are written entirely with
> + * lower-case alphabetical characters.
> + */
> +static bool
> +quotes_needed_for_GUC_name(const char *name)
> +{
> +	for (const char *p = name; *p; p++)
> +	{
> +		if ('a' > *p || *p > 'z')
> +			return false;
> +	}
> +
> +	return true;
> +}

I think you need a function that the name possibly quoted, in a way that
lets the translator handle the quoting:

  static char buffer[SOMEMAXLEN];

  quotes_needed = ...;

  if (quotes_needed)
     /* translator: a quoted configuration parameter name */
     snprintf(buffer, _("\"%s\""), name);
     return buffer
  else
     /* no translation needed in this case */
     return name;

then the calling code just does a single %s that prints the string
returned by this function.  (Do note that the function is not reentrant,
like pg_dump's fmtId.  Shouldn't be a problem ...)

> @@ -3621,8 +3673,8 @@ set_config_option_ext(const char *name, const char *value,
>  	{
>  		if (changeVal && !makeDefault)
>  		{
> -			elog(DEBUG3, "\"%s\": setting ignored because previous source is higher priority",
> -				 name);
> +			elog(DEBUG3, "%s%s%s: setting ignored because previous source is higher priority",
> +				 GUC_FORMAT(name));

Note that elog() doesn't do translation, and DEBUG doesn't really need
to worry too much about style anyway.  I'd leave these as-is.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"La primera ley de las demostraciones en vivo es: no trate de usar el sistema.
Escriba un guión que no toque nada para no causar daños." (Jakob Nielsen)



Commits

  1. Apply GUC name from central table in more places of guc.c

  2. Use camel case for "DateStyle" in some error messages

  3. Unify some error messages to ease work of translators

  4. Apply more quoting to GUC names in messages

  5. Revise GUC names quoting in messages again

  6. doc: Mention how to use quotes with GUC names in error messages

  7. Apply quotes more consistently to GUC names in logs