mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
locale: set LANG to the fallback value if we have invalid locale
See #201 for more information. Problem is that while we fall back to a default value to pass to `setlocale`, we don't set a `LANG` and instead reset it to `""`. What this does here is it changes the resetting to `""` and instead sets it to the default value.
This commit is contained in:
@ -35,16 +35,17 @@ pub fn ensureLocale() void {
|
|||||||
// If the locale is valid, we also use "" because LANG is already set.
|
// If the locale is valid, we also use "" because LANG is already set.
|
||||||
if (localeIsValid(new_lang)) break :locale "";
|
if (localeIsValid(new_lang)) break :locale "";
|
||||||
|
|
||||||
// If the locale is not valid, and our lang changed, then we reset
|
// If the locale is not valid we fall back to en_US.UTF-8 and need to
|
||||||
// to the old value.
|
// set LANG to this value too.
|
||||||
if (!std.mem.eql(u8, lang, new_lang)) {
|
const default_locale = "en_US.UTF-8";
|
||||||
if (setenv("LANG", lang.ptr, 1) < 0) {
|
log.info("LANG is not valid according to libc, will use en_US.UTF-8", .{});
|
||||||
log.err("error resetting locale env var", .{});
|
|
||||||
}
|
if (setenv("LANG", default_locale.ptr, 1) < 0) {
|
||||||
|
log.err("error setting LANG env var to {s}", .{default_locale});
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("LANG is not valid according to libc, will use en_US.UTF-8", .{});
|
// Use it as locale
|
||||||
break :locale "en_US.UTF-8";
|
break :locale default_locale;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set the locale
|
// Set the locale
|
||||||
|
Reference in New Issue
Block a user