i18n: note about i18n.N_ usage and @inComptime() return msgid for i18n._

This commit is contained in:
Ēriks Remess
2026-03-19 18:00:58 +02:00
parent df23bef0e9
commit 1125fa26df
2 changed files with 36 additions and 0 deletions

View File

@@ -62,8 +62,13 @@ pub fn initGlobalDomain() error{OutOfMemory}!void {
}
/// Translate a message for the Ghostty domain.
///
/// If this is called at comptime, the direct msgid is returned without
/// translation. This still allows the string to be marked for translation
/// while remaining usable in comptime contexts.
pub fn _(msgid: [*:0]const u8) [*:0]const u8 {
if (comptime !build_config.i18n) return msgid;
if (@inComptime()) return msgid;
return dgettext(build_config.bundle_id, msgid);
}
@@ -196,3 +201,10 @@ test "canonicalizeLocale darwin" {
// underscores. We should parse them out before calling this function.
try testing.expectEqualStrings("en_US.UTF_8", try canonicalizeLocale(&buf, "en_US.UTF-8"));
}
test "_ returns msgid at comptime" {
const testing = std.testing;
const msgid = comptime @"_"("Ghostty");
try testing.expectEqualStrings("Ghostty", std.mem.span(msgid));
}