跳转到内容

模組:Int

维基百科,自由的百科全书
--修改自[[mw:Module:Int]]
local int = {}

function int.int(frame)
    local args = frame.args
    local pargs = (frame:getParent() or {}).args
    local arguments = {}
    local arguments_subst = ''
    local arguments_qqx = ''
    for k, v in pairs(pargs) do
        local n = tonumber(k) or 0
        if (n >= 2) then
            arguments[n - 1] = mw.text.trim(v)
            arguments_subst = arguments_subst .. '|' .. mw.text.trim(v)
            arguments_qqx = arguments_qqx .. (n == 2 and ': ' or ', ') .. mw.text.trim(v)
        else
        end
    end
    if mw.isSubsting() then
        return '{{int:' .. args[1] .. arguments_subst ..'}}'
    else
        local msg = mw.message.new(mw.text.trim(args[1]), arguments)
        local lang = pargs['lang'] or args['lang'] or frame:callParserFunction{ name = 'int', args = {'Conversionname'} }
        if (frame:callParserFunction{ name = 'int', args = {'Lang'} } == 'qqx') then
            return '(' .. args[1] .. arguments_qqx .. ')'
        else
            if (msg:exists() and not msg:isDisabled()) then
                local msgstr = msg:inLanguage(lang):plain()
                return frame:preprocess(msgstr)
            else
                return '⧼' .. args[1] .. '⧽'
            end
        end
    end
end

return int