On Thu, Aug 22, 2019 at 11:13:53PM +0200, Ludovic Courtès wrote: > It would be great to add the right steps to website/.guix.scm (in > guix-artwork.git). >
Even though the attached patches allow building with .guix.scm, I found that my previous code does not work correctly. The deconstruction of the translation into an sexp happened at macro expansion time before the evaluation phase when setlocale calls took effect, so both or neither of index.en_US.html and index.de_DE.html contained the German translation, depending on the system-wide locale setting. I tried to move the deconstruction to the evaluation phase by using local-eval: (define (sgettext x) "After choosing an identifier for marking s-expressions for translation, make it usable by defining a macro with it calling sgettext. If for example the chosen identifier is G_, use (define-syntax G_ sgettext)." (syntax-case x () ((_ exp) (let ((msgstr (sexp->msgid (syntax->datum #'exp)))) #`(local-eval (pk (deconstruct (syntax->datum #'exp) (gettext #,msgstr))) (the-environment)))))) which almost works, except it seems (but I am unsure) the-environment captures the wrong environment, so functions are missing. I see: ERROR: In procedure %resolve-variable: error: gnu-url: unbound variable building pages in '/tmp/gnu.org/software/guix'... ;;; ((quasiquote (h2 (@ (class "a11y-offset")) "Menü des Webauftritts:"))) ;;; ((quasiquote (footer "Mit " (unquote (quasiquote (span (@ (class "metta")) "♥"))) " von Menschen gemacht und durch " (unquote (quasiquote (a (@ (class "link-yellow") (href (unquote (gnu-url "software/guile/")))) "GNU Guile"))) " ermöglicht. " (unquote (quasiquote (a (@ (class "link-yellow") (href "//git.savannah.gnu.org/cgit/guix/guix-artwork.git/tree/website")) "Quellcode"))) " unter der " (unquote (quasiquote (a (@ (class "link-yellow") (href (unquote (gnu-url "licenses/agpl-3.0.html")))) "GNU AGPL"))) "."))) I try to find a minimal example. I add the following to the pristine guix-website (with only my first patch): diff --git a/website/apps/base/templates/theme.scm b/website/apps/base/templates/theme.scm index ecb27ef..b993c2a 100644 --- a/website/apps/base/templates/theme.scm +++ b/website/apps/base/templates/theme.scm @@ -106,6 +106,9 @@ ,(navbar #:active-item active-menu-item) ,(if (null? crumbs) "" (breadcrumbs crumbs)) + ,(pk (let () + (use-modules (ice-9 local-eval)) + (local-eval '(gnu-url) (the-environment)))) ,content (footer It crashes with ERROR: In procedure %resolve-variable: error: local-eval: unbound variable I will continue investigating. Regards, Florian
>From 26d1bc2c1cea8742640be0e2b307a2e4c0397095 Mon Sep 17 00:00:00 2001 From: Florian Pelz <pelzflor...@pelzflorian.de> Date: Sat, 24 Aug 2019 21:27:50 +0200 Subject: [PATCH 7/8] website: Make building with .guix.scm work with multiple linguas. * website/.guix.scm: Make Haunt build directory writable so Haunt can overwrite duplicate assets. --- website/.guix.scm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/website/.guix.scm b/website/.guix.scm index 068ef0d..5eb48b6 100644 --- a/website/.guix.scm +++ b/website/.guix.scm @@ -48,6 +48,11 @@ (copy-recursively #$source ".") + ;; Make the copy writable so Haunt can overwrite duplicate assets. + (invoke #+(file-append (specification->package "coreutils") + "/bin/chmod") + "--recursive" "u+w" ".") + ;; For Haunt. (setenv "GUILE_LOAD_PATH" (string-join %load-path ":")) (setenv "GUILE_LOAD_COMPILED_PATH" -- 2.22.0
>From e367d7ba09d901c9ad4b54b919de2e3a10ba5791 Mon Sep 17 00:00:00 2001 From: Florian Pelz <pelzflor...@pelzflorian.de> 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