summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-09-15 17:54:05 +0200
committerLudovic Courtès <ludo@gnu.org>2019-09-23 10:38:44 +0200
commita725504a3a2f855c6a618e9b4cd222df91901113 (patch)
tree9ad9c10fb557bf7b71967afde383bb04b70deed3
parent9719e8d37aaa63e1c8f9d4ab1e28d49e2e56d85b (diff)
ui: Add 'current-message-language'.
* guix/ui.scm (%default-message-language): New variable. (current-message-language): New procedure.
-rw-r--r--guix/ui.scm18
1 files changed, 18 insertions, 0 deletions
diff --git a/guix/ui.scm b/guix/ui.scm
index 4be31db047..069d542131 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -121,6 +121,10 @@
roll-back*
switch-to-generation*
delete-generation*
+
+ %default-message-language
+ current-message-language
+
run-guix-command
run-guix
guix-main))
@@ -428,6 +432,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