Skip to content

Commit edf6192

Browse files
committed
add ghostty_translate C API
1 parent 238573d commit edf6192

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

include/ghostty.h

+1
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ typedef struct {
669669
int ghostty_init(void);
670670
void ghostty_cli_main(uintptr_t, char**);
671671
ghostty_info_s ghostty_info(void);
672+
const char* ghostty_translate(const char*);
672673

673674
ghostty_config_t ghostty_config_new();
674675
void ghostty_config_free(ghostty_config_t);

macos/Ghostty.xcodeproj/project.pbxproj

+12-8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
A53D0C952B53B4D800305CE6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A5B30538299BEAAB0047F10C /* Assets.xcassets */; };
4141
A53D0C9B2B543F3B00305CE6 /* Ghostty.App.swift in Sources */ = {isa = PBXBuildFile; fileRef = A53D0C992B543F3B00305CE6 /* Ghostty.App.swift */; };
4242
A53D0C9C2B543F7B00305CE6 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = A55B7BB729B6F53A0055DE60 /* Package.swift */; };
43+
A546F1142D7B68D7003B11A0 /* locale in Resources */ = {isa = PBXBuildFile; fileRef = A546F1132D7B68D7003B11A0 /* locale */; };
4344
A54B0CE92D0CECD100CBEFF8 /* ColorizedGhosttyIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A54B0CE82D0CECD100CBEFF8 /* ColorizedGhosttyIconView.swift */; };
4445
A54B0CEB2D0CFB4C00CBEFF8 /* NSImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A54B0CEA2D0CFB4A00CBEFF8 /* NSImage+Extension.swift */; };
4546
A54B0CED2D0CFB7700CBEFF8 /* ColorizedGhosttyIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = A54B0CEC2D0CFB7300CBEFF8 /* ColorizedGhosttyIcon.swift */; };
@@ -138,6 +139,7 @@
138139
A53A6C022CCC1B7D00943E98 /* Ghostty.Action.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ghostty.Action.swift; sourceTree = "<group>"; };
139140
A53D0C932B53B43700305CE6 /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = "<group>"; };
140141
A53D0C992B543F3B00305CE6 /* Ghostty.App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ghostty.App.swift; sourceTree = "<group>"; };
142+
A546F1132D7B68D7003B11A0 /* locale */ = {isa = PBXFileReference; lastKnownFileType = folder; name = locale; path = "../zig-out/share/locale"; sourceTree = "<group>"; };
141143
A54B0CE82D0CECD100CBEFF8 /* ColorizedGhosttyIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorizedGhosttyIconView.swift; sourceTree = "<group>"; };
142144
A54B0CEA2D0CFB4A00CBEFF8 /* NSImage+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSImage+Extension.swift"; sourceTree = "<group>"; };
143145
A54B0CEC2D0CFB7300CBEFF8 /* ColorizedGhosttyIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorizedGhosttyIcon.swift; sourceTree = "<group>"; };
@@ -424,6 +426,7 @@
424426
29C15B1C2CDC3B2000520DD4 /* bat */,
425427
A586167B2B7703CC009BDB1D /* fish */,
426428
55154BDF2B33911F001622DC /* ghostty */,
429+
A546F1132D7B68D7003B11A0 /* locale */,
427430
A5985CE52C33060F00C57AD3 /* man */,
428431
9351BE8E2D22937F003B3499 /* nvim */,
429432
A5A1F8842A489D6800D1E8BC /* terminfo */,
@@ -593,20 +596,21 @@
593596
buildActionMask = 2147483647;
594597
files = (
595598
FC9ABA9C2D0F53F80020D4C8 /* bash-completion in Resources */,
596-
A5B30539299BEAAB0047F10C /* Assets.xcassets in Resources */,
597-
A51BFC1E2B2FB5CE00E92F16 /* About.xib in Resources */,
598-
A5E112932AF73E6E00C6E0C2 /* ClipboardConfirmation.xib in Resources */,
599-
A5CDF1912AAF9A5800513312 /* ConfigurationErrors.xib in Resources */,
600-
857F63812A5E64F200CA4815 /* MainMenu.xib in Resources */,
601599
29C15B1D2CDC3B2900520DD4 /* bat in Resources */,
602-
A596309A2AEE1C6400D64628 /* Terminal.xib in Resources */,
603600
A586167C2B7703CC009BDB1D /* fish in Resources */,
604-
FC5218FA2D10FFCE004C93E0 /* zsh in Resources */,
605601
55154BE02B33911F001622DC /* ghostty in Resources */,
602+
A546F1142D7B68D7003B11A0 /* locale in Resources */,
606603
A5985CE62C33060F00C57AD3 /* man in Resources */,
604+
9351BE8E3D22937F003B3499 /* nvim in Resources */,
607605
A5A1F8852A489D6800D1E8BC /* terminfo in Resources */,
608606
552964E62B34A9B400030505 /* vim in Resources */,
609-
9351BE8E3D22937F003B3499 /* nvim in Resources */,
607+
FC5218FA2D10FFCE004C93E0 /* zsh in Resources */,
608+
A5B30539299BEAAB0047F10C /* Assets.xcassets in Resources */,
609+
A51BFC1E2B2FB5CE00E92F16 /* About.xib in Resources */,
610+
A5E112932AF73E6E00C6E0C2 /* ClipboardConfirmation.xib in Resources */,
611+
A5CDF1912AAF9A5800513312 /* ConfigurationErrors.xib in Resources */,
612+
857F63812A5E64F200CA4815 /* MainMenu.xib in Resources */,
613+
A596309A2AEE1C6400D64628 /* Terminal.xib in Resources */,
610614
A5CBD05C2CA0C5C70017A1AE /* QuickTerminal.xib in Resources */,
611615
);
612616
runOnlyForDeploymentPostprocessing = 0;

macos/Ghostty.xcodeproj/xcshareddata/xcschemes/Ghostty.xcscheme

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
buildConfiguration = "Debug"
3434
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3535
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
36+
language = "zh-Hans"
3637
launchStyle = "0"
3738
useCustomWorkingDirectory = "NO"
3839
ignoresPersistentStateOnLaunch = "NO"

src/build/GhosttyI18n.zig

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ const GhosttyI18n = @This();
33
const std = @import("std");
44
const Config = @import("Config.zig");
55
const gresource = @import("../apprt/gtk/gresource.zig");
6+
const internal_os = @import("../os/main.zig");
67

78
const domain = "com.mitchellh.ghostty";
89

9-
const locales = [_][]const u8{
10-
"zh_CN.UTF-8",
11-
};
12-
1310
owner: *std.Build,
1411
steps: []*std.Build.Step,
1512

@@ -23,7 +20,7 @@ pub fn init(b: *std.Build, cfg: *const Config) !GhosttyI18n {
2320
var steps = std.ArrayList(*std.Build.Step).init(b.allocator);
2421
defer steps.deinit();
2522

26-
inline for (locales) |locale| {
23+
inline for (internal_os.i18n.locales) |locale| {
2724
const msgfmt = b.addSystemCommand(&.{ "msgfmt", "-o", "-" });
2825
msgfmt.addFileArg(b.path("po/" ++ locale ++ ".po"));
2926

@@ -106,7 +103,7 @@ fn createUpdateStep(b: *std.Build) !*std.Build.Step {
106103
"po/" ++ domain ++ ".pot",
107104
);
108105

109-
inline for (locales) |locale| {
106+
inline for (internal_os.i18n.locales) |locale| {
110107
const msgmerge = b.addSystemCommand(&.{ "msgmerge", "-q" });
111108
msgmerge.addFileArg(b.path("po/" ++ locale ++ ".po"));
112109
msgmerge.addFileArg(xgettext.captureStdOut());

src/main_c.zig

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const build_config = @import("build_config.zig");
1515
const main = @import("main_ghostty.zig");
1616
const state = &@import("global.zig").state;
1717
const apprt = @import("apprt.zig");
18+
const internal_os = @import("os/main.zig");
1819

1920
// Some comptime assertions that our C API depends on.
2021
comptime {
@@ -88,3 +89,13 @@ export fn ghostty_info() Info {
8889
.version_len = build_config.version_string.len,
8990
};
9091
}
92+
93+
/// Translate a string maintained by libghostty into the current
94+
/// application language. This will return the same string (same pointer)
95+
/// if no translation is found, so the pointer must be stable through
96+
/// the function call.
97+
///
98+
/// This should only be used for singular strings maintained by Ghostty.
99+
export fn ghostty_translate(msgid: [*:0]const u8) [*:0]const u8 {
100+
return internal_os.i18n._(msgid);
101+
}

src/os/i18n.zig

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ const build_config = @import("../build_config.zig");
33

44
const log = std.log.scoped(.i18n);
55

6+
/// Supported locales for the application. This must be kept up to date
7+
/// with the translations available in the `po/` directory; this is used
8+
/// by our build process as well runtime libghostty APIs.
9+
pub const locales = [_][]const u8{
10+
"zh_CN.UTF-8",
11+
};
12+
613
pub const InitError = error{
714
InvalidResourcesDir,
815
OutOfMemory,

0 commit comments

Comments
 (0)