unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Julien Lepiller <julien@lepiller.eu>
To: Miguel <rosen644835@gmail.com>
Cc: guix-devel@gnu.org
Subject: Re: [PATCH 1/2] bootstrap: Break automake dependency on generated files. (was Re: Let’s translate!)
Date: Fri, 26 Apr 2019 20:55:23 +0200	[thread overview]
Message-ID: <20190426205523.1e1134b3@sybil.lepiller.eu> (raw)
In-Reply-To: <20190426130514.6639920e@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 643 bytes --]

Le Fri, 26 Apr 2019 13:05:14 +0200,
Miguel <rosen644835@gmail.com> a écrit :

> Hi,
> 
> El Fri, 26 Apr 2019 11:30:04 +0200
> Julien Lepiller <julien@lepiller.eu> escribió:
> > Thank you! I've just pushed it and removed doc/guix.*.texi and
> > doc/contributing.*.texi from the repository, added them
> > to .gitignore too.  
> 
> Thank you very much, my emacs and magit will thank you too, as each
> change in the manual was taking awfully long to refresh. :)
> 
> Best regards,
> Miguel

There was an issue introduced by that patch: the manual was not
generated by guix pull anymore. The attached patch fixes that. WDYT?

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-self-Rebuild-translated-manuals.patch --]
[-- Type: text/x-patch, Size: 8405 bytes --]

From d93644846ff954c221c2510755766da3f0e27b5c Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Fri, 26 Apr 2019 14:54:52 +0200
Subject: [PATCH] self: Rebuild translated manuals.

* guix/self.scm (info-manual): Run po4a and related commands to generate
translated texi files before building translated manuals.
---
 guix/self.scm | 116 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 115 insertions(+), 1 deletion(-)

diff --git a/guix/self.scm b/guix/self.scm
index 2a10d1d25f..89d3212f52 100644
--- a/guix/self.scm
+++ b/guix/self.scm
@@ -60,6 +60,8 @@
       ("gzip"       (ref '(gnu packages compression) 'gzip))
       ("bzip2"      (ref '(gnu packages compression) 'bzip2))
       ("xz"         (ref '(gnu packages compression) 'xz))
+      ("po4a"       (ref '(gnu packages gettext) 'po4a))
+      ("gettext"       (ref '(gnu packages gettext) 'gettext-minimal))
       (_            #f))))                        ;no such package
 
 \f
@@ -255,6 +257,12 @@ DOMAIN, a gettext domain."
 
 (define (info-manual source)
   "Return the Info manual built from SOURCE."
+  (define po4a
+    (specification->package "po4a"))
+
+  (define gettext
+    (specification->package "gettext"))
+
   (define texinfo
     (module-ref (resolve-interface '(gnu packages texinfo))
                 'texinfo))
@@ -270,6 +278,9 @@ DOMAIN, a gettext domain."
   (define documentation
     (file-append* source "doc"))
 
+  (define documentation-po
+    (file-append* source "po/doc"))
+
   (define examples
     (file-append* source "gnu/system/examples"))
 
@@ -277,6 +288,49 @@ DOMAIN, a gettext domain."
     (with-imported-modules '((guix build utils))
       #~(begin
           (use-modules (guix build utils))
+          (use-modules (ice-9 match))
+          (use-modules (ice-9 peg))
+          (use-modules (ice-9 regex))
+          (use-modules (ice-9 textual-ports))
+          (use-modules (srfi srfi-1))
+          
+          ;; A small parser for po files
+          (define-peg-pattern po-file body (* (or comment entry whitespace)))
+          (define-peg-pattern whitespace body (or " " "\t" "\n"))
+          (define-peg-pattern comment-chr body (range #\space #\頋))
+          (define-peg-pattern comment none (and "#" (* comment-chr) "\n"))
+          (define-peg-pattern entry all
+            (and (ignore (* whitespace)) (ignore "msgid ") msgid
+                 (ignore (* whitespace)) (ignore "msgstr ") msgstr))
+          (define-peg-pattern escape body (or "\\\\" "\\\"" "\\n"))
+          (define-peg-pattern str-chr body (or " " "!" (and (ignore "\\") "\"")
+                                               "\\n" (and (ignore "\\") "\\")
+                                               (range #\# #\頋)))
+          (define-peg-pattern msgid all content)
+          (define-peg-pattern msgstr all content)
+          (define-peg-pattern content body
+            (and (ignore "\"") (* str-chr) (ignore "\"")
+                 (? (and (ignore (* whitespace)) content))))
+          
+          (define (parse-tree->assoc parse-tree)
+            "Converts a po PARSE-TREE to an association list."
+            (define regex (make-regexp "\\\\n"))
+            (match parse-tree
+              ('() '())
+              ((entry parse-tree ...)
+               (match entry
+                 ((? string? entry)
+                  (parse-tree->assoc parse-tree))
+                 ;; empty msgid
+                 (('entry ('msgid ('msgstr msgstr)))
+                  (parse-tree->assoc parse-tree))
+                 ;; empty msgstr
+                 (('entry ('msgid msgid) 'msgstr)
+                  (parse-tree->assoc parse-tree))
+                 (('entry ('msgid msgid) ('msgstr msgstr))
+                  (acons (regexp-substitute/global #f regex msgid 'pre "\n" 'post)
+                         (regexp-substitute/global #f regex msgstr 'pre "\n" 'post)
+                         (parse-tree->assoc parse-tree)))))))
 
           (mkdir #$output)
 
@@ -322,11 +376,15 @@ DOMAIN, a gettext domain."
                     (find-files (string-append #$documentation "/images")
                                 "\\.png$"))
 
-          ;; Finally build the manual.  Copy it the Texinfo files to $PWD and
+          ;; Finally build the manual.  Copy it the Texinfo and po files to $PWD and
           ;; add a symlink to the 'images' directory so that 'makeinfo' can
           ;; see those images and produce image references in the Info output.
           (copy-recursively #$documentation "."
                             #:log (%make-void-port "w"))
+          (for-each
+            (lambda (file)
+              (copy-file file (basename file)))
+            (find-files #$documentation-po ".*.po$"))
           (delete-file-recursively "images")
           (symlink (string-append #$output "/images") "images")
 
@@ -334,6 +392,62 @@ DOMAIN, a gettext domain."
           (setenv "GUIX_LOCPATH"
                   #+(file-append glibc-utf8-locales "/lib/locale"))
 
+          (setenv "LC_ALL" "en_US.UTF-8")
+          (setlocale LC_ALL "en_US.UTF-8")
+
+          (define (create-texi po source texi-name)
+            (let* ((parse-tree
+                     (peg:tree (match-pattern
+                                 po-file
+                                 (call-with-input-file po get-string-all))))
+                   (translations (parse-tree->assoc parse-tree))
+                   (tmp-name (string-append texi-name ".tmp")))
+              (setenv "PATH" #+(file-append gettext "/bin"))
+              (invoke #+(file-append po4a "/bin/po4a-translate")
+                "-M" "UTF-8" "-L" "UTF-8" "-k" "0" "-f" "texinfo"
+                "-m" source "-p" po "-l" tmp-name)
+              (with-output-to-file texi-name
+                (lambda _
+                  (format #t "~a"
+                    (fold
+                      (lambda (elem content)
+                        (let* ((msgid (car elem))
+                               (msgstr (cdr elem)))
+                          (if (or (equal? msgstr "")
+                                  (string-any (lambda (chr)
+                                                (member chr '(#\{ #\} #\( #\)
+                                                              #\newline #\,)))
+                                              msgid))
+                            content
+                            (let ((regexp1
+                                    (make-regexp
+                                      (string-append
+                                        "ref\\{"
+                                        (string-join
+                                          (string-split msgid #\ ) "[ \n]+")
+                                        ","))))
+                            (let ((regexp2
+                                    (make-regexp
+                                      (string-append
+                                        "ref\\{"
+                                        (string-join
+                                          (string-split msgid #\ ) "[ \n]+")
+                                        "\\}"))))
+                              (regexp-substitute/global
+                                #f regexp2
+                                (regexp-substitute/global
+                                  #f regexp1 content 'pre "ref{" msgstr "," 'post)
+                                'pre "ref{" msgstr "}" 'post))))))
+                      (call-with-input-file tmp-name get-string-all)
+                      translations))))))
+          (for-each (lambda (po)
+                      (let ((lang (cadr (reverse (string-split po #\.)))))
+                        (create-texi po "guix.texi"
+                                     (string-append "guix." lang ".texi"))
+                        (create-texi po "contributing.texi"
+                                     (string-append "contributing." lang ".texi"))))
+                    (find-files "." "^guix-manual\\.[a-z]{2}(_[A-Z]{2})?\\.po$"))
+
           (for-each (lambda (texi)
                       (unless (string=? "guix.texi" texi)
                         ;; Create 'version-LL.texi'.
-- 
2.21.0


  reply	other threads:[~2019-04-26 18:56 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11  9:54 New template for 'guix-manual' made available Translation Project Robot
2019-04-12 20:43 ` Let’s translate! Ludovic Courtès
2019-04-13  1:56   ` Meiyo Peng
2019-04-13  6:45     ` pelzflorian (Florian Pelz)
2019-04-13  7:49       ` pelzflorian (Florian Pelz)
2019-04-13  9:33       ` Meiyo Peng
2019-04-13  7:14     ` Julien Lepiller
2019-04-13  9:27       ` Meiyo Peng
2019-04-23  0:42       ` [PATCH 0/2] Removal of generated files (was Re: Let’s translate!) Miguel
2019-04-23  0:43         ` [PATCH 1/2] bootstrap: Break automake dependency on generated files. " Miguel
2019-04-23  7:28           ` Julien Lepiller
2019-04-23 10:28             ` Miguel
2019-04-26  9:30               ` Julien Lepiller
2019-04-26 11:05                 ` Miguel
2019-04-26 18:55                   ` Julien Lepiller [this message]
2019-04-26 22:10                     ` Ludovic Courtès
2019-04-27 12:32                       ` Julien Lepiller
2019-04-27 13:52                         ` Ludovic Courtès
2019-04-23 14:30             ` Ludovic Courtès
2019-04-23 22:51               ` Miguel
2019-04-24 10:37                 ` Julien Lepiller
2019-04-25  8:50                   ` Ludovic Courtès
2019-04-25  9:54                     ` Julien Lepiller
2019-04-26  8:39                       ` Ludovic Courtès
     [not found]         ` <20190423024427.10cd6e87@gmail.com>
2019-04-23 22:42           ` [PATCH 2/2] doc: Add Spanish translation. " Ludovic Courtès
2019-04-13  7:49     ` Let’s translate! znavko
2019-04-13  9:46       ` Meiyo Peng
2019-04-15 12:38     ` Ludovic Courtès
2019-04-13  5:11 ` znavko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190426205523.1e1134b3@sybil.lepiller.eu \
    --to=julien@lepiller.eu \
    --cc=guix-devel@gnu.org \
    --cc=rosen644835@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).