Module:Int: Difference between revisions
From Neodyland Wiki
More actions
use internal page language instead of an expensive module; no pages using legacy manual translation use this module anyway |
m 5 revisions imported |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
-- This is a helper module for [[Template: | -- This is a helper module for [[Template:Int]] | ||
function | 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 | 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 | if n >= 2 then | ||
msgArgs[n - 1] = trim(v) | |||
end | end | ||
end | end | ||
local lang = args.lang | |||
local | if not lang or lang == '' or not isValidCode(lang) then | ||
lang = pageLang | |||
if | |||
lang = | |||
end | 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 | else | ||
return args.missing ~= '' | return args.missing ~= '' and args.missing or '⧼' .. msgId .. '⧽' | ||
end | end | ||
end | end | ||
return | return export | ||
Latest revision as of 16:29, 12 August 2026
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