Module:Lang: Difference between revisionsGive feedback
No edit summary |
integrated process_variables into get_string |
||
| Line 80: | Line 80: | ||
function p.get_string(key, lang_code_override, fallback_str, remove_var_index) | function p.get_string(key, lang_code_override, fallback_str, remove_var_index, item_name) | ||
-- Get frame object (either passed directly or via first argument) | -- Get frame object (either passed directly or via first argument) | ||
local frame | local frame | ||
| Line 89: | Line 89: | ||
fallback_str = frame.args["fallback_str"] | fallback_str = frame.args["fallback_str"] | ||
remove_var_index = frame.args["remove_var_index"] | remove_var_index = frame.args["remove_var_index"] | ||
item_name = frame.args["item_name"] | |||
else | else | ||
frame = mw.getCurrentFrame() | frame = mw.getCurrentFrame() | ||
| Line 112: | Line 113: | ||
local fallback | local fallback | ||
if (fallback_str == 'en') then | if (fallback_str == 'en') then | ||
fallback = p.get_string(key, 'en', key .. fallback_tooltip, remove_var_index) | fallback = p.get_string(key, 'en', key .. fallback_tooltip, remove_var_index, item_name) | ||
elseif fallback_str == 'dictionary' then | elseif fallback_str == 'dictionary' then | ||
return dictionary_module.translate(key, lang_code_override) | return dictionary_module.translate(key, lang_code_override) | ||
| Line 126: | Line 127: | ||
if (remove_var_index ~= nil) then | if (remove_var_index ~= nil) then | ||
label = util_module.remove_var(label, remove_var_index) | label = util_module.remove_var(label, remove_var_index) | ||
end | |||
-- Process variables if item_name is provided | |||
if item_name and item_name ~= '' then | |||
local item_data_module = require('Module:ItemData') | |||
label = label:gsub("{s:([^}]+)}", function(variable_name) | |||
-- Get the value from ItemData | |||
local value = item_data_module.get_prop({args = {item_name, variable_name}}) | |||
-- If value exists, remove non-number symbols (but keep + and -) | |||
if value then | |||
value = value:gsub("[^0-9+-]", "") | |||
-- Return empty string if nothing left, otherwise return the filtered value | |||
return value ~= "" and value or variable_name | |||
else | |||
return variable_name -- Fallback to variable name if value not found | |||
end | |||
end) | |||
end | end | ||