From 4cf127a06481f3dbcc23cec3c300f55253d03dfb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 7 Mar 2025 08:40:39 -0800 Subject: [PATCH] build: i18n should emit mo on every platform --- build.zig | 10 ++++++++++ src/build/GhosttyI18n.zig | 25 ++++++++++++------------- src/os/i18n.zig | 3 +++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/build.zig b/build.zig index 4e96a5bbf..f07918441 100644 --- a/build.zig +++ b/build.zig @@ -82,6 +82,16 @@ pub fn build(b: *std.Build) !void { { const run_cmd = b.addRunArtifact(exe.exe); 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"); run_step.dependOn(&run_cmd.step); } diff --git a/src/build/GhosttyI18n.zig b/src/build/GhosttyI18n.zig index 5ca564268..b7aa0be11 100644 --- a/src/build/GhosttyI18n.zig +++ b/src/build/GhosttyI18n.zig @@ -18,23 +18,22 @@ steps: []*std.Build.Step, update_step: *std.Build.Step, pub fn init(b: *std.Build, cfg: *const Config) !GhosttyI18n { + _ = cfg; + var steps = std.ArrayList(*std.Build.Step).init(b.allocator); defer steps.deinit(); - if (cfg.app_runtime == .gtk) { - // Output the .mo files used by the GTK apprt - inline for (locales) |locale| { - const msgfmt = b.addSystemCommand(&.{ "msgfmt", "-o", "-" }); - msgfmt.addFileArg(b.path("po/" ++ locale ++ ".po")); + inline for (locales) |locale| { + const msgfmt = b.addSystemCommand(&.{ "msgfmt", "-o", "-" }); + msgfmt.addFileArg(b.path("po/" ++ locale ++ ".po")); - try steps.append(&b.addInstallFile( - msgfmt.captureStdOut(), - std.fmt.comptimePrint( - "share/locale/{s}/LC_MESSAGES/{s}.mo", - .{ locale, domain }, - ), - ).step); - } + try steps.append(&b.addInstallFile( + msgfmt.captureStdOut(), + std.fmt.comptimePrint( + "share/locale/{s}/LC_MESSAGES/{s}.mo", + .{ locale, domain }, + ), + ).step); } return .{ diff --git a/src/os/i18n.zig b/src/os/i18n.zig index d6124cac5..668e22c7d 100644 --- a/src/os/i18n.zig +++ b/src/os/i18n.zig @@ -1,6 +1,8 @@ const std = @import("std"); const build_config = @import("../build_config.zig"); +const log = std.log.scoped(.i18n); + pub const InitError = error{ InvalidResourcesDir, OutOfMemory, @@ -26,6 +28,7 @@ pub fn init(resources_dir: []const u8) InitError!void { return error.OutOfMemory; // 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 return error.OutOfMemory; }