1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu system locale)
20 #:use-module (guix gexp)
21 #:use-module (guix records)
22 #:use-module (guix packages)
23 #:use-module (gnu packages base)
24 #:use-module (gnu packages compression)
25 #:use-module (srfi srfi-26)
26 #:export (locale-definition
28 locale-definition-name
29 locale-definition-source
30 locale-definition-charset
34 %default-locale-definitions))
38 ;;; Locale definitions, and compilation thereof.
42 (define-record-type* <locale-definition> locale-definition
43 make-locale-definition
45 (name locale-definition-name) ;string--e.g., "fr_FR.utf8"
46 (source locale-definition-source) ;string--e.g., "fr_FR"
47 (charset locale-definition-charset ;string--e.g., "UTF-8"
50 (define* (localedef-command locale
51 #:key (libc (canonical-package glibc)))
52 "Return a gexp that runs 'localedef' from LIBC to build LOCALE."
54 (format #t "building locale '~a'...~%"
55 #$(locale-definition-name locale))
56 (zero? (system* (string-append #$libc "/bin/localedef")
57 "--no-archive" "--prefix" #$output
58 "-i" #$(locale-definition-source locale)
59 "-f" #$(locale-definition-charset locale)
60 (string-append #$output "/"
61 #$(package-version libc) "/"
62 #$(locale-definition-name locale))))))
64 (define* (locale-directory locales
65 #:key (libc (canonical-package glibc)))
66 "Return a directory containing all of LOCALES for LIBC compiled.
68 Because locale data formats are incompatible when switching from one libc to
69 another, locale data is put in a sub-directory named after the 'version' field
74 (mkdir (string-append #$output "/" #$(package-version libc)))
76 ;; 'localedef' executes 'gzip' to access compressed locale sources.
77 (setenv "PATH" (string-append #$gzip "/bin"))
80 (and #$@(map (cut localedef-command <> #:libc libc)
83 (gexp->derivation "locale" build
86 (define %default-locale-definitions
87 ;; Arbitrary set of locales that are built by default. They are here mostly
88 ;; to facilitate first-time use to some people, while others may have to add
89 ;; a specific <locale-definition>.
90 (letrec-syntax ((utf8-locale (syntax-rules ()
93 ;; Note: We choose "utf8", which is the
94 ;; "normalized codeset".
95 (name (string-append name* ".utf8"))
98 (utf8-locales (syntax-rules ()
100 (list (utf8-locale name) ...)))))
101 ;; Add "en_US.UTF-8" for compatibility with Guix 0.8.
102 (cons (locale-definition
106 (utf8-locales "ca_ES"
140 ;;; locale.scm ends here