Skip to content

Commit 809fa4c

Browse files
committed
Load localization files from subfolders, resolves #1194
1 parent 8faa2c1 commit 809fa4c

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

lsp_def/utils.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,15 @@ function SMODS.SAVE_UNLOCKS() end
340340
function SMODS.process_loc_text(ref_table, ref_value, loc_txt, key) end
341341

342342
---@param path string
343+
--- This method is deprecated. Use SMODS.load_mod_localization instead.
343344
--- Handles injecting localization files.
344-
function SMODS.handle_loc_file(path) end
345+
function SMODS.handle_loc_file(path, mod_id) end
346+
347+
---@param path string The top level path of the mod that localization should be loaded from.
348+
---@param mod_id string The ID of the mod localization strings are being loaded for.
349+
---@param depth number Recursive calling depth. This function is called recursively to load localization files located in subfolders of a mod's localization folder up to four folders deep.
350+
--- Handles injecting a mod's localization files.
351+
function SMODS.load_mod_localization(path, mod_id, depth) end
345352

346353
---@param pool table[]
347354
---@param center metatable

src/game_object.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
400400
set = '[INTERNAL]',
401401
register = function() error('INTERNAL CLASS, DO NOT CALL') end,
402402
pre_inject_class = function()
403-
SMODS.handle_loc_file(SMODS.path, '_')
403+
SMODS.load_mod_localization(SMODS.path, '_')
404404
if SMODS.dump_loc then SMODS.dump_loc.pre_inject = copy_table(G.localization) end
405405
for _, mod in ipairs(SMODS.mod_list) do
406406
if mod.process_loc_text and type(mod.process_loc_text) == 'function' then
@@ -3910,7 +3910,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
39103910
pre_inject_class = function()
39113911
for _, mod in ipairs(SMODS.mod_list) do
39123912
if mod.can_load and not mod.lovely_only then
3913-
SMODS.handle_loc_file(mod.path, mod.id)
3913+
SMODS.load_mod_localization(mod.path, mod.id)
39143914
end
39153915
end
39163916
end

src/utils.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,24 @@ local function handle_loc_file(dir, language, force, mod_id)
219219
end
220220
end
221221

222-
function SMODS.handle_loc_file(path, mod_id)
223-
local dir = path .. 'localization/'
222+
function SMODS.load_mod_localization(path, mod_id, depth)
223+
local dir = path .. (depth and '' or 'localization/')
224+
depth = (depth or 0) + 1
224225
handle_loc_file(dir, 'en-us', true, mod_id)
225226
handle_loc_file(dir, 'default', true, mod_id)
226227
handle_loc_file(dir, G.SETTINGS.language, true, mod_id)
227228
if G.SETTINGS.real_language then handle_loc_file(dir, G.SETTINGS.real_language, true, mod_id) end
229+
if depth >= 4 then return end
230+
for _,v in ipairs(SMODS.NFS.getDirectoryItems(path)) do
231+
local new_path = dir .. v
232+
local file_type = SMODS.NFS.getInfo(new_path).type
233+
if file_type == 'directory' or file_type == 'symlink' then
234+
SMODS.load_mod_localization(new_path..'/', mod_id, depth)
235+
end
236+
end
228237
end
238+
-- deprecated, old identifier kept for compatibility
239+
SMODS.handle_loc_file = SMODS.load_mod_localization
229240

230241
function SMODS.insert_pool(pool, center, replace)
231242
assert(pool, ("Attempted to insert object \"%s\" into an empty pool."):format(center.key or "UNKNOWN"))

version.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
return "1.0.0~BETA-1416a-STEAMODDED"
1+
return "1.0.0~BETA-1419a-STEAMODDED"

0 commit comments

Comments
 (0)