From cc753650eccf3dcbf074999c458e42df8d3c0827 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 21 Apr 2020 21:50:34 +0200 Subject: self: translate-texi-manuals: Don't hardcode "guix.texi". * guix/self.scm (translate-texi-manuals)[build](translate-texi): Add 'prefix' and #:extras parameters and honor them. Adjust callers. --- guix/self.scm | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'guix/self.scm') diff --git a/guix/self.scm b/guix/self.scm index 1040c27a6b..93dcb9bee3 100644 --- a/guix/self.scm +++ b/guix/self.scm @@ -339,35 +339,35 @@ TRANSLATIONS, an alist of msgid and msgstr." #f regexp1 content 'pre "ref{" msgstr "," 'post) 'pre "ref{" msgstr "}" 'post)))))) content translations)) - - (define (translate-texi po lang) - "Translate the manual for one language LANG using the PO file." + + (define* (translate-texi prefix po lang + #:key (extras '())) + "Translate the manual for one language LANG using the PO file. +PREFIX must be the prefix of the manual, 'guix' or 'guix-cookbook'. EXTRAS is +a list of extra files, such as '(\"contributing\")." (let ((translations (call-with-input-file po read-po-file))) - (translate-tmp-texi po "guix.texi" - (string-append "guix." lang ".texi.tmp")) - (translate-tmp-texi po "contributing.texi" - (string-append "contributing." lang ".texi.tmp")) - (let* ((texi-name (string-append "guix." lang ".texi")) - (tmp-name (string-append texi-name ".tmp"))) - (with-output-to-file texi-name - (lambda _ - (format #t "~a" - (translate-cross-references - (call-with-input-file tmp-name get-string-all) - translations))))) - (let* ((texi-name (string-append "contributing." lang ".texi")) - (tmp-name (string-append texi-name ".tmp"))) - (with-output-to-file texi-name - (lambda _ - (format #t "~a" - (translate-cross-references - (call-with-input-file tmp-name get-string-all) - translations))))))) + (for-each (lambda (file) + (translate-tmp-texi po (string-append file ".texi") + (string-append file "." lang + ".texi.tmp"))) + (cons prefix extras)) + + (for-each (lambda (file) + (let* ((texi (string-append file "." lang ".texi")) + (tmp (string-append texi ".tmp"))) + (with-output-to-file texi + (lambda () + (display + (translate-cross-references + (call-with-input-file tmp get-string-all) + translations)))))) + (cons prefix extras)))) (for-each (lambda (po) (match (reverse (string-split po #\.)) ((_ lang _ ...) - (translate-texi po lang)))) + (translate-texi "guix" po lang + #:extras '("contributing"))))) (find-files "." "^guix-manual\\.[a-z]{2}(_[A-Z]{2})?\\.po$")) (for-each -- cgit v1.2.3 From 84c37e636804513f1fde1fe437784400d99e268e Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 21 Apr 2020 22:23:54 +0200 Subject: self: translate-texi-manuals: Add 'available-translations'. * guix/self.scm (translate-texi-manuals)[build](available-translations): New procedure. Use it rather than directly calling 'find-files' & co. --- guix/self.scm | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'guix/self.scm') diff --git a/guix/self.scm b/guix/self.scm index 93dcb9bee3..3cc1003c3a 100644 --- a/guix/self.scm +++ b/guix/self.scm @@ -363,12 +363,25 @@ a list of extra files, such as '(\"contributing\")." translations)))))) (cons prefix extras)))) - (for-each (lambda (po) - (match (reverse (string-split po #\.)) - ((_ lang _ ...) - (translate-texi "guix" po lang - #:extras '("contributing"))))) - (find-files "." "^guix-manual\\.[a-z]{2}(_[A-Z]{2})?\\.po$")) + (define (available-translations directory domain) + ;; Return the list of available translations under DIRECTORY for + ;; DOMAIN, a gettext domain such as "guix-manual". The result is + ;; a list of language/PO file pairs. + (filter-map (lambda (po) + (let ((base (basename po))) + (and (string-prefix? (string-append domain ".") + base) + (match (string-split base #\.) + ((_ ... lang "po") + (cons lang po)))))) + (find-files directory + "\\.[a-z]{2}(_[A-Z]{2})?\\.po$"))) + + (for-each (match-lambda + ((language . po) + (translate-texi "guix" po language + #:extras '("contributing")))) + (available-translations "." "guix-manual")) (for-each (lambda (file) -- cgit v1.2.3 From e1e6491226347d9fb93ff484d78cef98848a510a Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 21 Apr 2020 23:05:02 +0200 Subject: self: Build and install 'guix-cookbook.info' and its translations. * guix/self.scm (translate-texi-manuals)[build]: Translate and install guix-cookbook.texi. (info-manual)[build]: Handle "guix-cookbook*.texi". --- guix/self.scm | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'guix/self.scm') diff --git a/guix/self.scm b/guix/self.scm index 3cc1003c3a..4682cd221c 100644 --- a/guix/self.scm +++ b/guix/self.scm @@ -383,12 +383,17 @@ a list of extra files, such as '(\"contributing\")." #:extras '("contributing")))) (available-translations "." "guix-manual")) - (for-each - (lambda (file) - (copy-file file (string-append #$output "/" file))) - (append - (find-files "." "contributing\\..*\\.texi$") - (find-files "." "guix\\..*\\.texi$")))))) + (for-each (match-lambda + ((language . po) + (translate-texi "guix-cookbook" po language))) + (available-translations "." "guix-cookbook")) + + (for-each (lambda (file) + (install-file file #$output)) + (append + (find-files "." "contributing\\..*\\.texi$") + (find-files "." "guix\\..*\\.texi$") + (find-files "." "guix-cookbook\\..*\\.texi$")))))) (computed-file "guix-translated-texinfo" build)) @@ -415,7 +420,8 @@ a list of extra files, such as '(\"contributing\")." (define build (with-imported-modules '((guix build utils)) #~(begin - (use-modules (guix build utils)) + (use-modules (guix build utils) + (ice-9 match)) (mkdir #$output) @@ -476,13 +482,13 @@ a list of extra files, such as '(\"contributing\")." #+(file-append glibc-utf8-locales "/lib/locale")) (for-each (lambda (texi) - (unless (string=? "guix.texi" texi) - ;; Create 'version-LL.texi'. - (let* ((base (basename texi ".texi")) - (dot (string-index base #\.)) - (tag (string-drop base (+ 1 dot)))) - (symlink "version.texi" - (string-append "version-" tag ".texi")))) + (match (string-split (basename texi) #\.) + (("guix" language "texi") + ;; Create 'version-LL.texi'. + (symlink "version.texi" + (string-append "version-" language + ".texi"))) + (_ #f)) (invoke #+(file-append texinfo "/bin/makeinfo") texi "-I" #$documentation @@ -491,7 +497,10 @@ a list of extra files, such as '(\"contributing\")." (basename texi ".texi") ".info"))) (cons "guix.texi" - (find-files "." "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$"))) + (append (find-files "." + "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$") + (find-files "." + "^guix-cookbook.*\\.texi$")))) ;; Compress Info files. (setenv "PATH" -- cgit v1.2.3