Skip to content

Commit

Permalink
macOS: only set LANGUAGE for app bundle, do not inherit in termio env (
Browse files Browse the repository at this point in the history
…ghostty-org#6648)

Fixes ghostty-org#6633

For macOS, we set LANGUAGE to the priority list of preferred languages
for the app bundle, using the GNU gettext priority list format (colon
separated list of language codes).

This previously was inherited by the termio env. At first, this was by
design, but this has inherent flaws. Namely, the priority list format is
a GNU gettext specific format, and programs that use alternate gettext
implementations (like musl or Python) do not understand it and actually
do the wrong thing (not their fault!).

This change removes the inheritance of LANGUAGE in the termio env. To
make it extra safe, we only do set and unset LANGUAGE when we know we
launch from an app bundle. That was always the desired behavior but this
makes it more explicit.
  • Loading branch information
mitchellh authored Mar 10, 2025
2 parents 843cc83 + ebffe29 commit 480b1a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/apprt/embedded.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,13 @@ pub const Surface = struct {

// Remove this so that running `ghostty` within Ghostty works.
env.remove("GHOSTTY_MAC_APP");

// If we were launched from the desktop then we want to
// remove the LANGUAGE env var so that we don't inherit
// our translation settings for Ghostty. If we aren't from
// the desktop then we didn't set our LANGUAGE var so we
// don't need to remove it.
if (internal_os.launchedFromDesktop()) env.remove("LANGUAGE");
}

return env;
Expand Down
36 changes: 20 additions & 16 deletions src/os/locale.zig
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,26 @@ fn setLangFromCocoa() void {
}

// Get our preferred languages and set that to the LANGUAGE
// env var in case our language differs from our locale.
var buf: [1024]u8 = undefined;
if (preferredLanguageFromCocoa(&buf, NSLocale)) |pref_| {
if (pref_) |pref| {
log.debug(
"setting LANGUAGE from preferred languages value={s}",
.{pref},
);

// TODO: Disabled until we can figure out why this is causing
// invalid translations:
// https://github.com/ghostty-org/ghostty/discussions/6633
// _ = internal_os.setenv("LANGUAGE", pref);
}
} else |err| {
log.warn("error getting preferred languages. err={}", .{err});
// env var in case our language differs from our locale. We only
// do this when the app is launched from the desktop because then
// we're in an app bundle and we are expected to read from our
// Bundle's preferred languages.
if (internal_os.launchedFromDesktop()) language: {
var buf: [1024]u8 = undefined;
const pref_ = preferredLanguageFromCocoa(
&buf,
NSLocale,
) catch |err| {
log.warn("error getting preferred languages. err={}", .{err});
break :language;
};

const pref = pref_ orelse break :language;
log.debug(
"setting LANGUAGE from preferred languages value={s}",
.{pref},
);
_ = internal_os.setenv("LANGUAGE", pref);
}
}

Expand Down

0 comments on commit 480b1a9

Please sign in to comment.