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
| | ;;; 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 (srfi srfi-1)
#:export (G_
%current-lingua
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)
(define* (G_ msg msgctxt)
(if msgctxt
(gettext (string-append msgctxt "|" msg) %gettext-domain)
(gettext msg %gettext-domain)))
(define <page>
(@@ (haunt page) <page>))
(define %current-lingua
(make-fluid "en_US"))
(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 I THINK"
arg)
(define (builder->localized-builder builder lingua)
(compose
(lambda (pages)
(map
(lambda (page)
(match page
(($ <page> file-name contents writer)
(if (string-suffix? ".html" file-name)
(let* ((base (string-drop-right
file-name
(string-length ".html")))
(new-name (string-append base
"."
lingua
".html")))
(make-page new-name contents writer))
page))
(else page)))
pages))
(lambda (site posts)
(begin
(setlocale LC_ALL (string-append lingua ".utf8"))
(with-fluid*
%current-lingua lingua
(lambda _
(begin
(first-value (builder site posts)))))))))
(define (builders->localized-builders builders linguas)
(flatten
(map-in-order
(lambda (builder)
(map-in-order
(lambda (lingua)
(builder->localized-builder builder lingua))
linguas))
builders)))
|