Commit | Line | Data |
---|---|---|
598e19dc | 1 | ;;; GNU Guix --- Functional package management for GNU |
24004073 | 2 | ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org> |
598e19dc LC |
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))) | |
1cc8f3a6 | 51 | "Return a gexp that runs 'localedef' from LIBC to build LOCALE." |
598e19dc LC |
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 | |
b2636518 LC |
86 | ;; Note: We choose "utf8", which is the |
87 | ;; "normalized codeset". | |
598e19dc LC |
88 | (name (string-append name* ".utf8")) |
89 | (source name*) | |
90 | (charset "UTF-8"))))) | |
91 | (utf8-locales (syntax-rules () | |
92 | ((_ name ...) | |
93 | (list (utf8-locale name) ...))))) | |
24004073 LC |
94 | ;; Add "en_US.UTF-8" for compatibility with Guix 0.8. |
95 | (cons (locale-definition | |
96 | (name "en_US.UTF-8") | |
97 | (source "en_US") | |
98 | (charset "UTF-8")) | |
99 | (utf8-locales "ca_ES" | |
100 | "cs_CZ" | |
101 | "da_DK" | |
102 | "de_DE" | |
103 | "el_GR" | |
104 | "en_AU" | |
105 | "en_CA" | |
106 | "en_GB" | |
107 | "en_US" | |
108 | "es_AR" | |
109 | "es_CL" | |
110 | "es_ES" | |
111 | "es_MX" | |
112 | "fi_FI" | |
113 | "fr_BE" | |
114 | "fr_CA" | |
115 | "fr_CH" | |
116 | "fr_FR" | |
117 | "ga_IE" | |
118 | "it_IT" | |
119 | "ja_JP" | |
120 | "ko_KR" | |
121 | "nb_NO" | |
122 | "nl_NL" | |
123 | "pl_PL" | |
124 | "pt_PT" | |
125 | "ro_RO" | |
126 | "ru_RU" | |
127 | "sv_SE" | |
128 | "tr_TR" | |
129 | "uk_UA" | |
130 | "vi_VN" | |
131 | "zh_CN")))) | |
598e19dc LC |
132 | |
133 | ;;; locale.scm ends here |