Terraria Wiki
Регистрация
Advertisement
Terraria Wiki
1735
страниц
См. также этот модуль на английском языке: Module:Localization. В нём может содержаться более полная или подробная информация.

Документация для этого модуля отсутствует. Создайте её.


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
			local isReplacementArg = usub(token, 1, 1) == '$' -- parameter name starts with the "$" character
			if frame.args['calledFromModule'] ~= nil and frame.args['calledFromModule'] ~= '' then
				-- if {{l10n/long}} was called from a module, then it is impossible to include the "$" character in a parameter name
				-- therefore, replacement arguments are not in the format of "$arg$", but "__arg" there
				isReplacementArg = usub(token, 1, 2) == '__'
				token = '$' .. usub(token, 3) .. '$' -- reformat "__arg" to "$arg$"
			end
			if isReplacementArg then
				-- 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,

}
Advertisement