build: i18n should emit mo on every platform

This commit is contained in:
Mitchell Hashimoto
2025-03-07 08:40:39 -08:00
parent e8c20b5501
commit 4cf127a064
3 changed files with 25 additions and 13 deletions

View File

@ -82,6 +82,16 @@ pub fn build(b: *std.Build) !void {
{ {
const run_cmd = b.addRunArtifact(exe.exe); const run_cmd = b.addRunArtifact(exe.exe);
if (b.args) |args| run_cmd.addArgs(args); if (b.args) |args| run_cmd.addArgs(args);
// Set the proper resources dir so things like shell integration
// work correctly. If we're running `zig build run` in Ghostty,
// this also ensures it overwrites the release one with our debug
// build.
run_cmd.setEnvironmentVariable(
"GHOSTTY_RESOURCES_DIR",
b.getInstallPath(.prefix, "share/ghostty"),
);
const run_step = b.step("run", "Run the app"); const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_cmd.step);
} }

View File

@ -18,23 +18,22 @@ steps: []*std.Build.Step,
update_step: *std.Build.Step, update_step: *std.Build.Step,
pub fn init(b: *std.Build, cfg: *const Config) !GhosttyI18n { pub fn init(b: *std.Build, cfg: *const Config) !GhosttyI18n {
_ = cfg;
var steps = std.ArrayList(*std.Build.Step).init(b.allocator); var steps = std.ArrayList(*std.Build.Step).init(b.allocator);
defer steps.deinit(); defer steps.deinit();
if (cfg.app_runtime == .gtk) { inline for (locales) |locale| {
// Output the .mo files used by the GTK apprt const msgfmt = b.addSystemCommand(&.{ "msgfmt", "-o", "-" });
inline for (locales) |locale| { msgfmt.addFileArg(b.path("po/" ++ locale ++ ".po"));
const msgfmt = b.addSystemCommand(&.{ "msgfmt", "-o", "-" });
msgfmt.addFileArg(b.path("po/" ++ locale ++ ".po"));
try steps.append(&b.addInstallFile( try steps.append(&b.addInstallFile(
msgfmt.captureStdOut(), msgfmt.captureStdOut(),
std.fmt.comptimePrint( std.fmt.comptimePrint(
"share/locale/{s}/LC_MESSAGES/{s}.mo", "share/locale/{s}/LC_MESSAGES/{s}.mo",
.{ locale, domain }, .{ locale, domain },
), ),
).step); ).step);
}
} }
return .{ return .{

View File

@ -1,6 +1,8 @@
const std = @import("std"); const std = @import("std");
const build_config = @import("../build_config.zig"); const build_config = @import("../build_config.zig");
const log = std.log.scoped(.i18n);
pub const InitError = error{ pub const InitError = error{
InvalidResourcesDir, InvalidResourcesDir,
OutOfMemory, OutOfMemory,
@ -26,6 +28,7 @@ pub fn init(resources_dir: []const u8) InitError!void {
return error.OutOfMemory; return error.OutOfMemory;
// Bind our bundle ID to the given locale path // Bind our bundle ID to the given locale path
log.debug("binding domain={s} path={s}", .{ build_config.bundle_id, path });
_ = bindtextdomain(build_config.bundle_id, path.ptr) orelse _ = bindtextdomain(build_config.bundle_id, path.ptr) orelse
return error.OutOfMemory; return error.OutOfMemory;
} }