diff mbox series

[bug#37413,5/9] ui: Add 'current-message-language'.

Message ID 20190915222106.4463-5-ludo@gnu.org
State Accepted
Headers show
Series None | expand

Commit Message

Ludovic Courtès Sept. 15, 2019, 10:21 p.m. UTC
* guix/ui.scm (%default-message-language): New variable.
(current-message-language): New procedure.
---
 guix/ui.scm | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/guix/ui.scm b/guix/ui.scm
index 7920335928..42043b546c 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -120,6 +120,10 @@ 
             roll-back*
             switch-to-generation*
             delete-generation*
+
+            %default-message-language
+            current-message-language
+
             run-guix-command
             run-guix
             guix-main))
@@ -427,6 +431,20 @@  exiting.  ARGS is the list of arguments received by the 'throw' handler."
 report them in a user-friendly way."
   (call-with-unbound-variable-handling (lambda () exp ...)))
 
+(define %default-message-language
+  ;; Default language to use for messages.
+  (make-parameter "en"))
+
+(define (current-message-language)
+  "Return the language used for messages according to the current locale.
+Return %DEFAULT-MESSAGE-LANGUAGE if that information could not be obtained.  The
+result is an ISO-639-2 language code such as \"ar\", without the territory
+part."
+  (let ((locale (setlocale LC_MESSAGES)))
+    (match (string-index locale #\_)
+      (#f    locale)
+      (index (string-take locale index)))))
+
 (define (install-locale)
   "Install the current locale settings."
   (catch 'system-error