Hello!
Le mercredi 14 mai 2025 à 18:28 -0400, Richard Stallman a écrit :
> I wonder, does GNU Getopt have support for this already?
I am not sure, but I don’t think so. Looking at posix/getopt.c, in
process_long_option, it seems that the (relevant part of the) argument
is only matched against the name of the option (or an abbreviation),
and never against a translated name. Maybe I should be looking at
something else?
The rest of the email assumes it’s not supported.
For replacing options, support in getopt may not be necessary. Looking
at the "Getopt Long Option Example" in the libc manual, one would just
have to mark the option names with the traditional N_ macro and call
gettext before using the long_options array.
If the goal is to recognize both sets of options, it can still be done
without getopt support, but it becomes a bit more difficult. The
long_options array would reserve space for twice the number of options,
and then the translated options would be copied in the other half of
the array. This does not solve all problems. For instance, in the Guile
wrapper, checking for a value for an option after parsing now needs two
tests and it becomes impossible to require the presence of an option.
A substantial amount of work will be left to the getopt caller anyway.
Documentation of the translated option names must be correct in all
cases, whether the documentation has a translation, and whether the
option name has a translation. For instance, the documentation of --
help could be:
printf (_ (" -h, --help, --%s show this help message and exit\n"),
_ ("help")); /* or rather with pgettext */
If the option name is not translated, duplicate mention may also be
undesirable.
If getopt support is to be enabled, then in which catalog (textdomain)
should it try to find the translation of an option name? For standard
option names like --output, getopt can use its own catalog. For non-
standard option names, it needs to be configured. Or should we consider
that getopt is only called in a program, so it can use gettext /
pgettext directly?
Vivien