Module:Int

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:Int/doc

Code

-- 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