ui: Fix i18n for diagnostic messages.

Until now, we'd pass 'gettext' the "augmented" format string, which
'gettext' would not find in message catalogs.  Now we pass it FMT as is,
which is what catalogs contain.

* guix/ui.scm (define-diagnostic)[augmented-format-string]: Remove.
Emit one 'format' call to print the prefix, and a second one to print
the actual message.
This commit is contained in:
Ludovic Courtès 2019-04-09 23:06:38 +02:00
parent 5d9f9ad631
commit 32813e8440
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -129,28 +129,24 @@ (define-syntax-rule (define-diagnostic name prefix)
messages."
(define-syntax name
(lambda (x)
(define (augmented-format-string fmt)
(string-append "~:[~*~;guix ~a: ~]~a" (syntax->datum fmt)))
(syntax-case x ()
((name (underscore fmt) args (... ...))
(and (string? (syntax->datum #'fmt))
(free-identifier=? #'underscore #'G_))
(with-syntax ((fmt* (augmented-format-string #'fmt))
(prefix (datum->syntax x prefix)))
#'(format (guix-warning-port) (gettext fmt*)
(program-name) (program-name) prefix
#'(begin
(format (guix-warning-port) "~:[~*~;guix ~a: ~]~a"
(program-name) (program-name) prefix)
(format (guix-warning-port) (gettext fmt)
args (... ...))))
((name (N-underscore singular plural n) args (... ...))
(and (string? (syntax->datum #'singular))
(string? (syntax->datum #'plural))
(free-identifier=? #'N-underscore #'N_))
(with-syntax ((s (augmented-format-string #'singular))
(p (augmented-format-string #'plural))
(prefix (datum->syntax x prefix)))
#'(format (guix-warning-port)
(ngettext s p n %gettext-domain)
(program-name) (program-name) prefix
#'(begin
(format (guix-warning-port) "~:[~*~;guix ~a: ~]~a"
(program-name) (program-name) prefix)
(format (guix-warning-port)
(ngettext singular plural n %gettext-domain)
args (... ...))))))))
(define-diagnostic warning "warning: ") ; emit a warning