Module:Utilities: Difference between revisionsGive feedback
Jump to navigation
Jump to search
m remove_trailing_colon() initial |
added process_variables function |
||
| Line 188: | Line 188: | ||
-- Remove trailing colon | -- Remove trailing colon | ||
return (str:gsub(":$", "")) | return (str:gsub(":$", "")) | ||
end | |||
function p.process_variables(frame) | |||
-- Get arguments | |||
local string_key = frame.args[1] or '' | |||
local item_name = frame.args[2] or '' | |||
-- Load required modules | |||
local lang_module = require('Module:Lang') | |||
local item_data_module = require('Module:ItemData') | |||
-- Get the original text | |||
local original_text = lang_module.get_string(frame, string_key) or '' | |||
-- Process the text to replace variables with their values | |||
local processed_text = original_text:gsub("{s:([^}]+)}", function(variable_name) | |||
-- Get the value from ItemData | |||
local value = item_data_module.get_prop({args = {item_name, variable_name}}) | |||
return value or variable_name -- Fallback to variable name if value not found | |||
end) | |||
return processed_text | |||
end | end | ||
return p | return p | ||