guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/2] bootstrap: Break automake dependency on generated files.


From: Ludovic Courtès
Subject: Re: [PATCH 1/2] bootstrap: Break automake dependency on generated files. (was Re: Let’s translate!)
Date: Sat, 27 Apr 2019 00:10:04 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

Hi Julien!

Julien Lepiller <address@hidden> skribis:

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

Neat!

> From d93644846ff954c221c2510755766da3f0e27b5c Mon Sep 17 00:00:00 2001
> From: Julien Lepiller <address@hidden>
> 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.

[...]

>  (define (info-manual source)
>    "Return the Info manual built from SOURCE."

We should probably make a separate derivation (and a separate procedure)
to build the translated Texi files.  Maybe we can think about it later,
though.

>      (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))

Please make it a single use-modules:

  (use-modules (a b c) (x y z) &)

> +          ;; 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)))))))

What about moving all this to (guix build po) or similar?  It would
export read-po-file, which takes an input port and returns an alist of
message ID/translations.  I dont want to think about parse trees as a
user of the API.  :-)

> +          (define (create-texi po source texi-name)

This function is too long, could you split it?
Maybe it should be called translate-texi?

> +            (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)))

Please use match.

> +                          (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))))))

I guess this could become the body of a translate-cross-reference
procedure or similar?

> +          (for-each (lambda (po)
> +                      (let ((lang (cadr (reverse (string-split po #\.)))))

Use match.

Could you send an updated patch?

Thank you!

Ludo.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]