From 827bfef5508ba454992011a61ca6c6e3ed4767f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 11 Jan 2022 21:37:03 +0100 Subject: [PATCH] =?UTF-8?q?main:=20try=20to=20force=20an=20UTF-8=20locale?= =?UTF-8?q?=20if=20user=E2=80=99s=20locale=20isn=E2=80=99t=20UTF-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main.c b/main.c index 15ddbb00..b90c4b25 100644 --- a/main.c +++ b/main.c @@ -436,6 +436,25 @@ main(int argc, char *const *argv) user_notification_add_fmt(&user_notifications, USER_NOTIFICATION_ERROR, "locale '%s' is not UTF-8", locale); + + /* + * Try to force an UTF-8 locale. If we succeed, launch the + * user’s shell as usual, but add a user-notification saying + * the locale has been changed. + */ + if (setlocale(LC_CTYPE, "C.UTF-8") != NULL) { + user_notification_add( + &user_notifications, USER_NOTIFICATION_WARNING, + xstrdup("locale forcibly changed to C.UTF-8")); + bad_locale = false; + } + + else if (setlocale(LC_CTYPE, "en_US.UTF-8") != NULL) { + user_notification_add( + &user_notifications, USER_NOTIFICATION_WARNING, + xstrdup("locale forcibly changed to en_US.UTF-8")); + bad_locale = false; + } } struct config conf = {NULL};