guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

06/06: installer: Sort keyboard layouts according to language and transl


From: guix-commits
Subject: 06/06: installer: Sort keyboard layouts according to language and translations.
Date: Wed, 17 Apr 2019 09:32:54 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 9015e63996156dfaafecef182d20128f268c2719
Author: Ludovic Courtès <address@hidden>
Date:   Wed Apr 17 15:16:08 2019 +0200

    installer: Sort keyboard layouts according to language and translations.
    
    Previously, we would always (1) put English first, and (2) sort the
    other layouts based on their English description.  This fixes both
    issues.
    
    * gnu/installer/newt/keymap.scm (sort-layouts)[layout<?]: New procedure.
    [preferred]: New variable.
    Partition according to both the 'name' and 'synopsis' fields.  Sort both
    the main layouts and the other layouts according to 'layout<?'.
---
 gnu/installer/newt/keymap.scm | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/gnu/installer/newt/keymap.scm b/gnu/installer/newt/keymap.scm
index 623bfe0..2908ba7 100644
--- a/gnu/installer/newt/keymap.scm
+++ b/gnu/installer/newt/keymap.scm
@@ -28,6 +28,7 @@
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-34)
   #:use-module (srfi srfi-35)
+  #:use-module (ice-9 i18n)
   #:use-module (ice-9 match)
   #:export (run-keymap-page
             keyboard-layout->configuration))
@@ -64,14 +65,29 @@
 
 (define (sort-layouts layouts)
   "Sort LAYOUTS list by putting the US layout ahead and return it."
+  (define (layout<? layout1 layout2)
+    (let ((text1 (x11-keymap-layout-description layout1))
+          (text2 (x11-keymap-layout-description layout2)))
+      ;; XXX: We're calling 'gettext' more than once per item.
+      (string-locale<? (gettext text1 "xkeyboard-config")
+                       (gettext text2 "xkeyboard-config"))))
+
+  (define preferred
+    ;; Two-letter language tag for the preferred keyboard layout.
+    (or (getenv "LANGUAGE") "us"))
+
   (call-with-values
       (lambda ()
         (partition
          (lambda (layout)
-           (let ((name (x11-keymap-layout-name layout)))
-             (string=? name "us")))
+           ;; The 'synopsis' field is usually a language code (e.g., "en")
+           ;; while the 'name' field is a country code (e.g., "us").
+           (or (string=? (x11-keymap-layout-name layout) preferred)
+               (string=? (x11-keymap-layout-synopsis layout) preferred)))
          layouts))
-    (cut append <> <>)))
+    (lambda (main others)
+      (append (sort main layout<?)
+              (sort others layout<?)))))
 
 (define (sort-variants variants)
   "Sort VARIANTS list by putting the international variant ahead and return 
it."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]