ui: Make diagnostic message prefix translatable.
* guix/ui.scm (define-diagnostic): Expect PREFIX to be enclosed in 'G_'. Emit call to 'gettext' on PREFIX. (warning, info, report-error): Wrap prefix in 'G_'.
This commit is contained in:
parent
32813e8440
commit
26a2021a1f
1 changed files with 33 additions and 26 deletions
59
guix/ui.scm
59
guix/ui.scm
|
@ -124,35 +124,42 @@ (define-module (guix ui)
|
||||||
;;;
|
;;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(define-syntax-rule (define-diagnostic name prefix)
|
(define-syntax define-diagnostic
|
||||||
"Create a diagnostic macro (i.e., NAME), which will prepend PREFIX to all
|
(syntax-rules ()
|
||||||
|
"Create a diagnostic macro (i.e., NAME), which will prepend PREFIX to all
|
||||||
messages."
|
messages."
|
||||||
(define-syntax name
|
((_ name (G_ prefix))
|
||||||
(lambda (x)
|
(define-syntax name
|
||||||
(syntax-case x ()
|
(lambda (x)
|
||||||
((name (underscore fmt) args (... ...))
|
(syntax-case x ()
|
||||||
(and (string? (syntax->datum #'fmt))
|
((name (underscore fmt) args (... ...))
|
||||||
(free-identifier=? #'underscore #'G_))
|
(and (string? (syntax->datum #'fmt))
|
||||||
#'(begin
|
(free-identifier=? #'underscore #'G_))
|
||||||
(format (guix-warning-port) "~:[~*~;guix ~a: ~]~a"
|
#'(begin
|
||||||
(program-name) (program-name) prefix)
|
(format (guix-warning-port) "~:[~*~;guix ~a: ~]~a"
|
||||||
(format (guix-warning-port) (gettext fmt)
|
(program-name) (program-name)
|
||||||
args (... ...))))
|
(gettext prefix %gettext-domain))
|
||||||
((name (N-underscore singular plural n) args (... ...))
|
(format (guix-warning-port) (gettext fmt %gettext-domain)
|
||||||
(and (string? (syntax->datum #'singular))
|
args (... ...))))
|
||||||
(string? (syntax->datum #'plural))
|
((name (N-underscore singular plural n) args (... ...))
|
||||||
(free-identifier=? #'N-underscore #'N_))
|
(and (string? (syntax->datum #'singular))
|
||||||
#'(begin
|
(string? (syntax->datum #'plural))
|
||||||
(format (guix-warning-port) "~:[~*~;guix ~a: ~]~a"
|
(free-identifier=? #'N-underscore #'N_))
|
||||||
(program-name) (program-name) prefix)
|
#'(begin
|
||||||
(format (guix-warning-port)
|
(format (guix-warning-port) "~:[~*~;guix ~a: ~]~a"
|
||||||
(ngettext singular plural n %gettext-domain)
|
(program-name) (program-name)
|
||||||
args (... ...))))))))
|
(gettext prefix %gettext-domain))
|
||||||
|
(format (guix-warning-port)
|
||||||
|
(ngettext singular plural n %gettext-domain)
|
||||||
|
args (... ...))))))))))
|
||||||
|
|
||||||
(define-diagnostic warning "warning: ") ; emit a warning
|
;; XXX: This doesn't work well for right-to-left languages.
|
||||||
(define-diagnostic info "")
|
;; TRANSLATORS: The goal is to emit "warning:" followed by a short phrase;
|
||||||
|
;; "~a" is a placeholder for that phrase.
|
||||||
|
(define-diagnostic warning (G_ "warning: ")) ;emit a warning
|
||||||
|
(define-diagnostic info (G_ ""))
|
||||||
|
|
||||||
(define-diagnostic report-error "error: ")
|
(define-diagnostic report-error (G_ "error: "))
|
||||||
(define-syntax-rule (leave args ...)
|
(define-syntax-rule (leave args ...)
|
||||||
"Emit an error message and exit."
|
"Emit an error message and exit."
|
||||||
(begin
|
(begin
|
||||||
|
|
Loading…
Reference in a new issue