Skip to content

Commit

Permalink
feat: translate metainfo and desktop files
Browse files Browse the repository at this point in the history
Contributes to #15
  • Loading branch information
ianprime0509 committed Nov 27, 2024
1 parent 3660fdf commit b1d95f1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 25 deletions.
51 changes: 49 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ pub fn build(b: *std.Build) !void {
exe.root_module.addAnonymousImport("puzzles", .{ .root_source_file = b.path("puzzles/puzzles.zig") });
b.installArtifact(exe);

const metainfo = b.path("data/dev.ianjohnson.Nonograms.metainfo.xml");
const linguas = readLinguas(b);

const metainfo = generateMetainfo(b, linguas);
const metainfo_install = b.addInstallFileWithDir(metainfo, metainfo_dir, b.fmt("{s}.metainfo.xml", .{app_id}));
b.getInstallStep().dependOn(&metainfo_install.step);

const desktop = b.path("data/dev.ianjohnson.Nonograms.desktop");
const desktop = generateDesktop(b, linguas);
const desktop_install = b.addInstallFileWithDir(desktop, desktop_dir, b.fmt("{s}.desktop", .{app_id}));
b.getInstallStep().dependOn(&desktop_install.step);

Expand Down Expand Up @@ -107,3 +109,48 @@ pub fn build(b: *std.Build) !void {
const xgettext_step = b.step("xgettext", "Generate nonograms.pot using xgettext");
xgettext_step.dependOn(&run_xgettext.step);
}

fn readLinguas(b: *std.Build) []const []const u8 {
const max_bytes = 16 * 1024; // 16KB
const raw = std.fs.cwd().readFileAlloc(b.allocator, b.pathFromRoot("po/LINGUAS"), max_bytes) catch |err|
std.debug.panic("failed to read LINGUAS: {}", .{err});

var linguas = std.ArrayList([]const u8).init(b.allocator);
defer linguas.deinit();
var lines = std.mem.splitScalar(u8, raw, '\n');
while (lines.next()) |line| {
const trimmed_line = std.mem.trim(u8, line, &std.ascii.whitespace);
if (std.mem.startsWith(u8, trimmed_line, "#")) continue;
var items = std.mem.tokenizeAny(u8, trimmed_line, &std.ascii.whitespace);
while (items.next()) |item| {
linguas.append(item) catch @panic("OOM");
}
}
return linguas.toOwnedSlice() catch @panic("OOM");
}

fn generateMetainfo(b: *std.Build, linguas: []const []const u8) std.Build.LazyPath {
const base = b.path("data/dev.ianjohnson.Nonograms.metainfo.xml");

const translate = b.addSystemCommand(&.{ "msgfmt", "--xml" });
addPoDependencies(b, translate, linguas);
translate.addPrefixedDirectoryArg("-d", b.path("po"));
translate.addPrefixedFileArg("--template=", base);
return translate.addPrefixedOutputFileArg("-o", "dev.ianjohnson.Nonograms.metainfo.xml");
}

fn generateDesktop(b: *std.Build, linguas: []const []const u8) std.Build.LazyPath {
const base = b.path("data/dev.ianjohnson.Nonograms.desktop");

const translate = b.addSystemCommand(&.{ "msgfmt", "--desktop" });
addPoDependencies(b, translate, linguas);
translate.addPrefixedDirectoryArg("-d", b.path("po"));
translate.addPrefixedFileArg("--template=", base);
return translate.addPrefixedOutputFileArg("-o", "dev.ianjohnson.Nonograms.desktop");
}

fn addPoDependencies(b: *std.Build, run: *std.Build.Step.Run, linguas: []const []const u8) void {
for (linguas) |lingua| {
run.addFileInput(b.path(b.fmt("po/{s}.po", .{lingua})));
}
}
11 changes: 6 additions & 5 deletions po/POTFILES.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
data/ui/color-button.ui
data/ui/color-picker.ui
data/ui/view.ui
data/ui/window.ui

data/dev.ianjohnson.Nonograms.desktop
data/dev.ianjohnson.Nonograms.metainfo.xml
data/resources/ui/color-button.ui
data/resources/ui/color-picker.ui
data/resources/ui/view.ui
data/resources/ui/window.ui
src/Library.zig
src/main.zig
src/pbn.zig
Expand Down
51 changes: 33 additions & 18 deletions po/nonograms.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Nonograms 0.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-23 20:43-0400\n"
"POT-Creation-Date: 2024-11-27 10:09-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -17,70 +17,85 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: data/ui/window.ui:4 data/ui/window.ui:23 src/main.zig:315
#: data/dev.ianjohnson.Nonograms.desktop:3
#: data/dev.ianjohnson.Nonograms.metainfo.xml:6 data/resources/ui/window.ui:4
#: data/resources/ui/window.ui:20
msgid "Nonograms"
msgstr ""

#: data/ui/window.ui:29
#: data/dev.ianjohnson.Nonograms.desktop:4
#: data/dev.ianjohnson.Nonograms.metainfo.xml:7
msgid "Solve nonogram puzzles"
msgstr ""

#: data/dev.ianjohnson.Nonograms.desktop:6
msgid "picross;paint-by-number;puzzle"
msgstr ""

#: data/dev.ianjohnson.Nonograms.metainfo.xml:12
msgid "Ian Johnson"
msgstr ""

#: data/resources/ui/window.ui:26
msgid "Main menu"
msgstr ""

#: data/ui/window.ui:36
#: data/resources/ui/window.ui:33
msgid "About this puzzle"
msgstr ""

#: data/ui/window.ui:100
#: data/resources/ui/window.ui:97
msgid "Library"
msgstr ""

#: data/ui/window.ui:133 src/main.zig:229
#: data/resources/ui/window.ui:130 src/main.zig:225
msgid "Puzzles"
msgstr ""

#: data/ui/window.ui:178
#: data/resources/ui/window.ui:175
msgid "Open"
msgstr ""

#: data/ui/window.ui:184
#: data/resources/ui/window.ui:181
msgid "Clear"
msgstr ""

#: data/ui/window.ui:190
#: data/resources/ui/window.ui:187
msgid "About"
msgstr ""

#: src/main.zig:170 src/main.zig:176
#: src/main.zig:166 src/main.zig:172
msgid "Failed to read library"
msgstr ""

#: src/main.zig:180
#: src/main.zig:176
msgid "Failed to add default puzzles to library"
msgstr ""

#: src/main.zig:190 src/main.zig:251
#: src/main.zig:186 src/main.zig:247
msgid "Untitled"
msgstr ""

#: src/main.zig:212
#: src/main.zig:208
msgid "Failed to load puzzle"
msgstr ""

#: src/main.zig:230
#: src/main.zig:226
msgid "Untitled puzzle set"
msgstr ""

#: src/main.zig:265
#: src/main.zig:261
msgid "Untitled puzzle"
msgstr ""

#: src/main.zig:294
#: src/main.zig:290
msgid "Open Puzzle"
msgstr ""

#: src/main.zig:297
#: src/main.zig:293
msgid "_Open"
msgstr ""

#: src/main.zig:298
#: src/main.zig:294
msgid "_Cancel"
msgstr ""

0 comments on commit b1d95f1

Please sign in to comment.