mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-27 01:33:57 +00:00
add ghostty_translate C API
This commit is contained in:
@@ -3,13 +3,10 @@ const GhosttyI18n = @This();
|
||||
const std = @import("std");
|
||||
const Config = @import("Config.zig");
|
||||
const gresource = @import("../apprt/gtk/gresource.zig");
|
||||
const internal_os = @import("../os/main.zig");
|
||||
|
||||
const domain = "com.mitchellh.ghostty";
|
||||
|
||||
const locales = [_][]const u8{
|
||||
"zh_CN.UTF-8",
|
||||
};
|
||||
|
||||
owner: *std.Build,
|
||||
steps: []*std.Build.Step,
|
||||
|
||||
@@ -23,7 +20,7 @@ pub fn init(b: *std.Build, cfg: *const Config) !GhosttyI18n {
|
||||
var steps = std.ArrayList(*std.Build.Step).init(b.allocator);
|
||||
defer steps.deinit();
|
||||
|
||||
inline for (locales) |locale| {
|
||||
inline for (internal_os.i18n.locales) |locale| {
|
||||
const msgfmt = b.addSystemCommand(&.{ "msgfmt", "-o", "-" });
|
||||
msgfmt.addFileArg(b.path("po/" ++ locale ++ ".po"));
|
||||
|
||||
@@ -106,7 +103,7 @@ fn createUpdateStep(b: *std.Build) !*std.Build.Step {
|
||||
"po/" ++ domain ++ ".pot",
|
||||
);
|
||||
|
||||
inline for (locales) |locale| {
|
||||
inline for (internal_os.i18n.locales) |locale| {
|
||||
const msgmerge = b.addSystemCommand(&.{ "msgmerge", "-q" });
|
||||
msgmerge.addFileArg(b.path("po/" ++ locale ++ ".po"));
|
||||
msgmerge.addFileArg(xgettext.captureStdOut());
|
||||
|
||||
@@ -15,6 +15,7 @@ const build_config = @import("build_config.zig");
|
||||
const main = @import("main_ghostty.zig");
|
||||
const state = &@import("global.zig").state;
|
||||
const apprt = @import("apprt.zig");
|
||||
const internal_os = @import("os/main.zig");
|
||||
|
||||
// Some comptime assertions that our C API depends on.
|
||||
comptime {
|
||||
@@ -88,3 +89,13 @@ export fn ghostty_info() Info {
|
||||
.version_len = build_config.version_string.len,
|
||||
};
|
||||
}
|
||||
|
||||
/// Translate a string maintained by libghostty into the current
|
||||
/// application language. This will return the same string (same pointer)
|
||||
/// if no translation is found, so the pointer must be stable through
|
||||
/// the function call.
|
||||
///
|
||||
/// This should only be used for singular strings maintained by Ghostty.
|
||||
export fn ghostty_translate(msgid: [*:0]const u8) [*:0]const u8 {
|
||||
return internal_os.i18n._(msgid);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,13 @@ const build_config = @import("../build_config.zig");
|
||||
|
||||
const log = std.log.scoped(.i18n);
|
||||
|
||||
/// Supported locales for the application. This must be kept up to date
|
||||
/// with the translations available in the `po/` directory; this is used
|
||||
/// by our build process as well runtime libghostty APIs.
|
||||
pub const locales = [_][]const u8{
|
||||
"zh_CN.UTF-8",
|
||||
};
|
||||
|
||||
pub const InitError = error{
|
||||
InvalidResourcesDir,
|
||||
OutOfMemory,
|
||||
|
||||
Reference in New Issue
Block a user