From mboxrd@z Thu Jan 1 00:00:00 1970 From: "pelzflorian (Florian Pelz)" Subject: Re: Website translation Date: Sun, 25 Aug 2019 20:58:31 +0200 Message-ID: <20190825185831.6bcfajoe6hcep2eo@pelzflorian.localdomain> References: <20190715155414.y6lv45rv55ihvzs5@pelzflorian.localdomain> <87muhc8iqi.fsf@gnu.org> <20190718150836.kzf2tmbtng5l42ta@pelzflorian.localdomain> <87h87jffd7.fsf@elephly.net> <20190718202831.4vavgrmogrkpdote@pelzflorian.localdomain> <20190719122952.an6yr6azie4x3xjg@pelzflorian.localdomain> <20190726111155.qospxvrw7rnuwtok@pelzflorian.localdomain> <20190805130827.thp3zzw5ljo6g3h2@pelzflorian.localdomain> <20190807223310.yiwzodu7fwjhvrm6@pelzflorian.localdomain> <874l28lx7y.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="u53tpe2x3xs7dkno" Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:60951) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1xio-0006zs-AO for guix-devel@gnu.org; Sun, 25 Aug 2019 14:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1xim-0001bs-Pp for guix-devel@gnu.org; Sun, 25 Aug 2019 14:58:38 -0400 Content-Disposition: inline In-Reply-To: <874l28lx7y.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org, sirgazil , matias_jose_seco@autoproduzioni.net, julien lepiller --u53tpe2x3xs7dkno Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 22, 2019 at 11:13:53PM +0200, Ludovic Court=C3=A8s wrote: > It would be great to add the right steps to website/.guix.scm (in > guix-artwork.git). >=20 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=C3=BC des Webauftritt= s:"))) ;;; ((quasiquote (footer "Mit " (unquote (quasiquote (span (@ (class "met= ta")) "=E2=99=A5"))) " von Menschen gemacht und durch " (unquote (quasiqu= ote (a (@ (class "link-yellow") (href (unquote (gnu-url "software/guile/"= )))) "GNU Guile"))) " erm=C3=B6glicht. " (unquote (quasiquote (a (@ (clas= s "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/te= mplates/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) =20 ,(if (null? crumbs) "" (breadcrumbs crumbs)) + ,(pk (let () + (use-modules (ice-9 local-eval)) + (local-eval '(gnu-url) (the-environment)))) =20 ,content (footer It crashes with ERROR: In procedure %resolve-variable: error: local-eval: unbound variable I will continue investigating. Regards, Florian --u53tpe2x3xs7dkno Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0007-website-Make-building-with-.guix.scm-work-with-multi.patch" >From 26d1bc2c1cea8742640be0e2b307a2e4c0397095 Mon Sep 17 00:00:00 2001 From: Florian Pelz 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 --u53tpe2x3xs7dkno Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0008-website-Have-.guix.scm-create-MO-files-for-translati.patch" >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 --u53tpe2x3xs7dkno--