unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
blob d02dac9cbf34cebcbcff40f6f93c0493ff4a976b 3152 bytes (raw)
name: website/apps/i18n.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
 
;;; GNU Guix web site
;;; Copyright © 2019 Florian Pelz <pelzflorian@pelzflorian.de>
;;;
;;; This file is part of the GNU Guix web site.
;;;
;;; The GNU Guix web site is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU Affero General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; The GNU Guix web site 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 Affero General Public License for more details.
;;;
;;; You should have received a copy of the GNU Affero General Public License
;;; along with the GNU Guix web site.  If not, see <http://www.gnu.org/licenses/>.

(define-module (apps i18n)
  #:use-module (haunt page)
  #:use-module (haunt utils)
  #:use-module (ice-9 match)
  #:use-module (sexp-xgettext)
  #:use-module (srfi srfi-1)
  #:export (G_
            N_
            C_
            NC_
            %current-lingua
            %current-lang
            builder->localized-builder
            builders->localized-builders))

(define %gettext-domain
  "guix-website")

(bindtextdomain %gettext-domain (getcwd))
(bind-textdomain-codeset %gettext-domain "UTF-8")
(textdomain %gettext-domain)

;; NOTE: The sgettext macros have no hygiene because they use
;; datum->syntax and do not preserve the semantics of anything looking
;; like an sgettext macro.  This is an exceptional use case; do not
;; try this at home.

(define-syntax G_
  sgettext)

(set-simple-keywords! '(G_))

(define-syntax N_ ;like ngettext
  sngettext)

(define-syntax C_ ;like pgettext
  spgettext)

(define-syntax NC_ ;like npgettext
  snpgettext)

(set-complex-keywords! '(N_ C_ NC_))

(define <page>
  (@@ (haunt page) <page>))

(define %current-lingua
  (car (string-split (setlocale LC_ALL) #\.)))

(define %current-lang
  (car (string-split %current-lingua #\_)))

(define (first-value arg)
  "For some reason the builder returned by static-directory returns
multiple values.  This procedure is used to retain only the first
return value.  TODO: This should not be necessary."
  arg)

(define (builder->localized-builder builder)
  "Returns a Haunt builder procedure generated from an existing
BUILDER with translations for the current system locale coming from
sexp-xgettext."
  (compose
   (lambda (pages)
     (map
      (lambda (page)
        (match page
          (($ <page> file-name contents writer)
           (let ((new-name (string-append %current-lang
                                          "/"
                                          file-name)))
             (make-page new-name contents writer)))
          (else page)))
      pages))
   (lambda (site posts)
     (first-value (builder site posts)))))

(define (builders->localized-builders builders)
  "Returns a list of new Haunt builder procedures generated from
BUILDERS and localized via sexp-xgettext for the current system
locale."
  (flatten
   (map-in-order
    builder->localized-builder
    builders)))

debug log:

solving d02dac9 ...
found d02dac9 in https://yhetil.org/guix-bugs/20190906142548.4crfjgvxilgalgrs@pelzflorian.localdomain/

applying [1/1] https://yhetil.org/guix-bugs/20190906142548.4crfjgvxilgalgrs@pelzflorian.localdomain/
diff --git a/website/apps/i18n.scm b/website/apps/i18n.scm
new file mode 100644
index 0000000..d02dac9

Checking patch website/apps/i18n.scm...
Applied patch website/apps/i18n.scm cleanly.

index at:
100644 d02dac9cbf34cebcbcff40f6f93c0493ff4a976b	website/apps/i18n.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).