mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-17 05:33:52 -04:00
main: display warning only, when we succeed in enabling a fallback locale
This commit is contained in:
parent
820b15b844
commit
2bc77ebf09
1 changed files with 21 additions and 12 deletions
33
main.c
33
main.c
|
|
@ -434,26 +434,35 @@ main(int argc, char *const *argv)
|
||||||
if (check_config)
|
if (check_config)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
user_notification_add_fmt(&user_notifications, USER_NOTIFICATION_ERROR,
|
static const char fallback_locales[][12] = {
|
||||||
"locale '%s' is not UTF-8", locale);
|
"C.UTF-8",
|
||||||
|
"en_US.UTF-8",
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to force an UTF-8 locale. If we succeed, launch the
|
* Try to force an UTF-8 locale. If we succeed, launch the
|
||||||
* user’s shell as usual, but add a user-notification saying
|
* user’s shell as usual, but add a user-notification saying
|
||||||
* the locale has been changed.
|
* the locale has been changed.
|
||||||
*/
|
*/
|
||||||
if (setlocale(LC_CTYPE, "C.UTF-8") != NULL) {
|
for (size_t i = 0; i < ALEN(fallback_locales); i++) {
|
||||||
user_notification_add(
|
const char *const fallback_locale = fallback_locales[i];
|
||||||
&user_notifications, USER_NOTIFICATION_WARNING,
|
|
||||||
xstrdup("locale forcibly changed to C.UTF-8"));
|
if (setlocale(LC_CTYPE, fallback_locale) != NULL) {
|
||||||
bad_locale = false;
|
user_notification_add_fmt(
|
||||||
|
&user_notifications, USER_NOTIFICATION_WARNING,
|
||||||
|
"locale '%s' is not UTF-8, using '%s' instead",
|
||||||
|
locale, fallback_locale);
|
||||||
|
bad_locale = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (setlocale(LC_CTYPE, "en_US.UTF-8") != NULL) {
|
if (bad_locale) {
|
||||||
user_notification_add(
|
user_notification_add_fmt(
|
||||||
&user_notifications, USER_NOTIFICATION_WARNING,
|
&user_notifications, USER_NOTIFICATION_ERROR,
|
||||||
xstrdup("locale forcibly changed to en_US.UTF-8"));
|
"locale '%s' is not UTF-8, "
|
||||||
bad_locale = false;
|
"and failed to enable a fallback locale",
|
||||||
|
locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue