A modult a Modul:labels/demo/doc lapon tudod dokumentálni

local export = {}

function export.examples(frame)
	local beginning =
[[
{| class="wikitable"
]]
	local caption = "|+ "

	local headers = 
[[
! code !! result
]]
	
	local row_template =
[[
|-
| {{{code}}} ||{{{middle}}} {{{result}}}
]]

	local middle
	
	local close = "|}"

	local rows = {}
	
	local params = {
		[1] = { required = true },
		["caption"] = {},
		["header"] = { type = "boolean" },
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	if args.caption then
		beginning = beginning .. caption .. args.caption .. "\n"
	end
	
	if args.header then
		beginning = beginning .. headers
		middle = ""
	else
		middle = " → || "
	end
	
	local examples = mw.text.split(args[1], ";%s+")
	
	if not examples then
		error("No examples were found in the first parameter")
	end
	
	for i, example in ipairs(examples) do
		local lang = mw.ustring.match(example, "^([^:]+)%:")
		if lang then
			example = mw.ustring.gsub(example, "^([^:]+):", "")
		end
		
		local parameters = mw.text.split(example, ",%s+") or example
		if type(parameters) ~= "table" then
			error('No parameters were found in "' .. example .. '".')
		end
		local template_params = {
			[1] = "label",
			[2] = lang,
		}
		
		for i, parameter in ipairs(parameters) do
			table.insert(template_params, parameter)
		end
		
		local code = require("Module:template link").format_link(template_params)
		local result = require("Module:labels").show_labels(parameters, require("Module:languages").getByCode(lang), nil, nil, nil, nil, true)
		
		local content = {
			code = code,
			middle = middle,
			result = result,
		}
		
		local function add_content(item)
			if content[item] then
				return content[item]
			end
		end
		
		local row = mw.ustring.gsub(row_template, "{{{(%w+)}}}", add_content)
		table.insert(rows, row)
	end
	
	return beginning .. table.concat(rows) .. close
end

return export