Difference between revisions of "Module:Int"

From WPRDC Wiki
Jump to navigation Jump to search
>Shirayuki
m (Undid revision 3961335 by Tacsipacsi (talk): broken; per Topic:Vqfgm9pzez1gbhu0)
>Tacsipacsi
(allow passing custom language, second try)
Line 15: Line 15:


     local msg = mw.message.new(mw.text.trim(args[1]), arguments)
     local msg = mw.message.new(mw.text.trim(args[1]), arguments)
     local lang = templateTranslation.getLanguage()
     local lang
    if args.lang and args.lang ~= '' and mw.language.isValidCode(args.lang) then
    lang = args.lang
    else
    lang = templateTranslation.getLanguage()
    end
     if (msg:exists() and not msg:isDisabled()) then
     if (msg:exists() and not msg:isDisabled()) then
         local msgstr = msg:inLanguage(lang):plain()
         local msgstr = msg:inLanguage(lang):plain()

Revision as of 19:50, 19 July 2020

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

-- This is a helper module for Template:int
local this = {}
local templateTranslation = require 'Module:Template translation'

function this.renderIntMessage(frame)
    local args = frame.args
    local pargs = (frame:getParent() or {}).args
    local arguments = {}
    for k, v in pairs(pargs) do
        local n = tonumber(k) or 0
        if (n >= 2) then
            arguments[n - 1] = mw.text.trim(v)
        end
    end

    local msg = mw.message.new(mw.text.trim(args[1]), arguments)
    local lang
    if args.lang and args.lang ~= '' and mw.language.isValidCode(args.lang) then
    	lang = args.lang
    else
    	lang = templateTranslation.getLanguage()
    end
    if (msg:exists() and not msg:isDisabled()) then
        local msgstr = msg:inLanguage(lang):plain()
        return frame:preprocess(msgstr)
    else
        return '⧼' .. args[1] .. '⧽'
    end
end

return this