diff --git a/src/core/Game3.lua b/src/core/Game3.lua index ba4ea5d8..929459f3 100644 --- a/src/core/Game3.lua +++ b/src/core/Game3.lua @@ -223,6 +223,11 @@ function Game3:_loadMods(opts) require("src.core.Logger").error( "mods failed to load, continuing without them: %s", tostring(loader)) end + -- After the merge, so a translation mod's catalog is what Strings() reads, + -- as Game (src/core/Game.lua) and Game2 do. Without it the catalog the + -- launcher preloaded (every enabled mod's lang/strings.lua, whatever game + -- it targets) stayed in place for the whole FireRed session. + require("src.core.Strings").load(self.data) local okC, Gen3Compat = pcall(require, "src.mods.Gen3Compat") if okC and type(Gen3Compat) == "table" and Gen3Compat.applyMerged then local okA, err = pcall(Gen3Compat.applyMerged, self) diff --git a/tests/game3_strings_catalog_test.lua b/tests/game3_strings_catalog_test.lua new file mode 100644 index 00000000..f79af69e --- /dev/null +++ b/tests/game3_strings_catalog_test.lua @@ -0,0 +1,37 @@ +#!/usr/bin/env luajit +-- Game3 hands the merged mod data to Strings.load, like Game and Game2, so a +-- translation mod's `strings` registry is what Strings() answers from. + +package.path = "./?.lua;./?/init.lua;" .. package.path +love = require("tests.love_stub") + +local failed = 0 +local function check(cond, msg) + if not cond then + failed = failed + 1 + print("[FAIL] " .. msg) + end +end + +local merged = { YES = "OUI" } +package.loaded["src.mods.Loader"] = { + new = function() + return { + load = function(_, data) data.strings = merged end, + status = function() return {} end, + } + end, +} +package.loaded["src.mods.Gen3Compat"] = { applyMerged = function() end } + +local Strings = require("src.core.Strings") +Strings.load({ strings = { YES = "LAUNCHER" } }) -- the launcher's preload +local Game3 = require("src.core.Game3") +local game = { data = {} } +Game3._loadMods(game, {}) + +check(Strings("YES") == "OUI", "Strings() answers from the merged catalog after mods load") +check(Strings("NO") == "NO", "an untranslated key still falls back to English") + +print(("game3_strings_catalog_test: %s (%d failed)"):format(failed == 0 and "PASS" or "FAIL", failed)) +if failed > 0 then os.exit(1) end