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
-
Apply GUC name from central table in more places of guc.c
- f3f06b13308e 18.0 landed
-
Use camel case for "DateStyle" in some error messages
- 2e7c4abe5a88 18.0 landed
-
Unify some error messages to ease work of translators
- a68159ff2b32 18.0 landed
-
Apply more quoting to GUC names in messages
- b4db64270e0c 18.0 landed
-
Revise GUC names quoting in messages again
- 17974ec25946 17.0 landed
-
doc: Mention how to use quotes with GUC names in error messages
- a243569bf65c 17.0 landed
-
Apply quotes more consistently to GUC names in logs
- 8d9978a7176a 17.0 landed