From e367d7ba09d901c9ad4b54b919de2e3a10ba5791 Mon Sep 17 00:00:00 2001 From: Florian Pelz Date: Sun, 25 Aug 2019 11:59:24 +0200 Subject: [PATCH 8/8] website: Have .guix.scm create MO files for translation. website/.guix.scm: Convert PO files to MO files for each lingua. --- website/.guix.scm | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/website/.guix.scm b/website/.guix.scm index 5eb48b6..4a70f6a 100644 --- a/website/.guix.scm +++ b/website/.guix.scm @@ -21,7 +21,8 @@ (use-modules (guix) (gnu) (guix modules) (guix git-download) - (ice-9 match)) + (ice-9 match) + (ice-9 rdelim)) (define this-directory (dirname (current-filename))) @@ -36,6 +37,14 @@ (((labels packages) ...) (cons package packages)))) +(define linguas + (with-input-from-file "po/LINGUAS" + (lambda _ + (let loop ((line (read-line))) + (if (eof-object? line) + '() + (cons line (loop (read-line)))))))) + (define build (with-extensions (append (package+propagated-inputs (specification->package "guix")) @@ -53,6 +62,29 @@ "/bin/chmod") "--recursive" "u+w" ".") + ;; For translations, create MO files from PO files. + (for-each + (lambda (lingua) + (let* ((msgfmt #+(file-append (specification->package "gettext") + "/bin/msgfmt")) + (lingua-file (string-append "po/" lingua ".po")) + (lang (car (string-split lingua #\_))) + (lang-file (string-append "po/" lang ".po"))) + (define (create-mo filename) + (begin + (invoke msgfmt filename) + (mkdir-p (string-append lingua "/LC_MESSAGES")) + (rename-file "messages.mo" + (string-append lingua "/LC_MESSAGES/" + "guix-website.mo")))) + (cond + ((file-exists? lingua-file) + (create-mo lingua-file)) + ((file-exists? lang-file) + (create-mo lang-file)) + (else #t)))) + (list #$@linguas)) + ;; For Haunt. (setenv "GUILE_LOAD_PATH" (string-join %load-path ":")) (setenv "GUILE_LOAD_COMPILED_PATH" -- 2.22.0