i18n: Localize Nautilus .py script (#9976)

Closes #9266. 


Big Note: I noticed that this worked properly under `NixOS`, but on my
`Ubuntu` VM it didnt.

The reason is in
[src/build/GhosttyI18n.zig](73a93abf7b/src/build/GhosttyI18n.zig (L24-L31))
because the locale is expected in the `<lang>_<region>` without the
encoding suffix. `<lang>_<region>_<encoding>`
```
        // There is no encoding suffix in the LC_MESSAGES path on FreeBSD,
        // so we need to remove it from `locale` to have a correct destination string.
        // (/usr/local/share/locale/en_AU/LC_MESSAGES)
        const target_locale = comptime if (builtin.target.os.tag == .freebsd)
            std.mem.trimRight(u8, locale, ".UTF-8")
        else
            locale;

```
If i force it to always trim the encoding it works, but I am guessing
its there for a reason ,so maybe some of the maintainer can shed some
light in the best way forward, as I am not an expert in how other
systems deal with it. Here you see `Open in Ghostty` -> Abrir con
Ghostty

<img width="353" height="372" alt="image"
src="https://github.com/user-attachments/assets/2c0266f7-cfb3-49e3-aef1-9e98acb16ad8"
/>


- I wanted to format the `py` file with `ruff` but didnt want to drown
the changes, so maybe something that could be worth doing so that also
our `py` files have std formatting.

> [!NOTE]
> Used AI only for helping me debug where the locales could be and why
was it not detected, but no code help whatsoever
This commit is contained in:
Jeffrey C. Ollie
2026-02-17 18:34:53 -06:00
committed by GitHub
29 changed files with 176 additions and 36 deletions

View File

@@ -65,16 +65,14 @@ fn createUpdateStep(b: *std.Build) !*std.Build.Step {
"xgettext",
"--language=C", // Silence the "unknown extension" errors
"--from-code=UTF-8",
"--add-comments=Translators",
"--keyword=_",
"--keyword=C_:1c,2",
"--package-name=" ++ domain,
"--msgid-bugs-address=m@mitchellh.com",
"--copyright-holder=\"Mitchell Hashimoto, Ghostty contributors\"",
"-o",
"-",
});
// Collect to intermediate .pot file
xgettext.addArg("-o");
const gtk_pot = xgettext.addOutputFileArg("gtk.pot");
// Not cacheable due to the gresource files
xgettext.has_side_effects = true;
@@ -149,16 +147,45 @@ fn createUpdateStep(b: *std.Build) !*std.Build.Step {
}
}
// Add support for localizing our `nautilus` integration
const xgettext_py = b.addSystemCommand(&.{
"xgettext",
"--language=Python",
"--from-code=UTF-8",
});
// Collect to intermediate .pot file
xgettext_py.addArg("-o");
const py_pot = xgettext_py.addOutputFileArg("py.pot");
const nautilus_script_path = "dist/linux/ghostty_nautilus.py";
xgettext_py.addArg(nautilus_script_path);
xgettext_py.addFileInput(b.path(nautilus_script_path));
// Merge pot files
const xgettext_merge = b.addSystemCommand(&.{
"xgettext",
"--add-comments=Translators",
"--package-name=" ++ domain,
"--msgid-bugs-address=m@mitchellh.com",
"--copyright-holder=\"Mitchell Hashimoto, Ghostty contributors\"",
"-o",
"-",
});
// py_pot needs to be first on merge order because of `xgettext` behavior around
// charset when merging the two `.pot` files
xgettext_merge.addFileArg(py_pot);
xgettext_merge.addFileArg(gtk_pot);
const usf = b.addUpdateSourceFiles();
usf.addCopyFileToSource(
xgettext.captureStdOut(),
xgettext_merge.captureStdOut(),
"po/" ++ domain ++ ".pot",
);
inline for (locales) |locale| {
const msgmerge = b.addSystemCommand(&.{ "msgmerge", "--quiet", "--no-fuzzy-matching" });
msgmerge.addFileArg(b.path("po/" ++ locale ++ ".po"));
msgmerge.addFileArg(xgettext.captureStdOut());
msgmerge.addFileArg(xgettext_merge.captureStdOut());
usf.addCopyFileToSource(msgmerge.captureStdOut(), "po/" ++ locale ++ ".po");
}