Module:Sandbox: Difference between revisions

test
mNo edit summary
 
(19 intermediate revisions by 4 users not shown)
Line 1: Line 1:
local function process_template(text, itemName)
This page is protected from editing. Please see [[Deadlock:User pages]].
    -- 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