[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Make option parsing error messages translatable

From: Daniel Shahaf <d.s_at_daniel.shahaf.name>
Date: Fri, 3 May 2013 17:10:52 +0300

C. Michael Pilato wrote on Fri, May 03, 2013 at 08:56:25 -0400:
> On 05/02/2013 04:45 PM, Mattias Engdegård wrote:
> > It is quite annoying that some of the more common error messages, the
> >
> > svn: invalid option: --gurgle
> >
> > kind, are entirely untranslatable because they are printed directly by
> > APR which does not have any concept of translation at all. (This was
> > reported before but met with silence:
> > http://svn.haxx.se/dev/archive-2008-05/1445.shtml)
> >
> > It is not easy to fix it in a clean way; ideally, APR would return a
> > detailed error code together with the required string parameters, but
> > it doesn't. Even if we did change APR to that effect, it would be an
> > incompatibility requiring a new APR version for use with Subversion.
> >
> > This patch, instead, installs an apr_getopt_err_fn_t, acting as a
> > replacement for fprintf. It is admittedly a hack, but quite a
> > localised one -- it doesn't foul up any other code -- and does not
> > have any negative effects that I can think of. In short, it should be
> > a strict improvement.
> >
> > Should APR's getopt error strings change, all that will happen is that
> > they are shown untranslated, just like any other translated strings.
>
> It's a hack, to be sure, but it doesn't strike me as one that carries a
> particularly high penalty. Plus, it's ultimately not much more of a hack
> than we already employ in *much* more commonly executed code -- the code
> which determines which of the svn_error_t's in the chain are "tracing
> errors". (See svn_error__is_tracing_link().)
>
> +1 (from me, at least) to commit. That said, I know danielsh voiced some
> pretty strong opinions the opposite direction about this on IRC, so please
> respect those and see if he's willing to budge before moving forward.

It's a hack. It hardcodes the specific first and third arguments to the
    (os->errfn)("%s: %s: %c\n", _, "invalid option", _);
call in APR's unix/getopt.c. The only benefit we get in return is
translating six two-word error messages in option parsing.

Anyway, how about this:

static void
emit_option_error(void *baton, const char *fmt, ...)
{
  struct { FILE *stream; const char *argv0; apr_pool_t *pool; } *b = baton;
  va_list va;
  va_start(va, fmt);
  vfprintf(b->stream, fmt, va);
  va_end(va);
  svn_error_clear(svn_cmdline_fprintf(b->pool,
                                      _("%s: See '%s --help' or '%s --help <subcommand>'"),
                                      b->argv0, b->argv0, b->argv0));
  return;
}
Received on 2013-05-03 16:11:31 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.