Skip to content

Commit

Permalink
feat: initial implementation of i18n/l10n
Browse files Browse the repository at this point in the history
  • Loading branch information
pluiedev committed Jan 23, 2025
1 parent 72d0855 commit 66323d6
Show file tree
Hide file tree
Showing 18 changed files with 371 additions and 51 deletions.
4 changes: 4 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
.url = "git+https://github.com/natecraddock/zf/?ref=main#ed99ca18b02dda052e20ba467e90b623c04690dd",
.hash = "1220edc3b8d8bedbb50555947987e5e8e2f93871ca3c8e8d4cc8f1377c15b5dd35e8",
},
.zig_gettext = .{
.url = "git+https://github.com/pluiedev/zig-gettext/?ref=main#c1ff3a954ba0d9ad369ccf96810437c7e46cfc2a",
.hash = "122046140255a2dadfc3b3f55a68e750776f0ae2330865665f892d381d8d8f438c69",
},

// C libs
.cimgui = .{ .path = "./pkg/cimgui" },
Expand Down
2 changes: 2 additions & 0 deletions nix/devShell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
wayland,
wayland-scanner,
wayland-protocols,
gettext,
}: let
# See package.nix. Keep in sync.
rpathLibs =
Expand Down Expand Up @@ -84,6 +85,7 @@
gtk4
glib
wayland
gettext
];
in
mkShell {
Expand Down
10 changes: 9 additions & 1 deletion nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
pkg-config,
zig_0_13,
pandoc,
gettext,
revision ? "dirty",
optimize ? "Debug",
enableX11 ? true,
Expand Down Expand Up @@ -56,6 +57,7 @@
../images
../include
../pkg
../po
../src
../vendor
../build.zig
Expand Down Expand Up @@ -125,6 +127,7 @@ in
pkg-config
zig_hook
wrapGAppsHook4
gettext
]
++ lib.optionals enableWayland [
wayland-scanner
Expand Down Expand Up @@ -162,7 +165,12 @@ in

dontConfigure = true;

zigBuildFlags = "-Dversion-string=${finalAttrs.version}-${revision}-nix -Dgtk-x11=${lib.boolToString enableX11} -Dgtk-wayland=${lib.boolToString enableWayland}";
zigBuildFlags = builtins.toString [
"-Dversion-string=${finalAttrs.version}-${revision}-nix"
"-Dgtk-x11=${lib.boolToString enableX11}"
"-Dgtk-wayland=${lib.boolToString enableWayland}"
"--search-prefix ${gettext}"
];

preBuild = ''
rm -rf $ZIG_GLOBAL_CACHE_DIR
Expand Down
2 changes: 1 addition & 1 deletion nix/zigCacheHash.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# This file is auto-generated! check build-support/check-zig-cache-hash.sh for
# more details.
"sha256-2zXNHWSSWjnpW8oHu2sufT5+Ms4IKWaH6yRARQeMcxk="
"sha256-n9Va8twZZ9wqbC46vPp/oi7kd8f4D8VSDoar8m4ttZs="
29 changes: 29 additions & 0 deletions pkg/libintl/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const std = @import("std");

pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const module = b.addModule("libintl", .{
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
});

const lib = b.addStaticLibrary(.{
.name = "libintl",
.target = target,
.optimize = optimize,
});

lib.linkLibC();

if (!target.result.isGnuLibC()) {
lib.linkSystemLibrary2("intl", .{
.preferred_link_mode = .dynamic,
.search_strategy = .mode_first,
});
}

b.installArtifact(lib);
}
Empty file added po/LINGUAS
Empty file.
159 changes: 159 additions & 0 deletions po/messages.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
msgid ""
msgstr ""
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: src/apprt/gtk/App.zig:1843 src/apprt/gtk/Window.zig:899
msgid "About Ghostty"
msgstr ""

#: src/apprt/gtk/Tab.zig:147
msgid "All terminal sessions in this tab will be terminated."
msgstr ""

#: src/apprt/gtk/Window.zig:781
msgid "All terminal sessions in this window will be terminated."
msgstr ""

#: src/apprt/gtk/ClipboardConfirmationWindow.zig:170
msgid "Allow"
msgstr ""

#: src/apprt/gtk/ClipboardConfirmationWindow.zig:248
msgid ""
"An application is attempting to read from the clipboard.\n"
"The current clipboard contents are shown below.\n"
msgstr ""

#: src/apprt/gtk/ClipboardConfirmationWindow.zig:252
msgid ""
"An application is attempting to write to the clipboard.\n"
"The content to write is shown below.\n"
msgstr ""

#: src/apprt/gtk/ClipboardConfirmationWindow.zig:237
msgid "Authorize Clipboard Access"
msgstr ""

#: src/apprt/gtk/ClipboardConfirmationWindow.zig:169
msgid "Cancel"
msgstr ""

#: src/apprt/gtk/App.zig:1830
msgid "Close Tab"
msgstr ""

#: src/apprt/gtk/App.zig:1833
msgid "Close Window"
msgstr ""

#: src/apprt/gtk/Tab.zig:143
msgid "Close this tab?"
msgstr ""

#: src/apprt/gtk/Surface.zig:732
msgid "Close this terminal?"
msgstr ""

#: src/apprt/gtk/Window.zig:777
msgid "Close this window?"
msgstr ""

#: src/apprt/gtk/Surface.zig:1145
msgid "Copied to clipboard"
msgstr ""

#: src/apprt/gtk/App.zig:1864
msgid "Copy"
msgstr ""

#: src/apprt/gtk/ClipboardConfirmationWindow.zig:170
msgid "Deny"
msgstr ""

#: src/apprt/gtk/Window.zig:880
msgid "Ghostty Developers"
msgstr ""

#: src/apprt/gtk/inspector.zig:143
msgid "Ghostty: Terminal Inspector"
msgstr ""

#: src/apprt/gtk/App.zig:1890
msgid "Menu"
msgstr ""

#: src/apprt/gtk/App.zig:1829 src/apprt/gtk/Window.zig:201
msgid "New Tab"
msgstr ""

#: src/apprt/gtk/App.zig:1828
msgid "New Window"
msgstr ""

#: src/apprt/gtk/App.zig:1841
msgid "Open Configuration"
msgstr ""

#: src/apprt/gtk/App.zig:1865 src/apprt/gtk/ClipboardConfirmationWindow.zig:169
msgid "Paste"
msgstr ""

#: src/apprt/gtk/ClipboardConfirmationWindow.zig:245
msgid ""
"Pasting this text into the terminal may be dangerous as it looks like some commands may be executed.\n"
msgstr ""

#: src/apprt/gtk/App.zig:1842
msgid "Reload Configuration"
msgstr ""

#: src/apprt/gtk/App.zig:1880
msgid "Reset"
msgstr ""

#: src/apprt/gtk/App.zig:1832 src/apprt/gtk/App.zig:1873
msgid "Split Down"
msgstr ""

#: src/apprt/gtk/App.zig:1831 src/apprt/gtk/App.zig:1872
msgid "Split Right"
msgstr ""

#: src/apprt/gtk/App.zig:1840 src/apprt/gtk/App.zig:1881
msgid "Terminal Inspector"
msgstr ""

#: src/apprt/gtk/Surface.zig:736
msgid ""
"There is still a running process in the terminal. Closing the terminal will kill this process.\n"
"Are you sure you want to close the terminal?\n"
"\n"
"Click 'No' to cancel and return to your terminal.\n"
msgstr ""

#: src/apprt/gtk/Window.zig:174
msgid "View Open Tabs"
msgstr ""

#: src/apprt/gtk/ClipboardConfirmationWindow.zig:236
msgid "Warning: Potentially Unsafe Paste"
msgstr ""

#: src/apprt/gtk/ResizeOverlay.zig:99
msgid "c"
msgid_plural "c"
msgstr[0] ""
msgstr[1] ""

#: src/apprt/gtk/ResizeOverlay.zig:100
msgid "r"
msgid_plural "r"
msgstr[0] ""
msgstr[1] ""

#: src/apprt/gtk/Window.zig:220
msgid "⚠️ You're running a debug build of Ghostty! Performance will be degraded."
msgstr ""
35 changes: 18 additions & 17 deletions src/apprt/gtk/App.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const inspector = @import("inspector.zig");
const key = @import("key.zig");
const winproto = @import("winproto.zig");
const testing = std.testing;
const i18n = @import("../../i18n.zig");

const log = std.log.scoped(.gtk);

Expand Down Expand Up @@ -1825,22 +1826,22 @@ fn initMenuContent(menu: *c.GMenu) void {
const section = c.g_menu_new();
defer c.g_object_unref(section);
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
c.g_menu_append(section, "New Window", "win.new_window");
c.g_menu_append(section, "New Tab", "win.new_tab");
c.g_menu_append(section, "Close Tab", "win.close_tab");
c.g_menu_append(section, "Split Right", "win.split_right");
c.g_menu_append(section, "Split Down", "win.split_down");
c.g_menu_append(section, "Close Window", "win.close");
c.g_menu_append(section, i18n._("New Window"), "win.new_window");
c.g_menu_append(section, i18n._("New Tab"), "win.new_tab");
c.g_menu_append(section, i18n._("Close Tab"), "win.close_tab");
c.g_menu_append(section, i18n._("Split Right"), "win.split_right");
c.g_menu_append(section, i18n._("Split Down"), "win.split_down");
c.g_menu_append(section, i18n._("Close Window"), "win.close");
}

{
const section = c.g_menu_new();
defer c.g_object_unref(section);
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
c.g_menu_append(section, "Terminal Inspector", "win.toggle_inspector");
c.g_menu_append(section, "Open Configuration", "app.open-config");
c.g_menu_append(section, "Reload Configuration", "app.reload-config");
c.g_menu_append(section, "About Ghostty", "win.about");
c.g_menu_append(section, i18n._("Terminal Inspector"), "win.toggle_inspector");
c.g_menu_append(section, i18n._("Open Configuration"), "app.open-config");
c.g_menu_append(section, i18n._("Reload Configuration"), "app.reload-config");
c.g_menu_append(section, i18n._("About Ghostty"), "win.about");
}
}

Expand All @@ -1861,24 +1862,24 @@ fn initContextMenu(self: *App) void {
const section = c.g_menu_new();
defer c.g_object_unref(section);
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
c.g_menu_append(section, "Copy", "win.copy");
c.g_menu_append(section, "Paste", "win.paste");
c.g_menu_append(section, i18n._("Copy"), "win.copy");
c.g_menu_append(section, i18n._("Paste"), "win.paste");
}

{
const section = c.g_menu_new();
defer c.g_object_unref(section);
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
c.g_menu_append(section, "Split Right", "win.split_right");
c.g_menu_append(section, "Split Down", "win.split_down");
c.g_menu_append(section, i18n._("Split Right"), "win.split_right");
c.g_menu_append(section, i18n._("Split Down"), "win.split_down");
}

{
const section = c.g_menu_new();
defer c.g_object_unref(section);
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
c.g_menu_append(section, "Reset", "win.reset");
c.g_menu_append(section, "Terminal Inspector", "win.toggle_inspector");
c.g_menu_append(section, i18n._("Reset"), "win.reset");
c.g_menu_append(section, i18n._("Terminal Inspector"), "win.toggle_inspector");
}

const section = c.g_menu_new();
Expand All @@ -1887,7 +1888,7 @@ fn initContextMenu(self: *App) void {
defer c.g_object_unref(submenu);

initMenuContent(@ptrCast(submenu));
c.g_menu_append_submenu(section, "Menu", @ptrCast(@alignCast(submenu)));
c.g_menu_append_submenu(section, i18n._("Menu"), @ptrCast(@alignCast(submenu)));
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));

self.context_menu = menu;
Expand Down
31 changes: 16 additions & 15 deletions src/apprt/gtk/ClipboardConfirmationWindow.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const CoreSurface = @import("../../Surface.zig");
const App = @import("App.zig");
const View = @import("View.zig");
const c = @import("c.zig").c;
const i18n = @import("../../i18n.zig");

const log = std.log.scoped(.gtk);

Expand Down Expand Up @@ -166,8 +167,8 @@ const ButtonsView = struct {

pub fn init(root: *ClipboardConfirmation) !ButtonsView {
const cancel_text, const confirm_text = switch (root.pending_req) {
.paste => .{ "Cancel", "Paste" },
.osc_52_read, .osc_52_write => .{ "Deny", "Allow" },
.paste => .{ i18n._("Cancel"), i18n._("Paste") },
.osc_52_read, .osc_52_write => .{ i18n._("Deny"), i18n._("Allow") },
};

const cancel_button = c.gtk_button_new_with_label(cancel_text);
Expand Down Expand Up @@ -233,25 +234,25 @@ const ButtonsView = struct {
/// The title of the window, based on the reason the prompt is being shown.
fn titleText(req: apprt.ClipboardRequest) [:0]const u8 {
return switch (req) {
.paste => "Warning: Potentially Unsafe Paste",
.osc_52_read, .osc_52_write => "Authorize Clipboard Access",
.paste => i18n._("Warning: Potentially Unsafe Paste"),
.osc_52_read, .osc_52_write => i18n._("Authorize Clipboard Access"),
};
}

/// The text to display in the prompt window, based on the reason the prompt
/// is being shown.
fn promptText(req: apprt.ClipboardRequest) [:0]const u8 {
return switch (req) {
.paste =>
\\Pasting this text into the terminal may be dangerous as it looks like some commands may be executed.
,
.osc_52_read =>
\\An application is attempting to read from the clipboard.
\\The current clipboard contents are shown below.
,
.osc_52_write =>
\\An application is attempting to write to the clipboard.
\\The content to write is shown below.
,
.paste => i18n._(
\\Pasting this text into the terminal may be dangerous as it looks like some commands may be executed.
),
.osc_52_read => i18n._(
\\An application is attempting to read from the clipboard.
\\The current clipboard contents are shown below.
),
.osc_52_write => i18n._(
\\An application is attempting to write to the clipboard.
\\The content to write is shown below.
),
};
}
Loading

0 comments on commit 66323d6

Please sign in to comment.