2019-03-05 22:43:56 +01:00
|
|
|
;;; GNU Guix web site
|
2023-01-04 22:50:56 +01:00
|
|
|
;;; Copyright © 2017, 2019, 2020, 2021, 2023 Ludovic Courtès <ludo@gnu.org>
|
website: Add custom xgettext to extract from nested sexps for i18n.
* website/po/POTFILES: New file. List apps files here.
* website/po/LINGUAS: New file. List en_US lingua.
* website/po/ietf-tags.scm: New file. Add association for en_US lingua.
* website/scripts/sexp-xgettext.scm: New file for generating a POT file.
(<keyword-spec>, <po-entry>, <construct-fold-state>): New record types.
(combine-duplicate-po-entries, complex-keyword-spec?, parse-scheme-file,
po-equal?, write-po-entry, update-ecomments-string!, update-file-name!,
update-old-line-number!, update-line-number!, incr-line-number!,
incr-line-number-for-each-nl!, current-ref, make-simple-po-entry,
matching-keyword, nth-exp, more-than-one-exp?, token->string-symbol-or-keyw,
complex-marked-list->po-entries, construct-po-entries, tag,
construct-msgid-and-po-entries, scheme-file->po-entries): New procedures.
(%keyword-specs, %options, %comments-line, %ecomments-string, %file-name,
%old-line-number, %line-number, %files-from-port, %source-files,
%output-po-entries, %output-port): New variables.
* website/sexp-xgettext.scm: New file with module for looking up
translations.
(%complex-keywords, %simple-keywords, %plural-numbers, %linguas):
New variables.
(<construct-fold-state>, <deconstruct-fold-state>): New record types.
(set-complex-keywords!, set-simple-keywords!, gettext-keyword?, tag,
sexp->msgid, deconstruct): New procedures.
(sgettext, spgettext, sngettext, snpgettext): New macro helpers.
* website/apps/i18n.scm: New file.
(G_, N_, C_, NC_, ietf-tags-file-contents): New syntax to use for i18n.
(%current-ietf-tag, %current-lang, %current-lingua): New variables.
(builder->localized-builder, builders->localized-builders,
localized-root-path, first-value): New utility procedures.
(<asset>, <page>): New imports from Haunt.
* website/haunt.scm: Wrap each builder to build the locale set in LC_ALL.
* website/.guix.scm: Make Haunt build directory writable so Haunt can
overwrite duplicate assets. Convert PO files to MO files and build for
each lingua.
* website/README: Adapt build instructions for i18n.
* website/i18n-howto: New file with usage instructions.
2020-07-02 19:17:38 +02:00
|
|
|
;;; Copyright © 2019 Florian Pelz <pelzflorian@pelzflorian.de>
|
2017-05-22 12:26:59 +02:00
|
|
|
;;;
|
2019-03-05 22:43:56 +01:00
|
|
|
;;; This file is part of the GNU Guix web site.
|
2017-05-22 12:26:59 +02:00
|
|
|
;;;
|
2019-03-05 22:43:56 +01:00
|
|
|
;;; The GNU Guix web site is free software; you can redistribute it and/or modify it
|
2017-05-22 12:26:59 +02:00
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or
|
|
|
|
;;; (at your option) any later version.
|
|
|
|
;;;
|
2019-03-05 22:43:56 +01:00
|
|
|
;;; The GNU Guix web site is distributed in the hope that it will be useful, but
|
2017-05-22 12:26:59 +02:00
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
;;; General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
2019-03-05 22:43:56 +01:00
|
|
|
;;; along with the GNU Guix web site. If not, see <http://www.gnu.org/licenses/>.
|
2017-05-22 12:26:59 +02:00
|
|
|
|
2019-07-05 12:26:16 +02:00
|
|
|
;; Run 'guix build -f .guix.scm' to build the web site.
|
2017-05-22 12:26:59 +02:00
|
|
|
|
website: Add custom xgettext to extract from nested sexps for i18n.
* website/po/POTFILES: New file. List apps files here.
* website/po/LINGUAS: New file. List en_US lingua.
* website/po/ietf-tags.scm: New file. Add association for en_US lingua.
* website/scripts/sexp-xgettext.scm: New file for generating a POT file.
(<keyword-spec>, <po-entry>, <construct-fold-state>): New record types.
(combine-duplicate-po-entries, complex-keyword-spec?, parse-scheme-file,
po-equal?, write-po-entry, update-ecomments-string!, update-file-name!,
update-old-line-number!, update-line-number!, incr-line-number!,
incr-line-number-for-each-nl!, current-ref, make-simple-po-entry,
matching-keyword, nth-exp, more-than-one-exp?, token->string-symbol-or-keyw,
complex-marked-list->po-entries, construct-po-entries, tag,
construct-msgid-and-po-entries, scheme-file->po-entries): New procedures.
(%keyword-specs, %options, %comments-line, %ecomments-string, %file-name,
%old-line-number, %line-number, %files-from-port, %source-files,
%output-po-entries, %output-port): New variables.
* website/sexp-xgettext.scm: New file with module for looking up
translations.
(%complex-keywords, %simple-keywords, %plural-numbers, %linguas):
New variables.
(<construct-fold-state>, <deconstruct-fold-state>): New record types.
(set-complex-keywords!, set-simple-keywords!, gettext-keyword?, tag,
sexp->msgid, deconstruct): New procedures.
(sgettext, spgettext, sngettext, snpgettext): New macro helpers.
* website/apps/i18n.scm: New file.
(G_, N_, C_, NC_, ietf-tags-file-contents): New syntax to use for i18n.
(%current-ietf-tag, %current-lang, %current-lingua): New variables.
(builder->localized-builder, builders->localized-builders,
localized-root-path, first-value): New utility procedures.
(<asset>, <page>): New imports from Haunt.
* website/haunt.scm: Wrap each builder to build the locale set in LC_ALL.
* website/.guix.scm: Make Haunt build directory writable so Haunt can
overwrite duplicate assets. Convert PO files to MO files and build for
each lingua.
* website/README: Adapt build instructions for i18n.
* website/i18n-howto: New file with usage instructions.
2020-07-02 19:17:38 +02:00
|
|
|
(define this-directory
|
|
|
|
(dirname (current-filename)))
|
|
|
|
|
|
|
|
;; Make sure po/LINGUAS will be found in the current working
|
|
|
|
;; directory.
|
|
|
|
(chdir this-directory)
|
|
|
|
|
|
|
|
;; We need %linguas from the (sexp-xgettext) module.
|
|
|
|
;; Therefore, we add its path to the load path.
|
|
|
|
(set! %load-path (cons this-directory %load-path))
|
|
|
|
|
2017-05-22 12:26:59 +02:00
|
|
|
(use-modules (guix) (gnu)
|
2020-06-23 20:13:27 +02:00
|
|
|
(gnu packages guile)
|
|
|
|
(gnu packages guile-xyz)
|
2021-01-26 17:48:47 +01:00
|
|
|
(gnu packages package-management)
|
2017-05-22 12:26:59 +02:00
|
|
|
(guix modules)
|
2019-07-05 12:26:16 +02:00
|
|
|
(guix git-download)
|
2019-08-22 17:17:51 +02:00
|
|
|
(guix gexp)
|
2020-06-23 20:13:27 +02:00
|
|
|
(srfi srfi-1)
|
2019-08-22 17:17:51 +02:00
|
|
|
(srfi srfi-9)
|
website: Add custom xgettext to extract from nested sexps for i18n.
* website/po/POTFILES: New file. List apps files here.
* website/po/LINGUAS: New file. List en_US lingua.
* website/po/ietf-tags.scm: New file. Add association for en_US lingua.
* website/scripts/sexp-xgettext.scm: New file for generating a POT file.
(<keyword-spec>, <po-entry>, <construct-fold-state>): New record types.
(combine-duplicate-po-entries, complex-keyword-spec?, parse-scheme-file,
po-equal?, write-po-entry, update-ecomments-string!, update-file-name!,
update-old-line-number!, update-line-number!, incr-line-number!,
incr-line-number-for-each-nl!, current-ref, make-simple-po-entry,
matching-keyword, nth-exp, more-than-one-exp?, token->string-symbol-or-keyw,
complex-marked-list->po-entries, construct-po-entries, tag,
construct-msgid-and-po-entries, scheme-file->po-entries): New procedures.
(%keyword-specs, %options, %comments-line, %ecomments-string, %file-name,
%old-line-number, %line-number, %files-from-port, %source-files,
%output-po-entries, %output-port): New variables.
* website/sexp-xgettext.scm: New file with module for looking up
translations.
(%complex-keywords, %simple-keywords, %plural-numbers, %linguas):
New variables.
(<construct-fold-state>, <deconstruct-fold-state>): New record types.
(set-complex-keywords!, set-simple-keywords!, gettext-keyword?, tag,
sexp->msgid, deconstruct): New procedures.
(sgettext, spgettext, sngettext, snpgettext): New macro helpers.
* website/apps/i18n.scm: New file.
(G_, N_, C_, NC_, ietf-tags-file-contents): New syntax to use for i18n.
(%current-ietf-tag, %current-lang, %current-lingua): New variables.
(builder->localized-builder, builders->localized-builders,
localized-root-path, first-value): New utility procedures.
(<asset>, <page>): New imports from Haunt.
* website/haunt.scm: Wrap each builder to build the locale set in LC_ALL.
* website/.guix.scm: Make Haunt build directory writable so Haunt can
overwrite duplicate assets. Convert PO files to MO files and build for
each lingua.
* website/README: Adapt build instructions for i18n.
* website/i18n-howto: New file with usage instructions.
2020-07-02 19:17:38 +02:00
|
|
|
(ice-9 match)
|
|
|
|
(ice-9 rdelim)
|
|
|
|
(ice-9 regex)
|
|
|
|
(sexp-xgettext))
|
2017-05-22 12:26:59 +02:00
|
|
|
|
|
|
|
(define source
|
2019-07-05 12:26:16 +02:00
|
|
|
(local-file this-directory "guix-web-site"
|
2017-05-22 12:26:59 +02:00
|
|
|
#:recursive? #t
|
2019-07-05 12:26:16 +02:00
|
|
|
#:select? (git-predicate this-directory)))
|
2017-05-22 12:26:59 +02:00
|
|
|
|
2021-10-25 22:57:47 +02:00
|
|
|
(define po-directory
|
|
|
|
(local-file (string-append this-directory "/po")
|
|
|
|
"guix-web-site-po-files"
|
|
|
|
#:recursive? #t
|
|
|
|
#:select? (git-predicate this-directory)))
|
|
|
|
|
2019-10-30 22:45:45 +01:00
|
|
|
(define root-path
|
|
|
|
(getenv "GUIX_WEB_SITE_ROOT_PATH"))
|
|
|
|
|
2019-07-05 12:27:34 +02:00
|
|
|
(define (package+propagated-inputs package)
|
|
|
|
(match (package-transitive-propagated-inputs package)
|
|
|
|
(((labels packages) ...)
|
|
|
|
(cons package packages))))
|
2017-05-22 12:26:59 +02:00
|
|
|
|
2021-10-25 22:57:47 +02:00
|
|
|
(define (lingua-mo-files lingua)
|
|
|
|
"Return a directory containing .mo files for LINGUA."
|
|
|
|
(define build
|
|
|
|
(with-imported-modules '((guix build utils))
|
|
|
|
#~(begin
|
|
|
|
(use-modules (guix build utils))
|
|
|
|
|
|
|
|
(define lingua
|
|
|
|
#$lingua)
|
|
|
|
|
|
|
|
(define msgfmt
|
|
|
|
#+(file-append
|
|
|
|
(specification->package "gettext-minimal")
|
|
|
|
"/bin/msgfmt"))
|
|
|
|
|
|
|
|
(define (create-mo filename)
|
|
|
|
(invoke msgfmt filename
|
|
|
|
"-o"
|
|
|
|
(string-append #$output "/" lingua "/LC_MESSAGES/"
|
|
|
|
"guix-website.mo")))
|
|
|
|
|
|
|
|
(let* ((lingua-file (string-append #$po-directory "/"
|
|
|
|
lingua ".po"))
|
|
|
|
(lang (car (string-split lingua #\_)))
|
|
|
|
(lang-file (string-append #$po-directory "/"
|
|
|
|
lang ".po"))
|
|
|
|
(packages-lingua-mo (string-append
|
|
|
|
#$guix "/share/locale/" lingua
|
|
|
|
"/LC_MESSAGES/guix-packages.mo"))
|
|
|
|
(packages-lang-mo (string-append
|
|
|
|
#$guix "/share/locale/" lang
|
|
|
|
"/LC_MESSAGES/guix-packages.mo")))
|
|
|
|
|
|
|
|
(mkdir-p (string-append #$output "/" lingua "/LC_MESSAGES"))
|
|
|
|
(cond ((file-exists? lingua-file)
|
|
|
|
(create-mo lingua-file))
|
|
|
|
((file-exists? lang-file)
|
|
|
|
(create-mo lang-file)))
|
|
|
|
|
|
|
|
(cond
|
|
|
|
((file-exists? packages-lingua-mo)
|
|
|
|
(copy-file packages-lingua-mo
|
|
|
|
(string-append #$output "/" lingua "/LC_MESSAGES/"
|
|
|
|
"guix-packages.mo")))
|
|
|
|
((file-exists? packages-lang-mo)
|
|
|
|
(copy-file packages-lang-mo
|
|
|
|
(string-append #$output "/" lingua "/LC_MESSAGES/"
|
|
|
|
"guix-packages.mo"))))))))
|
|
|
|
|
|
|
|
(computed-file (string-append "guix-web-site-" lingua "-messages")
|
|
|
|
build
|
|
|
|
#:options '(#:env-vars (("COLUMNS" . "200")))))
|
|
|
|
|
2021-10-26 00:00:41 +02:00
|
|
|
(define (lingua-web-site lingua)
|
|
|
|
"Return the web site built for LINGUA."
|
|
|
|
(define build
|
|
|
|
;; We need Guile-JSON for 'packages-json-builder'.
|
|
|
|
(with-extensions (append (package+propagated-inputs
|
|
|
|
(specification->package "guile-json"))
|
|
|
|
|
|
|
|
(package+propagated-inputs
|
|
|
|
(specification->package "guile-syntax-highlight")))
|
|
|
|
(with-imported-modules (source-module-closure
|
|
|
|
'((guix build utils)))
|
|
|
|
#~(begin
|
|
|
|
(use-modules (guix build utils)
|
|
|
|
(ice-9 popen)
|
|
|
|
(ice-9 match))
|
|
|
|
|
|
|
|
(define lingua #$lingua)
|
|
|
|
|
|
|
|
(setvbuf (current-output-port) 'line)
|
|
|
|
(setvbuf (current-error-port) 'line)
|
|
|
|
|
|
|
|
(setenv "GUIX_WEB_SITE_LOCAL" "no")
|
|
|
|
(copy-recursively #$source ".")
|
|
|
|
|
|
|
|
;; Set 'GUILE_LOAD_PATH' so that Haunt find the Guix modules and
|
|
|
|
;; its dependencies. To find out the load path of Guix and its
|
|
|
|
;; dependencies, fetch its value over 'guix repl'.
|
|
|
|
(let ((pipe (open-pipe* OPEN_BOTH
|
2023-01-04 22:50:56 +01:00
|
|
|
#+(file-append guix "/bin/guix")
|
2021-10-26 00:00:41 +02:00
|
|
|
"repl" "-t" "machine")))
|
|
|
|
(pk 'repl-version (read pipe))
|
|
|
|
(write '(list %load-path %load-compiled-path) pipe)
|
|
|
|
(force-output pipe)
|
|
|
|
(match (read pipe)
|
|
|
|
(('values ('value ((load-path ...) (compiled-path ...))))
|
|
|
|
(setenv "GUILE_LOAD_PATH" (string-join
|
|
|
|
(append load-path %load-path)
|
|
|
|
":"))
|
|
|
|
(setenv "GUILE_LOAD_COMPILED_PATH"
|
|
|
|
(string-join (append compiled-path
|
|
|
|
%load-compiled-path)
|
|
|
|
":"))))
|
|
|
|
(close-pipe pipe))
|
|
|
|
|
|
|
|
;; Make the copy writable so Haunt can overwrite duplicate assets.
|
|
|
|
(for-each make-file-writable
|
|
|
|
(find-files "." ".*" #:directories? #t))
|
|
|
|
|
|
|
|
;; So we can read/write UTF-8 files.
|
|
|
|
(setenv "GUIX_LOCPATH"
|
|
|
|
#+(file-append (specification->package "glibc-locales")
|
|
|
|
"/lib/locale"))
|
|
|
|
|
|
|
|
;; Use a sane default.
|
|
|
|
(setenv "XDG_CACHE_HOME" "/tmp/.cache")
|
|
|
|
|
|
|
|
;; Use GUIX_WEB_SITE_ROOT_PATH from the environment in which
|
|
|
|
;; this script was run.
|
|
|
|
(setenv "GUIX_WEB_SITE_ROOT_PATH" #$root-path)
|
|
|
|
|
|
|
|
;; Build the website for LINGUA. (apps i18n) calls
|
|
|
|
;; 'bindtextdomain' on $PWD so provide .mo files right here.
|
2021-10-28 10:21:52 +02:00
|
|
|
(for-each
|
|
|
|
(lambda (lingua mo-directory)
|
|
|
|
(symlink (string-append mo-directory "/" lingua)
|
|
|
|
lingua))
|
|
|
|
(list #$@%linguas)
|
|
|
|
'#$(map lingua-mo-files %linguas))
|
2021-10-26 00:00:41 +02:00
|
|
|
|
|
|
|
(setenv "LC_ALL" (string-append lingua ".utf8"))
|
|
|
|
(format #t "Running 'haunt build' for lingua ~a...~%" lingua)
|
2023-01-04 22:50:56 +01:00
|
|
|
(invoke #+(file-append haunt "/bin/haunt")
|
2021-10-26 00:00:41 +02:00
|
|
|
"build")
|
|
|
|
(mkdir-p #$output)
|
|
|
|
(copy-recursively "/tmp/gnu.org/software/guix" #$output
|
|
|
|
#:log (%make-void-port "w"))
|
|
|
|
(let ((tag (assoc-ref
|
|
|
|
(call-with-input-file "po/ietf-tags.scm"
|
|
|
|
(lambda (port) (read port)))
|
|
|
|
lingua)))
|
|
|
|
(symlink "guix.html"
|
|
|
|
(string-append #$output "/" tag "/index.html")))))))
|
|
|
|
|
|
|
|
(computed-file (string-append "guix-web-site-" lingua)
|
|
|
|
build
|
|
|
|
#:guile (specification->package "guile")
|
2021-10-26 00:14:24 +02:00
|
|
|
#:local-build? #f ;this is costly, allow offloading
|
2021-10-26 00:00:41 +02:00
|
|
|
#:options '(#:effective-version "3.0")))
|
|
|
|
|
|
|
|
(directory-union "guix-web-site"
|
|
|
|
(map lingua-web-site %linguas)
|
|
|
|
#:copy? #t)
|
2017-05-22 12:26:59 +02:00
|
|
|
|
|
|
|
;; Local Variables:
|
|
|
|
;; eval: (put 'let-package 'scheme-indent-function 1)
|
|
|
|
;; End:
|