guix-commits
[Top][All Lists]
Advanced

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

02/02: website: Localize package list.


From: julien lepiller
Subject: 02/02: website: Localize package list.
Date: Thu, 28 Jan 2021 20:50:33 -0500 (EST)

roptat pushed a commit to branch master
in repository guix-artwork.

commit f56e35bbd34aca09b67c3623fcd9b05cc0467d6f
Author: Julien Lepiller <julien@lepiller.eu>
AuthorDate: Tue Jan 26 17:48:47 2021 +0100

    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 +++
 website/apps/packages/templates/components.scm |  4 +++-
 website/apps/packages/utils.scm                |  6 ++++--
 website/i18n-howto.txt                         |  7 ++++++-
 5 files changed, 35 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..aca6ae6 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,12 @@
 (define (package-description-shtml package)
   "Return a SXML representation of PACKAGE description field with HTML
 vocabulary."
-  (and=> (package-description package) texinfo->shtml))
+  (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 \



reply via email to

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