Module:Localization

From Terraria Wiki
Jump to navigation Jump to search

No documentation subpage exists yet for this module. Create one now.


local ugsub = mw.ustring.gsub
local usub = mw.ustring.sub

------------------------------
return {
	-- replace all tokens in source string with replacement
	replace = function(frame)
		local str = frame.args['str']
		-- iterate over parameters
		for token, replace in pairs(frame:getParent().args) do
			if usub(token, 1, 1) == '$' then -- parameter name starts with the "$" character
				-- escape, to perform plain text replacement. see Module:String
				str = ugsub(str, (ugsub(token, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1")), (ugsub(replace, "%%", "%%%%" ))) -- () to force return only 1 value.
			end
		end
		return str
	end,
}