Localization support #2357
Replies: 6 comments 1 reply
-
Is there a "state-of-the-art" localization for Zig code? This could be an interesting project as a lot of Ghostty's documentation is generated from Zig documentation comments. The documentation comments inside |
Beta Was this translation helpful? Give feedback.
-
After a cursory search, there appears to be literally only four libraries1 that deal with localization for Zig, and all of them are dormant, incomplete, and more proofs of concept than mature libraries we can use off-the-shelf.
And of course, none of them handles translating doc comments for automated documentation purposes. ...Looks like we have to NIH this, then! Footnotes
|
Beta Was this translation helpful? Give feedback.
-
I'm interested in this but probably not for the 1.0 release. I'm only saying this out of time available and effort. |
Beta Was this translation helpful? Give feedback.
-
I could be wrong but I don't believe we need to reinvent the wheel here. I'd actually implemented something similar to this for my own personal Zig playground just last week. The code below could be modified to fit Ghostty. Once the strings are properly encased in const std = @import("std");
const c = @cImport({
// libraries for translation support
@cInclude("libintl.h");
@cInclude("locale.h");
@cInclude("gettext.h");
});
pub fn main() !void {
// We use __ instead of _ for Zig because _ is a reserved identifier
const __ = c.gettext;
const UUID = "com.mitchellh.ghostty";
const bind_path = "/usr/share/locale";
const msgid = "About Ghostty";
// locale.h
_ = c.setlocale(c.LC_MESSAGES, "");
// libintl.h
_ = c.bindtextdomain(UUID, bind_path);
// libintl.h
_ = c.textdomain(UUID);
// both are valid if we don't want to use a custom keyword
const gettext = c.gettext(msgid);
const same_gettext = __(msgid);
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
try stdout.print("gettext: {s}\n", .{gettext});
try stdout.print("same_gettext: {s}\n", .{same_gettext});
try bw.flush(); // don't forget to flush!
} The One caveat is that I know that this will work for the Linux ecosystem. I'm actually not sure if having the translations and possibly compiled objects will suffice elsewhere. And then there's the overall question of whether C imports would be preferred for this as an alternative to something more native in Zig. The GNU If desired, I could probably have something working within a few days along these lines. |
Beta Was this translation helpful? Give feedback.
-
For the record, cross-referencing to @pluiedev's draft PR #5214 here. |
Beta Was this translation helpful? Give feedback.
-
I'm curious about the macOS half of this feature, since GTK half is merged in #6004. |
Beta Was this translation helpful? Give feedback.
-
For the 1.0 release, I think we should at least have a foundation for localization support so that Ghostty can appeal to users whose native language is not English. As of now, all user-facing strings, names, labels, etc. are all hardcoded in English in the source code, which greatly limits what we could do for these users.
Beta Was this translation helpful? Give feedback.
All reactions