From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id ODivDTg1amF4pgAAgWs5BA (envelope-from ) for ; Sat, 16 Oct 2021 04:13:12 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id eA5rCTg1amFHQAAA1q6Kng (envelope-from ) for ; Sat, 16 Oct 2021 02:13:12 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4CB612B6C2 for ; Sat, 16 Oct 2021 04:13:10 +0200 (CEST) Received: from localhost ([::1]:43838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbZC8-00036h-QC for larch@yhetil.org; Fri, 15 Oct 2021 22:13:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbZC2-00036U-Dw for guix-patches@gnu.org; Fri, 15 Oct 2021 22:13:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57342) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mbZC2-0005LU-5d for guix-patches@gnu.org; Fri, 15 Oct 2021 22:13:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mbZC1-0004YF-SY for guix-patches@gnu.org; Fri, 15 Oct 2021 22:13:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51122] [PATCH v2] maint: Factorize po xref translation. Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 16 Oct 2021 02:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51122 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: "pelzflorian (Florian Pelz)" Cc: 51122@debbugs.gnu.org Received: via spool by 51122-submit@debbugs.gnu.org id=B51122.163435035217454 (code B ref 51122); Sat, 16 Oct 2021 02:13:01 +0000 Received: (at 51122) by debbugs.gnu.org; 16 Oct 2021 02:12:32 +0000 Received: from localhost ([127.0.0.1]:40655 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mbZBX-0004XR-3G for submit@debbugs.gnu.org; Fri, 15 Oct 2021 22:12:31 -0400 Received: from lepiller.eu ([89.234.186.109]:35678) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mbZBQ-0004XC-6E for 51122@debbugs.gnu.org; Fri, 15 Oct 2021 22:12:29 -0400 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id 5359caf1; Sat, 16 Oct 2021 02:12:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from :to:cc:subject:message-id:in-reply-to:references:mime-version :content-type; s=dkim; bh=YEL7kLudPtGHs60Uji4dghidy5zBOndrknHwfu GFNHI=; b=L3zXFHHudMKxrnxaz89fzWTXGpV6KH9vlwlxxCoERaPezmtQ09J1SN W+xbq2BQ1TrXX4UD2cp677nenlz0XN1eWvY2RqfYSsXM58F4AsW3tr8wkTVHngz0 v8r1/PnTMbn4A5Dhs1ht9WlLBp+kJsqzPvoWRY2SIVJ7y86bUK/KI8uJrbF8QawE PZX73e/hZZ4ROkDzIgKDp1ZEycChPuMIJSheAejtHnSBgQfFWzgtAHXnbm1xzYmz g0W/6tBrqUrpZY8+qj0qpwwz8Dc3eWj8/2h0jvhA8jlDBHtXO4C3li3dRJM+M1yM hogHbLBZ4wLAFkojb3NoOwcAAvCfGuRw== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id 203293d6 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 16 Oct 2021 02:12:22 +0000 (UTC) Date: Sat, 16 Oct 2021 04:12:15 +0200 From: Julien Lepiller Message-ID: <20211016041215.1005a12b@tachikoma.lepiller.eu> In-Reply-To: <5EFA87E6-D0D0-4D28-99D4-2CCC7E00EDD0@lepiller.eu> References: <8a210e8ceaadfa600e60b0b97a1e7aba04b2bb02.1633901513.git.julien@lepiller.eu> <20211010233711.23bb1e9e@tachikoma.lepiller.eu> <20211011082415.j6wera4b5t4mtnxa@pelzflorian.localdomain> <20211011144626.0049af43@tachikoma.lepiller.eu> <20211011171603.3m7spi6bwlhpgjiv@pelzflorian.localdomain> <20211012000657.11daa7a3@tachikoma.lepiller.eu> <20211012155611.vbhkyxjmqlc3ja77@pelzflorian.localdomain> <20211012180941.i7c26gyz3yyqsdd6@pelzflorian.localdomain> <5EFA87E6-D0D0-4D28-99D4-2CCC7E00EDD0@lepiller.eu> X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/9VvQuUbQh/xngZ4vfRMsCRY" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1634350391; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=GoE43PIg/8fIOgSNe2S1/6aFwsR01VB8ts6O3Ew3pkU=; b=VQSkRed1atYUwgzER4kDYCfC3r9gsclVD7W7WSJER72k/HRX8bqeUE09R0+PVzCxQqYqMU OHbOtfzDDJF3IzcPdPdwHsn2k5RnaljyBhbsf0z0yO/J52YkKeXR0YY9K/XxYBorvyL3Qb oeAzuTHxezmSyEOxDi4o9RoRDECHpWtJhfnE5We6R8xV7ObUws0fTbEd5YuFSz5RJj6jk6 kAS2eZGtOqKSL78KcJymIgfNbeLm9IX8JYfs6SSev1M8MdGrU6aF1cCOMn/MKfzJfgF0/N TZ1JPzpzkKKYRVdQdbCHCsH/rGXmktcYf6DGdNNn9RXe0pzynUy/themK2uzkg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1634350391; a=rsa-sha256; cv=none; b=XMjayKHaCoAD8/w4tyJWuhP5BDoIaOHDuNFByWPPHLOZmxSqqC8J8XILp6yY4U/YV6srqE MRFEI8gfYrEeE6KQicw4nmvc8rh07zAGFZdErQYFNWC9GLhtZuBVG9Za38R4gYxCR4oOlZ Vj4RoGaXipo3qum8ild0HgInvFAYQdx37+GtC6aYpOa0zmZ3xA/Gli5V5vSP7WNv914kEf hjh56CLYeUrZVc/mYC8pyVS8JuBjxlJBtg3E6/JBYzsxm9XzHfmPHKNwWmpyF+rW/jPOvm 9y0LDULV+rM6P6uUwAXuGxvaNmOZCe5EOQApm8Ed5Aps94s9CpUITw1eJW6fNw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lepiller.eu header.s=dkim header.b=L3zXFHHu; dmarc=fail reason="SPF not aligned (relaxed)" header.from=lepiller.eu (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -1.72 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lepiller.eu header.s=dkim header.b=L3zXFHHu; dmarc=fail reason="SPF not aligned (relaxed)" header.from=lepiller.eu (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 4CB612B6C2 X-Spam-Score: -1.72 X-Migadu-Scanner: scn1.migadu.com X-TUID: 4/48b2d3ZZxx --MP_/9VvQuUbQh/xngZ4vfRMsCRY Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Le Tue, 12 Oct 2021 15:25:37 -0400, Julien Lepiller a =C3=A9crit : > Le 12 octobre 2021 14:09:41 GMT-04:00, "pelzflorian (Florian Pelz)" > a =C3=A9crit=C2=A0: > >On Tue, Oct 12, 2021 at 05:56:23PM +0200, pelzflorian (Florian Pelz) > >wrote: =20 > >> We definitely want to compile guix/build/po.scm, I think, because > >> it should be run each time a guix-manual.LL.po or > >> guix-cookbook.LL.po file changes. =20 > > > >Then again, is calling guix without compiling necessarily slower than > >the sed script? > > > >Regards, > >Florian =20 >=20 > Yes, each time I see the "newer than compiled" message, it takes > several minutes. >=20 >=20 >=20 I managed to change the dependency to only guix/po.go, and to make it not phony, so the translated manuals don't get rebuilt on every make invocation anymore. I checked again that "make" from a clean checkout and "make as-derivation" still work. --MP_/9VvQuUbQh/xngZ4vfRMsCRY Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=0001-maint-Factorize-po-xref-translation.patch =46rom 96d7096ac46f0fa8a97db76fefdf751a0584975b Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Sun, 10 Oct 2021 22:07:51 +0200 Subject: [PATCH] maint: Factorize po xref translation. This ensures we use the same method in "make" as in "guix/self.scm". * Makefile.am: Build guix/build/po.scm. * build-aux/convert-xref.scm: New file. * doc/local.mk (xref_command): Use it. * guix/self.scm (translate-cross-references): Move it... * guix/build/po.scm: Parse comments and flags separately to find fuzzy flags. (translate-cross-references): ...here. (parse-tree->assoc): Ignore fuzzy entries. --- Makefile.am | 12 +++- build-aux/convert-xref.scm | 26 +++++++++ doc/local.mk | 29 +++------- guix/build/po.scm | 115 +++++++++++++++++++++++++++++++++++-- guix/self.scm | 81 ++++---------------------- 5 files changed, 164 insertions(+), 99 deletions(-) create mode 100644 build-aux/convert-xref.scm diff --git a/Makefile.am b/Makefile.am index 635147efc1..41ec19eb89 100644 --- a/Makefile.am +++ b/Makefile.am @@ -640,6 +640,7 @@ EXTRA_DIST +=3D \ build-aux/check-final-inputs-self-contained.scm \ build-aux/check-channel-news.scm \ build-aux/compile-as-derivation.scm \ + build-aux/convert-xref.scm \ build-aux/generate-authors.scm \ build-aux/test-driver.scm \ build-aux/update-guix-package.scm \ @@ -699,8 +700,6 @@ $(1): $(2) --completed $(3) \ $$(filter %.scm,$$^) =20 -.PHONY: $(1) - endef =20 # Split compilation in several steps, each of which building a subset of @@ -712,22 +711,31 @@ MODULES_CORE =3D guix.scm $(filter-out guix/scrip= ts/%,$(filter guix/%,$(MODULE MODULES_PACKAGES =3D $(filter gnu/packages/%,$(MODULES)) MODULES_SYSTEM =3D gnu.scm $(filter-out gnu/packages/%,$(filter gnu/%,$(= MODULES))) MODULES_CLI =3D $(filter guix/scripts/%,$(MODULES)) +MODULES_PO =3D guix/build/po.scm =20 $(eval $(call guile-compilation-rule,make-core-go, \ $(MODULES_CORE) guix/config.scm $(dist_noinst_DATA), \ 0)) +.PHONY: make-core-go =20 $(eval $(call guile-compilation-rule,make-packages-go, \ $(MODULES_PACKAGES) make-core-go, \ $(words $(MODULES_CORE)))) +.PHONY: make-packages-go =20 $(eval $(call guile-compilation-rule,make-system-go, \ $(MODULES_SYSTEM) make-packages-go make-core-go, \ $(words $(MODULES_CORE) $(MODULES_PACKAGES)))) +.PHONY: make-system-go =20 $(eval $(call guile-compilation-rule,make-cli-go, \ $(MODULES_CLI) make-system-go make-packages-go make-core-go, \ $(words $(MODULES_CORE) $(MODULES_PACKAGES) $(MODULES_SYSTEM)))) +.PHONY: make-cli-go + +$(eval $(call guile-compilation-rule,guix/build/po.go, \ + $(MODULES_PO), \ + 0)) =20 SUFFIXES =3D .go =20 diff --git a/build-aux/convert-xref.scm b/build-aux/convert-xref.scm new file mode 100644 index 0000000000..47c8828857 --- /dev/null +++ b/build-aux/convert-xref.scm @@ -0,0 +1,26 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2021 Julien Lepiller +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; 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. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; 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 +;;; along with GNU Guix. If not, see . + +;; Translate cross-references in a translated .texi manual. + +(use-modules (guix build po) + (ice-9 match)) + +(match (command-line) + ((program texi pofile) + (translate-cross-references texi pofile))) diff --git a/doc/local.mk b/doc/local.mk index 8340b75a87..fff11f8183 100644 --- a/doc/local.mk +++ b/doc/local.mk @@ -97,44 +97,29 @@ PO4A_PARAMS +=3D -k 0 # produce an output even if the t= ranslation is not complete PO4A_PARAMS +=3D -f texinfo # texinfo format =20 # When a change to guix.texi occurs, it is not translated immediately. -# Because @pxref and @xref commands are reference to a section by name, th= ey +# Because @pxref and @xref commands are references to sections by name, th= ey # should be translated. If a modification adds a reference to a section, t= his # reference is not translated, which means it references a section that do= es not # exist. -# This command loops through the translated files looking for references. = For -# each of these references, it tries to find the translation and replaces = the -# reference name, even in untranslated strings. -# The last sed is a multiline sed because some references span multiple li= nes. define xref_command -cat "$@.tmp" | egrep '@p?x?ref' -A1 | sed 'N;s|--\n||g;P;D' | sed 's|^| |g= ' | \ - tr -d '\012' | sed 's|\(@p\?x\?ref\)|\n\1|g' | egrep '@p?x?ref' | \ - sed 's|^.*@p\?x\?ref{\([^,}]*\).*$$|\1|g' | sort | uniq | while re= ad e; do \ - if [ -n "$$e" ]; then \ - line=3D$$(grep -n "^msgid \"$$e\"" "$<" | cut -f1 --delimiter=3D":")= ;\ - ((line++)) ;\ - if [ "$$line" !=3D "1" ]; then \ - translation=3D$$(head -n "$$line" "$<" | tail -1 | grep msgstr | sed 's|m= sgstr "\([^"]*\)"|\1|') ;\ - if [ "$$translation" !=3D "" ]; then \ - sed "N;s@\(p\?x\?ref\){$$(echo $$e | sed 's| |[\\n ]|g')\(,\|}\)@\1= {$$translation\2@g;P;D" -i "$@.tmp" ;\ - fi ;\ - fi ;\ - fi ;\ -done +$(top_srcdir)/pre-inst-env $(GUILE) --no-auto-compile \ + "$(top_srcdir)/build-aux/convert-xref.scm" \ + $@.tmp $< endef =20 -$(srcdir)/%D%/guix.%.texi: po/doc/guix-manual.%.po $(srcdir)/%D%/contribut= ing.%.texi +$(srcdir)/%D%/guix.%.texi: po/doc/guix-manual.%.po $(srcdir)/%D%/contribut= ing.%.texi guix/build/po.go -$(AM_V_PO4A)$(PO4A_TRANSLATE) $(PO4A_PARAMS) -m "%D%/guix.texi" -p "$<" = -l "$@.tmp" -sed -i "s|guix\.info|$$(basename "$@" | sed 's|texi$$|info|')|" "$@.tmp" -$(AM_V_POXREF)$(xref_command) -mv "$@.tmp" "$@" =20 -$(srcdir)/%D%/guix-cookbook.%.texi: po/doc/guix-cookbook.%.po +$(srcdir)/%D%/guix-cookbook.%.texi: po/doc/guix-cookbook.%.po guix/build/p= o.go -$(AM_V_PO4A)$(PO4A_TRANSLATE) $(PO4A_PARAMS) -m "%D%/guix-cookbook.texi"= -p "$<" -l "$@.tmp" -sed -i "s|guix-cookbook\.info|$$(basename "$@" | sed 's|texi$$|info|')|"= "$@.tmp" -$(AM_V_POXREF)$(xref_command) -mv "$@.tmp" "$@" =20 -$(srcdir)/%D%/contributing.%.texi: po/doc/guix-manual.%.po +$(srcdir)/%D%/contributing.%.texi: po/doc/guix-manual.%.po guix/build/po.go -$(AM_V_PO4A)$(PO4A_TRANSLATE) $(PO4A_PARAMS) -m "%D%/contributing.texi" = -p "$<" -l "$@.tmp" -$(AM_V_POXREF)$(xref_command) -mv "$@.tmp" "$@" diff --git a/guix/build/po.scm b/guix/build/po.scm index eb9690ad1a..a167252244 100644 --- a/guix/build/po.scm +++ b/guix/build/po.scm @@ -20,17 +20,23 @@ (define-module (guix build po) #:use-module (ice-9 match) #:use-module (ice-9 peg) + #:use-module (ice-9 regex) #:use-module (ice-9 textual-ports) - #:export (read-po-file)) + #:use-module (ice-9 vlist) + #:use-module (srfi srfi-1) + #:export (read-po-file + translate-cross-references)) =20 ;; A small parser for po files -(define-peg-pattern po-file body (* (or comment entry whitespace))) +(define-peg-pattern po-file body (* (or entry whitespace))) (define-peg-pattern whitespace body (or " " "\t" "\n")) (define-peg-pattern comment-chr body (range #\space #\=F0=AF=A7=BF)) (define-peg-pattern comment none (and "#" (* comment-chr) "\n")) +(define-peg-pattern flags all (and (ignore "#, ") (* comment-chr) (ignore = "\n"))) (define-peg-pattern entry all - (and (ignore (* whitespace)) (ignore "msgid ") msgid - (ignore (* whitespace)) (ignore "msgstr ") msgstr)) + (and (* (or flags comment (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 "\\") "\\") @@ -53,7 +59,24 @@ (append (list "\n" prefix) result))))))) =20 (define (parse-tree->assoc parse-tree) - "Converts a po PARSE-TREE to an association list." + "Converts a po PARSE-TREE to an association list, where the key is the m= sgid +and the value is the msgstr. The result only contains non fuzzy strings." + (define (comments->flags comments) + (match comments + (('flags flags) + (map (lambda (flag) (string->symbol (string-trim-both flag #\space)= )) + (string-split flags #\,))) + ((? list? comments) + (fold + (lambda (comment res) + (match comment + ((? string? _) res) + (flags + (append (comments->flags flags) + res)))) + '() + comments)))) + (match parse-tree (() '()) ((entry . parse-tree) @@ -66,10 +89,22 @@ ;; empty msgstr (('entry ('msgid msgid) 'msgstr) (parse-tree->assoc parse-tree)) + (('entry _ ('msgid msgid) 'msgstr) + (parse-tree->assoc parse-tree)) (('entry ('msgid msgid) ('msgstr msgstr)) (acons (interpret-newline-escape msgid) (interpret-newline-escape msgstr) - (parse-tree->assoc parse-tree))))))) + (parse-tree->assoc parse-tree))) + (('entry ('msgid msgid) ('msgstr msgstr)) + (acons (interpret-newline-escape msgid) + (interpret-newline-escape msgstr) + (parse-tree->assoc parse-tree))) + (('entry comments ('msgid msgid) ('msgstr msgstr)) + (if (member 'fuzzy (comments->flags comments)) + (parse-tree->assoc parse-tree) + (acons (interpret-newline-escape msgid) + (interpret-newline-escape msgstr) + (parse-tree->assoc parse-tree)))))))) =20 (define (read-po-file port) "Read a .po file from PORT and return an alist of msgid and msgstr." @@ -77,3 +112,71 @@ po-file (get-string-all port))))) (parse-tree->assoc tree))) + +(define (canonicalize-whitespace str) + "Change whitespace (newlines, etc.) in STR to @code{#\\space}." + (string-map (lambda (chr) + (if (char-set-contains? char-set:whitespace chr) + #\space + chr)) + str)) + +(define xref-regexp + ;; Texinfo cross-reference regexp. + (make-regexp "@(px|x)?ref\\{([^,}]+)")) + +(define (translate-cross-references texi pofile) + "Translate the cross-references that appear in @var{texi}, the initial +translation of a Texinfo file, using the msgid/msgstr pairs from @var{pofi= le}." + (define translations + (call-with-input-file pofile read-po-file)) + + (define content + (call-with-input-file texi get-string-all)) + + (define matches + (list-matches xref-regexp content)) + + (define translation-map + (fold (match-lambda* + (((msgid . str) result) + (vhash-cons msgid str result))) + vlist-null + translations)) + + (define translated + ;; Iterate over MATCHES and replace cross-references with their + ;; translation found in TRANSLATION-MAP. (We can't use + ;; 'substitute*' because matches can span multiple lines.) + (let loop ((matches matches) + (offset 0) + (result '())) + (match matches + (() + (string-concatenate-reverse + (cons (string-drop content offset) result))) + ((head . tail) + (let ((prefix (match:substring head 1)) + (ref (canonicalize-whitespace (match:substring head 2)))) + (define translated + (string-append "@" (or prefix "") + "ref{" + (match (vhash-assoc ref translation-map) + (#f ref) + ((_ . str) str)))) + + (loop tail + (match:end head) + (append (list translated + (string-take + (string-drop content offset) + (- (match:start head) offset))) + result))))))) + + (format (current-error-port) + "translated ~a cross-references in '~a'~%" + (length matches) texi) + + (call-with-output-file texi + (lambda (port) + (display translated port)))) diff --git a/guix/self.scm b/guix/self.scm index a0d448742a..8ada1d85a4 100644 --- a/guix/self.scm +++ b/guix/self.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2017, 2018, 2019, 2020, 2021 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2020 Martin Becze +;;; Copyright =C2=A9 2021 Julien Lepiller ;;; ;;; This file is part of GNU Guix. ;;; @@ -316,81 +317,23 @@ the result to OUTPUT." chr)) str)) =20 - (define xref-regexp - ;; Texinfo cross-reference regexp. - (make-regexp "@(px|x)?ref\\{([^,}]+)")) - - (define (translate-cross-references texi translations) - ;; Translate the cross-references that appear in TEXI, a Texin= fo - ;; file, using the msgid/msgstr pairs from TRANSLATIONS. - (define content - (call-with-input-file texi get-string-all)) - - (define matches - (list-matches xref-regexp content)) - - (define translation-map - (fold (match-lambda* - (((msgid . str) result) - (vhash-cons msgid str result))) - vlist-null - translations)) - - (define translated - ;; Iterate over MATCHES and replace cross-references with th= eir - ;; translation found in TRANSLATION-MAP. (We can't use - ;; 'substitute*' because matches can span multiple lines.) - (let loop ((matches matches) - (offset 0) - (result '())) - (match matches - (() - (string-concatenate-reverse - (cons (string-drop content offset) result))) - ((head . tail) - (let ((prefix (match:substring head 1)) - (ref (canonicalize-whitespace (match:substring= head 2)))) - (define translated - (string-append "@" (or prefix "") - "ref{" - (match (vhash-assoc ref translation-= map) - (#f ref) - ((_ . str) str)))) - - (loop tail - (match:end head) - (append (list translated - (string-take - (string-drop content offset) - (- (match:start head) offset))) - result))))))) - - (format (current-error-port) - "translated ~a cross-references in '~a'~%" - (length matches) texi) - (call-with-output-file texi - (lambda (port) - (display translated port)))) - (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'. EXTRA= S is a list of extra files, such as '(\"contributing\")." - (let ((translations (call-with-input-file po read-po-file))) - (for-each (lambda (file) - (translate-tmp-texi po (string-append file ".tex= i") - (string-append file "." lang - ".texi.tmp"))) - (cons prefix extras)) + (for-each (lambda (file) + (translate-tmp-texi po (string-append file ".texi") + (string-append file "." lang + ".texi.tmp"))) + (cons prefix extras)) =20 - (for-each (lambda (file) - (let* ((texi (string-append file "." lang ".texi= ")) - (tmp (string-append texi ".tmp"))) - (copy-file tmp texi) - (translate-cross-references texi - translations))) - (cons prefix extras)))) + (for-each (lambda (file) + (let* ((texi (string-append file "." lang ".texi")) + (tmp (string-append texi ".tmp"))) + (copy-file tmp texi) + (translate-cross-references texi po))) + (cons prefix extras))) =20 (define (available-translations directory domain) ;; Return the list of available translations under DIRECTORY f= or --=20 2.31.1 --MP_/9VvQuUbQh/xngZ4vfRMsCRY--