Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Sandbox/Johnuniq/message

From Wikipedia, the free encyclopedia
-- Adapt message() from Module:Documentation/sandbox to test
-- Anomie's advice at [[WT:Lua#Module localisation]]:
--   mw.message.newRawMessage("text"):params("$1", "$2", "etc"):plain()
-- To see output, preview following in a sandbox:
--   {{#invoke:Sandbox/Johnuniq/message|main}}

local cfg = {
	invalid = 'Input "$1" is not a number',
	too_big = 'Input $1 should be less than $2',
}

local function message(cfgKey, valArray)
	local msg = cfg[cfgKey]
	if valArray then
		return mw.message.newRawMessage(msg):params(valArray):plain()
	end
	return msg
end

local tests = {
	{ 'invalid', { 'xyz' } },
	{ 'too_big', { '42', '12' } },
	{ 'too_big', { 42, 12 } },
}

local function main()
	local result = {}
	for _, t in ipairs(tests) do
		result[#result + 1] = '*' .. message(t[1], t[2]) .. '\n'
	end
	return table.concat(result)
end

return { main = main }