unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Mark H Weaver <mhw@netris.org>
Cc: 22572@debbugs.gnu.org
Subject: bug#22572: Handling of system 'locale' field needs improvement
Date: Sun, 07 Feb 2016 22:19:42 +0100	[thread overview]
Message-ID: <871t8orzf5.fsf@gnu.org> (raw)
In-Reply-To: <87k2mhudex.fsf@netris.org> (Mark H. Weaver's message of "Sat, 06 Feb 2016 09:22:14 -0500")

[-- Attachment #1: Type: text/plain, Size: 590 bytes --]

Mark H Weaver <mhw@netris.org> skribis:

> Better yet, the value of the 'locale' field should be automatically
> added to the default value of 'locale-definitions' if it's not already
> there.  The overwhelming majority of users set their 'locale' and have
> no interest in 'locale-definitions'.

What about this?  This is not ideal in that it guesses the charset based
on the locale name, which won’t always work (the locale name is supposed
to use the normalized name, like “utf8”, whereas the real name is, say,
“UTF-8”), but it should cover 90% of the use cases.


[-- Attachment #2: Type: text/x-patch, Size: 4295 bytes --]

diff --git a/doc/guix.texi b/doc/guix.texi
index 66ab384..f35a9fe 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -6452,11 +6452,12 @@ Usually, you will want to specify the default locale for the machine
 using the @code{locale} field of the @code{operating-system} declaration
 (@pxref{operating-system Reference, @code{locale}}).
 
-That locale must be among the @dfn{locale definitions} that are known to
-the system---and these are specified in the @code{locale-definitions}
-slot of @code{operating-system}.  The default value includes locale
-definitions for some widely used locales, but not for all the available
-locales, in order to save space.
+The selected locale is automatically added to the @dfn{locale
+definitions} known to the system.  Additional locale definitions can be
+specified in the @code{locale-definitions} slot of
+@code{operating-system}.  The default value includes locale definitions
+for some widely used locales, but not for all the available locales, in
+order to save space.
 
 If the locale specified in the @code{locale} field is not among the
 definitions listed in @code{locale-definitions}, @command{guix system}
diff --git a/gnu/system.scm b/gnu/system.scm
index d4759a0..324d071 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -669,14 +669,25 @@ hardware-related operations as necessary when booting a Linux container."
   "Return the directory containing the locales compiled for the definitions
 listed in OS.  The C library expects to find it under
 /run/current-system/locale."
-  ;; While we're at it, check whether the locale of OS is defined.
-  (unless (member (operating-system-locale os)
-                  (map locale-definition-name
-                       (operating-system-locale-definitions os)))
-    (raise (condition
-            (&message (message "system locale lacks a definition")))))
+  (define name
+    (operating-system-locale os))
 
-  (locale-directory (operating-system-locale-definitions os)
+  (define definitions
+    ;; While we're at it, check whether the locale of OS is defined.
+    (if (member (operating-system-locale os)
+                (map locale-definition-name
+                     (operating-system-locale-definitions os)))
+        (operating-system-locale-definitions os)
+        (cons (match (locale-name->definition name)
+                (#f
+                 (raise (condition
+                         (&message
+                          (message (format #f (_ "~a: invalid locale name")
+                                           name))))))
+                (def def))
+              (operating-system-locale-definitions os))))
+
+  (locale-directory definitions
                     #:libcs (operating-system-locale-libcs os)))
 
 (define (kernel->grub-label kernel)
diff --git a/gnu/system/locale.scm b/gnu/system/locale.scm
index e798827..9d695b3 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,22 @@
   (charset locale-definition-charset              ;string--e.g., "UTF-8"
            (default "UTF-8")))
 
+(define %not-dot
+  (char-set-complement (char-set #\.)))
+
+(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)
+     (locale-definition (name name)
+                        (source source)
+                        (charset (if (string-ci=? charset "utf8")
+                                     "UTF-8"
+                                     charset))))
+    (_
+     #f)))
+
 (define* (localedef-command locale
                             #:key (libc (canonical-package glibc)))
   "Return a gexp that runs 'localedef' from LIBC to build LOCALE."

[-- Attachment #3: Type: text/plain, Size: 21 bytes --]


Thanks,
Ludo’.

  reply	other threads:[~2016-02-07 21:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-06 14:22 bug#22572: Handling of system 'locale' field needs improvement Mark H Weaver
2016-02-07 21:19 ` Ludovic Courtès [this message]
2016-02-10 14:20   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871t8orzf5.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=22572@debbugs.gnu.org \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).