Merge branch 'master' into 'core-updates'.
[jackhill/guix/guix.git] / gnu / system / locale.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (gnu system locale)
20 #:use-module (guix gexp)
21 #:use-module (guix records)
22 #:use-module (gnu packages base)
23 #:use-module (gnu packages compression)
24 #:use-module (srfi srfi-26)
25 #:export (locale-definition
26 locale-definition?
27 locale-definition-name
28 locale-definition-source
29 locale-definition-charset
30
31 locale-directory
32
33 %default-locale-definitions))
34
35 ;;; Commentary:
36 ;;;
37 ;;; Locale definitions, and compilation thereof.
38 ;;;
39 ;;; Code:
40
41 (define-record-type* <locale-definition> locale-definition
42 make-locale-definition
43 locale-definition?
44 (name locale-definition-name) ;string--e.g., "fr_FR.utf8"
45 (source locale-definition-source) ;string--e.g., "fr_FR"
46 (charset locale-definition-charset ;string--e.g., "UTF-8"
47 (default "UTF-8")))
48
49 (define* (localedef-command locale
50 #:key (libc (canonical-package glibc)))
51 "Return a gexp that runs 'localedef' from LIBC to build LOCALE."
52 #~(begin
53 (format #t "building locale '~a'...~%"
54 #$(locale-definition-name locale))
55 (zero? (system* (string-append #$libc "/bin/localedef")
56 "--no-archive" "--prefix" #$output
57 "-i" #$(locale-definition-source locale)
58 "-f" #$(locale-definition-charset locale)
59 (string-append #$output "/"
60 #$(locale-definition-name locale))))))
61
62 (define* (locale-directory locales
63 #:key (libc (canonical-package glibc)))
64 "Return a directory containing all of LOCALES compiled."
65 (define build
66 #~(begin
67 (mkdir #$output)
68
69 ;; 'localedef' executes 'gzip' to access compressed locale sources.
70 (setenv "PATH" (string-append #$gzip "/bin"))
71
72 (exit
73 (and #$@(map (cut localedef-command <> #:libc libc)
74 locales)))))
75
76 (gexp->derivation "locale" build
77 #:local-build? #t))
78
79 (define %default-locale-definitions
80 ;; Arbitrary set of locales that are built by default. They are here mostly
81 ;; to facilitate first-time use to some people, while others may have to add
82 ;; a specific <locale-definition>.
83 (letrec-syntax ((utf8-locale (syntax-rules ()
84 ((_ name*)
85 (locale-definition
86 (name (string-append name* ".utf8"))
87 (source name*)
88 (charset "UTF-8")))))
89 (utf8-locales (syntax-rules ()
90 ((_ name ...)
91 (list (utf8-locale name) ...)))))
92 (utf8-locales "ca_ES"
93 "cs_CZ"
94 "da_DK"
95 "de_DE"
96 "el_GR"
97 "en_AU"
98 "en_CA"
99 "en_GB"
100 "en_US"
101 "es_AR"
102 "es_CL"
103 "es_ES"
104 "es_MX"
105 "fi_FI"
106 "fr_BE"
107 "fr_CA"
108 "fr_CH"
109 "fr_FR"
110 "ga_IE"
111 "it_IT"
112 "ja_JP"
113 "ko_KR"
114 "nb_NO"
115 "nl_NL"
116 "pl_PL"
117 "pt_PT"
118 "ro_RO"
119 "ru_RU"
120 "sv_SE"
121 "tr_TR"
122 "uk_UA"
123 "vi_VN"
124 "zh_CN")))
125
126 ;;; locale.scm ends here