Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Int: Difference between revisions

From Neodyland Wiki
m reduce the number of template expansion/preprocessings to save resources
Line 1: Line 1:
-- This is a helper module for [[Template:int]]
-- This is a helper module for [[Template:Int]]
local this = {}


function this.renderIntMessage(frame)
local trim = mw.text.trim
local isValidCode = mw.language.isValidCode
local messageNew = mw.message.new
 
local frameCurrent = mw.getCurrentFrame()
local preprocess = frameCurrent.preprocess
local pageLang = preprocess(frameCurrent, '{{PAGELANGUAGE}}')
 
local export = {}
 
function export.renderIntMessage(frame)
local args = frame.args
local args = frame.args
local msgId = trim(args[1])
local pargs = (frame:getParent() or {}).args
local pargs = (frame:getParent() or {}).args
local arguments = {}
local msgArgs = {}
for k, v in pairs(pargs) do
for k, v in pairs(pargs) do
local n = tonumber(k) or 0
local n = tonumber(k) or 0
if (n >= 2) then
if n >= 2 then
arguments[n - 1] = mw.text.trim(v)
msgArgs[n - 1] = trim(v)
end
end
end
end
 
local lang = args.lang
local lang
if not lang or lang == '' or not isValidCode(lang) then
if args.lang and args.lang ~= '' and mw.language.isValidCode(args.lang) then
lang = pageLang
lang = args.lang
else
lang = mw.getCurrentFrame():preprocess('{{PAGELANGUAGE}}')
end
end
local msg = mw.message.new(mw.text.trim(args[1]), arguments):inLanguage(lang)
local msg = messageNew(msgId, msgArgs):inLanguage(lang)
 
if lang == 'qqx' or msg:exists() then
if msg:exists() or lang == 'qqx' then
return msg:isDisabled() and (args.missing or '') or preprocess(frameCurrent, msg:plain())
if msg:isDisabled() then
return args.missing or ''
else
local msgstr = msg:plain()
return frame:preprocess(msgstr)
end
else
else
return args.missing ~= ''
return args.missing ~= '' and args.missing or '⧼' .. msgId .. '⧽'
and args.missing
or '⧼' .. args[1] .. '⧽'
end
end
end
end


return this
return export

Revision as of 15:31, 17 May 2024

Module documentation[ create · purge ]
This documentation is transcluded from Module:Int/doc.
-- This is a helper module for [[Template:Int]]

local trim = mw.text.trim
local isValidCode = mw.language.isValidCode
local messageNew = mw.message.new

local frameCurrent = mw.getCurrentFrame()
local preprocess = frameCurrent.preprocess
local pageLang = preprocess(frameCurrent, '{{PAGELANGUAGE}}')

local export = {}

function export.renderIntMessage(frame)
	local args = frame.args
	local msgId = trim(args[1])
	local pargs = (frame:getParent() or {}).args
	local msgArgs = {}
	for k, v in pairs(pargs) do
		local n = tonumber(k) or 0
		if n >= 2 then
			msgArgs[n - 1] = trim(v)
		end
	end
	local lang = args.lang
	if not lang or lang == '' or not isValidCode(lang) then
		lang = pageLang
	end
	local msg = messageNew(msgId, msgArgs):inLanguage(lang)
	if lang == 'qqx' or msg:exists() then
			return msg:isDisabled() and (args.missing or '') or preprocess(frameCurrent, msg:plain())
	else
		return args.missing ~= '' and args.missing or '⧼' .. msgId .. '⧽'
	end
end

return export
Cookies help us deliver our services. By using our services, you agree to our use of cookies.