Module:labels/demo

Hello, you have come here looking for the meaning of the word Module:labels/demo. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:labels/demo, but we will also tell you about its etymology, its characteristics and you will know how to say Module:labels/demo in singular and plural. Everything you need to know about the word Module:labels/demo you have here. The definition of the word Module:labels/demo will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:labels/demo, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

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 = {
		 = { required = true, list = true },
		 = {},
		 = { 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
	
	for i, example in ipairs(args) do
		local lang, rest = mw.ustring.match(example, "^(+)%:(.*)$")
		if lang then
			example = rest
		else
			error("Examples must be preceded by a language code prefix, followed by a colon")
		end
		
		local parameters = mw.text.split(example, "~")
		local template_params = {
			lang,
		}
		
		for _, parameter in ipairs(parameters) do
			table.insert(template_params, parameter)
		end
		
		local code = require("Module:template parser").templateLink("label", template_params)
		local result = require("Module:labels").show_labels {
			labels = parameters,
			lang = require("Module:languages").getByCode(lang, i, "allow etym"),
			nocat = true
		}
		
		local content = {
			code = code,
			middle = middle,
			result = result,
		}
		
		local function add_content(item)
			if content then
				return content
			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