From patchwork Tue Jan 26 21:43:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Julien Lepiller X-Patchwork-Id: 26655 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 28B7427BC1C; Tue, 26 Jan 2021 21:44:11 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 7C9B027BC1B for ; Tue, 26 Jan 2021 21:44:10 +0000 (GMT) Received: from localhost ([::1]:45416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4W89-0004XF-HJ for patchwork@mira.cbaines.net; Tue, 26 Jan 2021 16:44:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4W81-0004Wt-UM for guix-patches@gnu.org; Tue, 26 Jan 2021 16:44:01 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:59515) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l4W81-0006J6-Md for guix-patches@gnu.org; Tue, 26 Jan 2021 16:44:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l4W81-0005yg-Kw for guix-patches@gnu.org; Tue, 26 Jan 2021 16:44:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#46114] [PATCH] website: Localize package list. Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 26 Jan 2021 21:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46114 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 46114-submit@debbugs.gnu.org id=B46114.161169740322924 (code B ref 46114); Tue, 26 Jan 2021 21:44:01 +0000 Received: (at 46114) by debbugs.gnu.org; 26 Jan 2021 21:43:23 +0000 Received: from localhost ([127.0.0.1]:42828 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l4W7O-0005xf-LX for submit@debbugs.gnu.org; Tue, 26 Jan 2021 16:43:23 -0500 Received: from lepiller.eu ([89.234.186.109]:55564) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l4W7K-0005xS-Kl for 46114@debbugs.gnu.org; Tue, 26 Jan 2021 16:43:20 -0500 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id 33be4afd; Tue, 26 Jan 2021 21:43:16 +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=1YBXORgVCjHf9I5QrCKmuTNT9iggydmk4gbGTg +xUNM=; b=kXi7iaGa1iVafY/4IAY8HNwWnlKpjMDcfKkQYRukew8uAbHT/Uox7Z QBgAHE//3dn6pEAfJwoOuDB4UseKxNHQWUi8kemkGlIiwygiKIyEzpjSsCmsFGPI DPel3A9OB9FgaF4MQX2WRQ1mUx/k7qeq2Cw8puZ6uK7uEfdoeLE99ANC2hJAh7FS rh+2tb9EUBEGOgZ+Iy0/yv25xBP4puaV73Qa4DcWE7AWTeQBjeVQt3MIjrVwt/m7 2CrP2wxF2Ei0Win9bm+GA3YhAYF5zCMd8zfhWa/S0pYA/SneTCNiB8L21vZolNii m11AYjh5MAkrb9blVdHQOUrrbD8VBN2A== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id a457e3af (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Tue, 26 Jan 2021 21:43:16 +0000 (UTC) Date: Tue, 26 Jan 2021 22:43:06 +0100 From: Julien Lepiller Message-ID: <20210126224306.08ebfa99@tachikoma.lepiller.eu> In-Reply-To: <87bldbxu82.fsf@gnu.org> References: <20210126175618.252a04e8@tachikoma.lepiller.eu> <87bldbxu82.fsf@gnu.org> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 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: , Cc: 46114@debbugs.gnu.org Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Le Tue, 26 Jan 2021 22:29:33 +0100, Ludovic Courtès a écrit : > Hi, > > Julien Lepiller skribis: > > > This patch lets us localize package synopsis and description in > > package lists. This is not super useful, because our guix-packages > > domain is almost untranslated, for every language, but I think it's > > better than nothing. > > Yes, good idea. > > > Locally, you can simply copy an existing guix-packages.mo (on the > > Guix System, > > /run/current-system/profile/share/locale/de/LC_MESSAGES/guix-packages.mo > > for the German translation) to the local locale directory > > (de/LC_MESSAGES/guix-packages.mo), in the same way we do for the > > guix-website domain. > > > > I also modified .guix.scm so the website can be generated with > > localized packages. I used the latest guix package from the current > > guix, because latest-guix (defined in .guix.scm) does not have any > > locale information in it (mo or po). Any idea to get the latest > > translations instead? > > ‘latest-guix’ is the same as what you get with ‘guix pull’, so it > knows where to find its .gmo files—see this bit in (guix self): > > (bindtextdomain "guix" > #$(locale-data source "guix")) > (bindtextdomain "guix-packages" > #$(locale-data source > "guix-packages" > "packages")) yeah, but that's not very helpful. I don't understand how to get them from guix-latest? > > Now, you sent the wrong patch. :-) haha, indeed ^^' > > Ludo’. From ee20fd1a63914b9f3d13afb061b2192d65a26ee7 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Tue, 26 Jan 2021 17:48:47 +0100 Subject: [PATCH] website: Localize package list. * .guix.scm: Copy guix-packages gettext domain locally. * apps/i18n.scm: Bind the guix-packages gettext domain. * apps/packages/templates/components.scm (package-preview): Localize package description. * apps/packages/utils.scm (package-description-shtml, package-synopsis-shtml): Localize package synopsis and description. * i18n-howto.txt: Document package list localization. --- website/.guix.scm | 21 +++++++++++++++++-- website/apps/i18n.scm | 3 +++ .../apps/packages/templates/components.scm | 4 +++- website/apps/packages/utils.scm | 7 +++++-- website/i18n-howto.txt | 7 ++++++- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/website/.guix.scm b/website/.guix.scm index 5f5c570..f656d47 100644 --- a/website/.guix.scm +++ b/website/.guix.scm @@ -33,6 +33,7 @@ (use-modules (guix) (gnu) (gnu packages guile) (gnu packages guile-xyz) + (gnu packages package-management) (guix modules) (guix git-download) (guix gexp) @@ -145,7 +146,13 @@ "/bin/msgfmt")) (lingua-file (string-append "po/" lingua ".po")) (lang (car (string-split lingua #\_))) - (lang-file (string-append "po/" lang ".po"))) + (lang-file (string-append "po/" 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"))) (define (create-mo filename) (begin (invoke msgfmt filename) @@ -158,7 +165,17 @@ (create-mo lingua-file)) ((file-exists? lang-file) (create-mo lang-file)) - (else #t)))) + (else #t)) + (cond + ((file-exists? packages-lingua-mo) + (copy-file packages-lingua-mo + (string-append lingua "/LC_MESSAGES/" + "guix-packages.mo"))) + ((file-exists? packages-lang-mo) + (copy-file packages-lang-mo + (string-append lingua "/LC_MESSAGES/" + "guix-packages.mo"))) + (else #t)))) (list #$@%linguas)) ;; So we can read/write UTF-8 files. diff --git a/website/apps/i18n.scm b/website/apps/i18n.scm index d88333a..09f275e 100644 --- a/website/apps/i18n.scm +++ b/website/apps/i18n.scm @@ -20,6 +20,7 @@ #:use-module (haunt asset) #:use-module (haunt page) #:use-module (haunt utils) + #:use-module ((guix i18n) #:select (%package-text-domain)) #:use-module (ice-9 match) #:use-module (sexp-xgettext) #:use-module (srfi srfi-1) @@ -41,6 +42,8 @@ (bindtextdomain %gettext-domain (getcwd)) (bind-textdomain-codeset %gettext-domain "UTF-8") (textdomain %gettext-domain) +(bindtextdomain %package-text-domain (getcwd)) +(bind-textdomain-codeset %package-text-domain "UTF-8") ;; NOTE: The sgettext macros have no hygiene because they use ;; datum->syntax and do not preserve the semantics of anything looking diff --git a/website/apps/packages/templates/components.scm b/website/apps/packages/templates/components.scm index 565b408..785b01a 100644 --- a/website/apps/packages/templates/components.scm +++ b/website/apps/packages/templates/components.scm @@ -14,6 +14,7 @@ #:use-module (apps packages utils) #:use-module (guix licenses) #:use-module (guix packages) + #:use-module ((guix i18n) #:select (P_)) #:use-module (guix gnu-maintenance) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) @@ -186,7 +187,8 @@ (p (@ (class "item-summary")) ,(string-summarize - (stexi->plain-text (texi-fragment->stexi (package-description package))) + (stexi->plain-text + (texi-fragment->stexi (P_ (package-description package)))) 30) "…"))) diff --git a/website/apps/packages/utils.scm b/website/apps/packages/utils.scm index 66edfc6..2a1be86 100644 --- a/website/apps/packages/utils.scm +++ b/website/apps/packages/utils.scm @@ -24,9 +24,11 @@ (define-module (apps packages utils) #:use-module (apps aux web) #:use-module (apps base utils) + #:use-module (apps i18n) #:use-module (apps packages data) #:use-module (apps packages types) #:use-module (guix packages) + #:use-module ((guix i18n) #:select (P_)) #:use-module (guix utils) #:use-module (guix build utils) #:use-module (guix build download) @@ -92,12 +94,13 @@ (define (package-description-shtml package) "Return a SXML representation of PACKAGE description field with HTML vocabulary." - (and=> (package-description package) texinfo->shtml)) + ;(setenv "LC_ALL" (getenv "LANG")) + (and=> (and=> (package-description package) P_) texinfo->shtml)) (define (package-synopsis-shtml package) "Return a SXML representation of PACKAGE synopsis field with HTML vocabulary." - (and=> (package-synopsis package) + (and=> (and=> (package-synopsis package) P_) (lambda (synopsis) ;; Strip the paragraph that 'texinfo->shtml' adds. (match (texinfo->shtml synopsis) diff --git a/website/i18n-howto.txt b/website/i18n-howto.txt index 9ec8e81..1cf836b 100644 --- a/website/i18n-howto.txt +++ b/website/i18n-howto.txt @@ -70,11 +70,16 @@ msgfmt de.po cd .. mv po/messages.mo de/LC_MESSAGES/guix-website.mo +To translate package synopsis and descriptions, you will need the guix-packages +domain. On the Guix System, you can copy one from your installation: + +cp /run/current-system/profile/share/locale/de/LC_MESSAGES/guix-packages.mo de/LC_MESSAGES/ + To build all languages: guix build -f .guix.scm -To test the de_DE translation, update its mo file as above, then: +To test the de_DE translation, update its mo files as above, then: guix environment --ad-hoc haunt LC_ALL=de_DE.utf8 \ -- 2.30.0