Module:SandboxGive feedback
Documentation for this module may be created at Module:Sandbox/doc
local function process_template(text, itemName)
-- This pattern matches {s:SomePropertyName} in the text
return text:gsub("{s:([^}]+)}", function(property)
-- Construct the template call using the itemName parameter
local template = "{{#invoke:ItemData|get_prop|" .. itemName .. "|" .. property .. "}}"
return template
end)
end
function p.process_item_string(frame)
local args = frame.args
local parentArgs = frame:getParent().args
-- Get parameters - either from direct invocation or from parent frame
local stringKey = args[1] or parentArgs[1]
local itemName = args.item or parentArgs.item
if not stringKey or not itemName then
return "Error: Missing required parameters. Usage: {{#invoke:ItemStringProcessor|process_item_string|string_key|item=item_name}}"
end
-- First get the base string from the Lang module
local langModule = require("Module:Lang")
local baseString = langModule.get_string(frame, stringKey)
if not baseString then
return "Error: String key '" .. stringKey .. "' not found"
end
-- Process the string to replace property placeholders
local processedString = process_template(baseString, itemName)
return processedString
end