diff mbox series

[bug#46114] website: Localize package list.

Message ID 20210126224306.08ebfa99@tachikoma.lepiller.eu
State Accepted
Headers show
Series [bug#46114] website: Localize package list. | expand

Checks

Context Check Description
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Julien Lepiller Jan. 26, 2021, 9:43 p.m. UTC
Le Tue, 26 Jan 2021 22:29:33 +0100,
Ludovic Courtès <ludo@gnu.org> a écrit :

> Hi,
> 
> Julien Lepiller <julien@lepiller.eu> 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’.

Comments

Ludovic Courtès Jan. 27, 2021, 10:18 p.m. UTC | #1
Hi,

Julien Lepiller <julien@lepiller.eu> skribis:

> Le Tue, 26 Jan 2021 22:29:33 +0100,
> Ludovic Courtès <ludo@gnu.org> a écrit :

[...]

>> ‘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?

Oh you need the .mo files so you can ‘bindtextdomain’ hmmm…

It would be easier if the web site used the inferior API; you would
delegate translation to the inferior and that’s it.

> From ee20fd1a63914b9f3d13afb061b2192d65a26ee7 Mon Sep 17 00:00:00 2001
> From: Julien Lepiller <julien@lepiller.eu>
> 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.

[...]

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

So we copy them for the sake of ‘bindtextdomain’, right?

In practice those .mo files should be the same as what you’d get via
‘latest-guix’ so that’s probably fine.

Why “lingua” and “lang” BTW?


[...]

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

Leftover.  :-)

LGTM, thanks!

Ludo’.
Julien Lepiller Jan. 29, 2021, 1:52 a.m. UTC | #2
Le Wed, 27 Jan 2021 23:18:02 +0100,
Ludovic Courtès <ludo@gnu.org> a écrit :
> 
> So we copy them for the sake of ‘bindtextdomain’, right?
> 
> In practice those .mo files should be the same as what you’d get via
> ‘latest-guix’ so that’s probably fine.
> 
> Why “lingua” and “lang” BTW?

I simply copied the same template as for the po file. I think lingua
contains the specific language+territory code, whearas lang contains
only the language code. If we have a specific translation, we want to
use it, otherwise we use the generic one for the language.

> 
> 
> [...]
> 
> >  (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"))  
> 
> Leftover.  :-)

Fixed.

> 
> LGTM, thanks!
> 
> Ludo’.

Pushed as f56e35bbd34aca09b67c3623fcd9b05cc0467d6f, thank you!
Julien Lepiller Jan. 29, 2021, 1:53 a.m. UTC | #3
Forgot to close :)
diff mbox series

Patch

From ee20fd1a63914b9f3d13afb061b2192d65a26ee7 Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
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