build(i18n): embed language JSON only on Windows, add lookup fallbacks
CMake turned every res/lang/*.json into an xxd header that i18n.cpp compiled in as a fallback, on every platform. Only the Windows single-file exe needs it: the Linux zip and AppImage and the macOS .app always ship res/lang, and loadLanguage() reads the loose file first. On Linux the embedded copy added about 1.5 MB to the binary, and every translation edit recompiled i18n.cpp. A new option, DRAGONX_EMBED_LANG, defaults to ON for WIN32 and OFF elsewhere: - ON without xxd is now a configure error (it used to warn, then fail to compile i18n.cpp on the missing headers); - i18n.cpp compiles the embedded includes and the fallback only when ON; - outside Windows, loadLanguage() also tries <exe>/../share/<app>/res/lang (the cmake --install layout and the full-node AppImage) and <exe>/../Resources/res/lang (the macOS .app binary run directly), so those layouts find the loose files whatever the working directory; before, only the embedded copy covered that. Measured: - full-node Linux binary: .data 1,699,696 -> 168,592 bytes; stripped 19,983,136 -> 18,456,128 bytes (-1.53 MB); - with the ImGui demo stubs, the Linux zips and AppImages are 0.50-0.55 MB smaller, with identical file lists including all 8 language files; - a Lite build started from an unrelated working directory loads the ja.json next to the binary (2422 strings), and the packaged Lite zip and AppImage load ja.json with no new not-found or failed lines; - Windows keeps the embedded copy: the 8 language headers are generated and the ja.json bytes are in the exe. A new test loads "de" from the loose files and checks a translated string; with bin/res/lang moved away exactly its two assertions fail. Behaviour changes on Linux and macOS: a missing or corrupt res/lang now falls back to English instead of the embedded copy, and a translation edit needs only the copy_langs step instead of a recompile. Not verifiable here: the macOS .app in a non-English language, and the Windows single-file exe at runtime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15320,6 +15320,18 @@ void testTextFitBanner()
|
||||
EXPECT_EQ(calls, 6);
|
||||
}
|
||||
}
|
||||
|
||||
// Linux/macOS builds no longer embed res/lang (DRAGONX_EMBED_LANG=OFF), so a translation must load from the
|
||||
// loose copy beside the binary (copy_langs puts res/lang in bin/, next to this test). Windows (ON) passes
|
||||
// through either the loose or the embedded copy.
|
||||
void testLoadLanguageFromLooseFiles()
|
||||
{
|
||||
auto& i18n = dragonx::util::I18n::instance();
|
||||
EXPECT_TRUE(i18n.loadLanguage("de"));
|
||||
EXPECT_TRUE(std::string(i18n.translate("overview")) != "Overview"); // de.json: "Übersicht"
|
||||
EXPECT_TRUE(i18n.loadLanguage("en")); // restore the built-in English table
|
||||
EXPECT_EQ(std::string(i18n.translate("overview")), std::string("Overview"));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
@@ -15569,6 +15581,7 @@ int main()
|
||||
testChatThreadLayout();
|
||||
testTextFit();
|
||||
testTextFitBanner();
|
||||
testLoadLanguageFromLooseFiles();
|
||||
|
||||
if (g_failures != 0) {
|
||||
std::cerr << g_failures << " test assertion(s) failed\n";
|
||||
|
||||
Reference in New Issue
Block a user