Le 18/04/2018 à 22:12, William A Rowe Jr a écrit :
On Wed, Apr 18, 2018 at 2:31 PM, Nick Kew <n...@apache.org> wrote:
I suspect the straightforward way to do this, in 2.6/3.0, will be to add an
i18n table of the error log strings extracted from and indexed by those
APLOGNO() entries. No match? Default English message.
Please, not without an overhaul of APLOGNO to automate it a lot better!
The time to devise your error message is when coding an original
ap_log_*error, not retrospectively once a number has been generated!
++1
This could be achieved easily by just adding in 'log_error_core()':
(+ a few lines to initialize gettext in main() + a few lines to get a pool in 'log_error_core()' (i.e. p below))

    /* Check if we have a leading AHnnnnn: header */
    if (p &&
        fmt[0] == 'A' &&
        fmt[1] == 'H' &&
        apr_isdigit(fmt[2]) &&
        apr_isdigit(fmt[3]) &&
        apr_isdigit(fmt[4]) &&
        apr_isdigit(fmt[5]) &&
        apr_isdigit(fmt[6]) &&
        fmt[7] == ':' &&
        fmt[8] == ' ') {
            const char *tmp;

            /* Get the translation of the message itself */
            tmp = gettext(&fmt[9]);

            /* Rewrite the format string with the translated message */
            fmt = apr_pstrcat(p, apr_pstrmemdup(p, fmt, 9), tmp, NULL);
            printf("tmp: %s\n", fmt);
    }

That's all.
If interested by this approach, I can give a full working patch.

the po file can then be generated with things like:
   xgettext server/core.c -kap_log_error:5

This could be a good starting point which does not need to refactor everything, at the cost of some cycles and some additional memory.

In fact, it would call for a refactoring of the entire ap_log framework
away from printf-style format strings and vars, that’ll inevitably give rise
to a whole new level of awkwardness.  Which seems like a very bad
effort-to-gain ratio.  -1 to embarking on this, unless you want to
create a new experimental branch to play in.
I agree this is not a trivial change. There are specific risks of corrupting
one language's %tokens in a way that segfaults the runtime (switch any
%d for a %s and boom.) The resulting table is absolutely a root admin's
directive, must not be manipulated by any other than root.

If using gettext, there are some tools to check for that.

CJ

Reply via email to