From b6a3a1222912bef89f109fec4174febb43944fae Mon Sep 17 00:00:00 2001 From: Vivien Kraus Date: Thu, 30 Sep 2021 22:35:48 +0200 Subject: web i18n: handle locales such as en-gb The region may not be in capital letters --- src/scm/webid-oidc/web-i18n.scm | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/scm/webid-oidc/web-i18n.scm b/src/scm/webid-oidc/web-i18n.scm index 54d0c36..978e6a4 100644 --- a/src/scm/webid-oidc/web-i18n.scm +++ b/src/scm/webid-oidc/web-i18n.scm @@ -51,7 +51,7 @@ ((? string? (= (cute string-split <> #\-) ((? string? lang) - (? string? region)))) + (? string? (= string-upcase region))))) (format #f "~a_~a.UTF-8" lang region)) (else ""))) @@ -67,22 +67,24 @@ ;; Translation done, nothing to do out)) +(define (set-lc-all locale) + (catch #t + (lambda () + (setlocale LC_ALL locale)) + (lambda error + (setlocale LC_ALL "C")))) + (define (web-gettext str) (let ((out (with-mutex locale-mutex (let ((previous-locale (setlocale LC_ALL))) (dynamic-wind (lambda () - (with-exception-handler - (lambda (exn) - (setlocale LC_ALL "C")) - (lambda () - (setlocale LC_ALL (web-locale))) - #:unwind? #t)) + (set-lc-all (web-locale))) (lambda () (gettext str)) (lambda () - (setlocale LC_ALL previous-locale))))))) + (set-lc-all previous-locale))))))) (disambiguate str out))) (define (sysadmin-gettext str) -- cgit v1.2.3