-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial implementation of i18n/l10n
- Loading branch information
Showing
19 changed files
with
467 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) !void { | ||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const module = b.addModule("intl", .{ | ||
.root_source_file = b.path("main.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
if (target.result.isGnuLibC()) { | ||
// If we use glibc, then great! We don't have to do anything. | ||
// lib.linkLibC(); | ||
} else { | ||
// If we're on any other platform we have to do more work. | ||
// In GNU's infinite wisdom, there's no easy pkg-config file for | ||
// you to consume and integrate into build systems other than autoconf. | ||
// Users must rely on system library/include paths, or manually | ||
// add libintl to the Zig search path. | ||
|
||
switch (target.result.os.tag) { | ||
// .windows => { | ||
// const msys2 = b.dependency("libintl_msys2", .{}); | ||
// lib.addLibraryPath(msys2.path("usr/bin")); | ||
// module.linkSystemLibrary2("msys-intl-8", .{ | ||
// .preferred_link_mode = .dynamic, | ||
// .search_strategy = .mode_first, | ||
// }); | ||
// }, | ||
else => |tag| if (tag.isDarwin()) { | ||
// module.linkSystemLibrary2("libintl", .{ | ||
// .preferred_link_mode = .dynamic, | ||
// .search_strategy = .mode_first, | ||
// }); | ||
} else { | ||
@compileError("unsupported platform"); | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.{ | ||
.name = "libintl", | ||
.version = "0.0.1", | ||
.paths = .{""}, | ||
.dependencies = .{}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
pub const locale = @cImport(@cInclude("locale.h")); | ||
|
||
pub extern fn gettext( | ||
msgid: [*:0]const u8, | ||
) [*:0]const u8; | ||
pub extern fn dgettext( | ||
domainname: [*:0]const u8, | ||
msgid: [*:0]const u8, | ||
) [*:0]const u8; | ||
pub extern fn dcgettext( | ||
domainname: [*:0]const u8, | ||
msgid: [*:0]const u8, | ||
category: c_int, | ||
) [*:0]const u8; | ||
|
||
pub extern fn ngettext( | ||
msgid1: [*:0]const u8, | ||
msgid2: [*:0]const u8, | ||
n: c_ulong, | ||
) [*:0]const u8; | ||
pub extern fn dngettext( | ||
domainname: [*:0]const u8, | ||
msgid1: [*:0]const u8, | ||
msgid2: [*:0]const u8, | ||
n: c_ulong, | ||
) [*:0]const u8; | ||
pub extern fn dcngettext( | ||
domainname: [*:0]const u8, | ||
msgid1: [*:0]const u8, | ||
msgid2: [*:0]const u8, | ||
n: c_ulong, | ||
category: c_int, | ||
) [*:0]const u8; | ||
|
||
pub extern fn bindtextdomain( | ||
domainname: [*:0]const u8, | ||
dirname: [*:0]const u8, | ||
) ?[*]const u8; | ||
pub extern fn textdomain( | ||
domainname: ?[*:0]const u8, | ||
) ?[*]const u8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const std = @import("std"); | ||
const c = @import("c.zig"); | ||
|
||
pub const Category = enum(c_int) { | ||
messages = c.locale.LC_MESSAGES, | ||
collate = c.locale.LC_COLLATE, | ||
ctype = c.locale.LC_CTYPE, | ||
monetary = c.locale.LC_MONETARY, | ||
numeric = c.locale.LC_NUMERIC, | ||
time = c.locale.LC_TIME, | ||
_, | ||
}; | ||
|
||
pub const Query = struct { | ||
msg: [:0]const u8, | ||
plural: ?struct { | ||
msg: [:0]const u8, | ||
number: c_ulong, | ||
} = null, | ||
domain: ?[:0]const u8 = null, | ||
category: ?Category = null, | ||
}; | ||
|
||
pub fn _(msg: [:0]const u8) [:0]const u8 { | ||
return get(.{ .msg = msg }); | ||
} | ||
|
||
pub fn get(comptime query: Query) [:0]const u8 { | ||
const result = res: { | ||
if (query.plural) |plural| { | ||
if (query.domain) |d| { | ||
break :res if (query.category) |cat| | ||
c.dcngettext(d, query.msg, plural.msg, plural.number, @intFromEnum(cat)) | ||
else | ||
c.dngettext(d, query.msg, plural.msg, plural.number); | ||
} | ||
|
||
if (query.category != null) @panic("domain must be specified alongside category"); | ||
break :res c.ngettext(query.msg, query.plural, plural.number); | ||
} | ||
|
||
if (query.domain) |d| { | ||
break :res if (query.category) |cat| | ||
c.dcgettext(d, query.msg, @intFromEnum(cat)) | ||
else | ||
c.dgettext(d, query.msg); | ||
} | ||
|
||
if (query.category != null) @panic("domain must be specified alongside category"); | ||
break :res c.gettext(query.msg); | ||
}; | ||
|
||
return std.mem.span(result); | ||
} | ||
|
||
pub fn bindTextDomain(domain: [:0]const u8, dir: [:0]const u8) std.mem.Allocator.Error!void { | ||
// ENOMEM is the only possible error | ||
if (c.bindtextdomain(domain, dir) == null) return error.OutOfMemory; | ||
} | ||
pub fn setTextDomain(domain: [:0]const u8) std.mem.Allocator.Error!void { | ||
// ENOMEM is the only possible error | ||
if (c.textdomain(domain) == null) return error.OutOfMemory; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" |
Oops, something went wrong.