From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Andrey Albershteyn <aalbersh@kernel.org>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 2/4] repair: add canonical names for the XR_INO_ constants
Date: Fri, 5 Dec 2025 08:29:05 -0800 [thread overview]
Message-ID: <20251205162905.GP89472@frogsfrogsfrogs> (raw)
In-Reply-To: <20251205081337.GA21400@lst.de>
On Fri, Dec 05, 2025 at 09:13:37AM +0100, Christoph Hellwig wrote:
> On Thu, Dec 04, 2025 at 09:18:11AM -0800, Darrick J. Wong wrote:
> > > And that's what I'd expect. But there are no direct gettext calls
> > > anywhere in xfsprogs, despite quite a bit of N_() usage. What am I
> > > missing?
> >
> > #define _(x) gettext(x)
> >
> > in platform_defs.h.
> >
> > (and no, I don't get anything meaningful out of "N_()" for magic
> > tagging and "_()" to mean lookup, but according to Debian codesearch
> > it's a common practice in things like binutils and git and vim)
>
> Yeah, the caller has the _() anyway for the format string, even in the
> current version of the patch. No idea how that leads to inserting the
> translations passed in through %s, but I'll just stick to what we do
> for other such cases in xfsprogs (e.g. the .oneline field in xfs_io).
<nod> It took me a while to wrap my head around what's really happening
with gettext. Would an example help? Start with:
static const char foostrings[] = {
[0] = N_("foo"),
[1] = N_("bar"),
};
int main(int argc, char *argv[])
{
int i = argc > 2 ? 1 : 0;
printf("%s\n", _("Hello world!"));
printf("%s\n", _(foostrings[i]));
}
First, make runs the gettext catalog generator, which sees two N_()
expression with a constant string inside of it ("foo" and "bar"), and
one _() expression with a constant string inside of it ("Hello world!").
These three strings are added to the catalog. It ignores the _()
expression with a variable reference in it because that's not a string.
gcc then runs the source through the preprocessor:
static const char foostrings[] = {
[0] = "foo",
[1] = "bar",
};
int main(int argc, char *argv[])
{
int i = argc > 2 ? 1 : 0;
printf("%s\n", gettext("Hello world!"));
printf("%s\n", gettext(foostrings[i]));
}
So foostrings is an array of pointers to const strings, as expected.
The actual message catalogue lookups happen in the printfs at the end of
main.
(Also note that we're not supposed to put format specifiers in message
catalog strings because malicious translation files can screw over the
program by replacing %d with %s, etc. But most programs are super
guilty of violating that, xfsprogs included...)
--D
next prev parent reply other threads:[~2025-12-05 16:29 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-28 6:36 repair tidyups for metadir handling Christoph Hellwig
2025-11-28 6:36 ` [PATCH 1/4] repair: add a enum for the XR_INO_* values Christoph Hellwig
2025-11-28 7:53 ` Carlos Maiolino
2025-12-01 6:22 ` Christoph Hellwig
2025-12-01 9:00 ` Carlos Maiolino
2025-12-01 22:37 ` Darrick J. Wong
2025-11-28 6:37 ` [PATCH 2/4] repair: add canonical names for the XR_INO_ constants Christoph Hellwig
2025-11-28 8:00 ` Carlos Maiolino
2025-12-01 6:23 ` Christoph Hellwig
2025-12-01 22:47 ` Darrick J. Wong
2025-12-02 7:33 ` Christoph Hellwig
2025-12-02 17:59 ` Darrick J. Wong
2025-12-03 6:09 ` Christoph Hellwig
2025-12-04 17:18 ` Darrick J. Wong
2025-12-05 8:13 ` Christoph Hellwig
2025-12-05 16:29 ` Darrick J. Wong [this message]
2025-11-28 6:37 ` [PATCH 3/4] repair: factor out a process_dinode_metafile helper Christoph Hellwig
2025-11-28 8:05 ` Carlos Maiolino
2025-12-01 22:47 ` Darrick J. Wong
2025-11-28 6:37 ` [PATCH 4/4] repair: enhance process_dinode_metafile Christoph Hellwig
2025-11-28 8:15 ` Carlos Maiolino
2025-12-01 6:23 ` Christoph Hellwig
2025-12-01 9:01 ` Carlos Maiolino
2025-12-01 22:48 ` Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2025-12-08 7:11 repair tidyups for metadir handling v2 Christoph Hellwig
2025-12-08 7:11 ` [PATCH 2/4] repair: add canonical names for the XR_INO_ constants Christoph Hellwig
2025-12-08 17:36 ` Darrick J. Wong
2025-12-09 6:57 ` Christoph Hellwig
2025-12-09 15:59 ` Darrick J. Wong
2025-12-09 16:20 ` Christoph Hellwig
2025-12-09 16:26 ` Darrick J. Wong
2025-12-10 5:54 repair tidyups for metadir handling v3 Christoph Hellwig
2025-12-10 5:54 ` [PATCH 2/4] repair: add canonical names for the XR_INO_ constants Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251205162905.GP89472@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=aalbersh@kernel.org \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox