summary refs log tree commit diff
path: root/gnu/system
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-02-10 11:01:54 +0100
committerLudovic Courtès <ludo@gnu.org>2016-02-10 15:15:17 +0100
commitf5582b2c1d7cb73f36d5278bec99d7279f813a39 (patch)
tree1af4e61e8aa258338e4eeb9e0b5d4c78fe3a7a8f /gnu/system
parent32e16112064ae3f7bad729802834c965b270bbc0 (diff)
downloadguix-f5582b2c1d7cb73f36d5278bec99d7279f813a39.tar.gz
system: Selected locale is automatically built.
Fixes <http://bugs.gnu.org/22572>.
Reported by Mark H Weaver <mhw@netris.org>.

* gnu/system/locale.scm (%not-dot): New variable.
(denormalize-codeset, locale-name->definition): New procedures.
* gnu/system.scm (locale-name->definition*): New procedure.
(operating-system-locale-directory): Instead of raising an error, add
the missing locale.
* doc/guix.texi (Locales): Adjust accordingly.
Diffstat (limited to 'gnu/system')
-rw-r--r--gnu/system/locale.scm32
1 files changed, 31 insertions, 1 deletions
diff --git a/gnu/system/locale.scm b/gnu/system/locale.scm
index e798827a01..f9d713e0cf 100644
--- a/gnu/system/locale.scm
+++ b/gnu/system/locale.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -33,6 +33,7 @@
             locale-definition-source
             locale-definition-charset
 
+            locale-name->definition
             locale-directory
 
             %default-locale-libcs
@@ -52,6 +53,35 @@
   (charset locale-definition-charset              ;string--e.g., "UTF-8"
            (default "UTF-8")))
 
+(define %not-dot
+  (char-set-complement (char-set #\.)))
+
+(define (denormalize-codeset codeset)
+  "Attempt to guess the \"real\" name of CODESET, a normalized codeset as
+defined in (info \"(libc) Using gettextized software\")."
+  (cond ((string=? codeset "utf8")
+         "UTF-8")
+        ((string-prefix? "iso8859" codeset)
+         (string-append "ISO-8859-" (string-drop codeset 7)))
+        ((string=? codeset "eucjp")
+         "EUC-JP")
+        (else                                ;cross fingers, hope for the best
+         codeset)))
+
+(define (locale-name->definition name)
+  "Return a <locale-definition> corresponding to NAME, guessing the charset,
+or #f on failure."
+  (match (string-tokenize name %not-dot)
+    ((source charset)
+     ;; XXX: NAME is supposed to use the "normalized codeset", such as "utf8",
+     ;; whereas the actual name used is different.  Add a special case to make
+     ;; the right guess for UTF-8.
+     (locale-definition (name name)
+                        (source source)
+                        (charset (denormalize-codeset charset))))
+    (_
+     #f)))
+
 (define* (localedef-command locale
                             #:key (libc (canonical-package glibc)))
   "Return a gexp that runs 'localedef' from LIBC to build LOCALE."