Thread: Re: Better title output for psql \dt \di etc. commands
Greg Sabino Mullane <htamfids@gmail.com> writes: > Please find attached a patch to enable more intuitive titles when using > psql and doing the following actions: > \dt \di \dv \dm \ds \dE > In other words, everything in listTables() > We still default to "List or relations", but if we know that the user has > requested exactly one specific type of relation, we use that > instead. As presented, I think this fails the translatability guideline about "Do not construct sentences at run-time" [1]. You could get around that by selecting one of several whole title strings, though. For myself, if we were going to do something like this, I'd kind of like to cover more cases: greg=# \dti List of tables and indexes But I'm really not sure how to maintain translatability without a combinatorial explosion. It's fairly easy to see how we might produce output like greg=# \dtvi List of tables, views, indexes but "List of", "tables", "views", and "indexes" would all have to be separately translated, and I fear that might not hang together well. regards, tom lane [1] https://www.postgresql.org/docs/devel/nls-programmer.html#NLS-GUIDELINES
Greg Sabino Mullane <htamfids@gmail.com> writes: > I toyed with that for a bit, but as you say, without generating a ton of > combinations to translate, we'd have to fall back on run-time > constructions. Neither is ideal. I also realized that I almost never type > "\dti". Very common for me are \d and \dt and \dv etc. but combinations are > something I never bother with. At that point, I just do a \d. I think given > how rare (granted, anecdotally) those combinations are, it's okay if we > expose people to the "r" word. Fair. This is already a step forward, so it doesn't have to be perfect. Looking at the code, I'm not thrilled with the strspn() coding method. I'd much rather it relied on the bool flags we already computed (showTables etc). I'm wondering about adding a step like int ntypes = (int) showTables + (int) showIndexes + ... (the explicit coercions to int probably aren't necessary) and then the code could look like (ntypes != 1) ? _("List of relations") : (showTables) ? _("List of tables") : (showIndexes) ? _("List of indexes") : ... "ntypes" could also be used to simplify the logic that forces all the flags on, up at the top of the function. regards, tom lane
On Mon, Feb 03, 2025 at 03:12:57PM -0500, Tom Lane wrote: > Greg Sabino Mullane <htamfids@gmail.com> writes: >> I toyed with that for a bit, but as you say, without generating a ton of >> combinations to translate, we'd have to fall back on run-time >> constructions. Neither is ideal. I also realized that I almost never type >> "\dti". Very common for me are \d and \dt and \dv etc. but combinations are >> something I never bother with. At that point, I just do a \d. I think given >> how rare (granted, anecdotally) those combinations are, it's okay if we >> expose people to the "r" word. > > Fair. This is already a step forward, so it doesn't have to be > perfect. +1. I don't use combinations like \dti regularly, either. -- nathan
On Mon, Feb 3, 2025 at 5:38 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
One problem with it is that while we can leave "List of ???" out of the set of translatable strings easily, we can't currently do that for the argument of pg_log_error because it's automatically a gettext trigger. I'd rather not burden translators with figuring out what to do with that. Is it worth creating pg_log_error_internal, equivalently to elog and errmsg_internal in the backend?
I don't think so, unless there are other uses of it waiting. For this particular item, I'm still of the opinion that leaving it as "List of relations" is a pretty good default for some future somebody who forgets to update the lists of relation types. New types are certainly not going to happen often. Better "List of relations" than a release where everybody and their cousin starts asking what "List of ???" means.
BTW, I updated the regression tests for this, and that bears out your argument that one-type commands are the majority. There are still a couple "List of relations", but not many.
Thank you for that, I should have done that in my original patch.
Cheers,
Greg
P.S. I found it amusing to see in some quick grepping that pg_controldata has a msgstr of "???". So far no language has managed to translate it into something else.
Greg Sabino Mullane <htamfids@gmail.com> writes: > ... For this > particular item, I'm still of the opinion that leaving it as "List of > relations" is a pretty good default for some future somebody who forgets to > update the lists of relation types. New types are certainly not going to > happen often. Better "List of relations" than a release where everybody and > their cousin starts asking what "List of ???" means. Hopefully an oversight like that wouldn't make it to release. But hiding it by putting out an ordinary-looking title might help it avoid detection for a long time. > P.S. I found it amusing to see in some quick grepping that pg_controldata > has a msgstr of "???". So far no language has managed to translate it into > something else. There are several pre-existing "???" strings in describe.c too, for similar this-shouldn't-happen cases. I'm not proposing something that's far outside our existing practice. regards, tom lane