Module:User:Erutuon/labels/templates

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


local m_labels = require("Module:User:Erutuon/labels")
local m_params = require("Module:parameters")
local m_utilities = require("Module:utilities")
local m_languages = require("Module:languages")
local print_template = require("Module:template link").format_link

local export = {}

function export.show(frame)
	local compat = (frame.args or "") ~= ""
	local term_mode = (frame.args or "") ~= ""
	
	local params = {
		 = {required = true},
		 = {list = true},
		 = {type = "boolean"},
		 = {},
		 = {},
		 = {},
		 = {},
	}
	
	if compat then
		params = params
		params = nil
		params = {required = true}
	end
	
	local args = m_params.process(frame:getParent().args, params)
	
	-- Gather parameters
	local lang = args
	local labels = args
	local nocat = args
	local script = args
	local script2 = args
	local sort_key = args
	local sort_key2 = args

	if not lang then
		if mw.title.getCurrentTitle().nsText == "Template" then
			lang = "und"
		else
			error("Language code has not been specified. Please provide it to the template using the first parameter.")
		end
	end
	
	lang = m_languages.getByCode(lang) or m_languages.err(lang, compat and "lang" or 1)
	
	return m_labels.show_labels(labels, lang, script, script2, sort_key, sort_key2, nocat, term_mode)
end

--[[	temporary. intentionally undocumented.
		this function is only to be used in
		{{alternative spelling of}},
		{{eye dialect of}}
		and similar templates					]]
function export.show_from(frame)
	local m_labeldata = require('Module:labels/data')
	
	local froms = {}
	local categories = {}
	local args = frame:getParent().args
	local nocat = args
	local lang = args or "en"
	local limit = frame.args.limit and tonumber(frame.args.limit) or 99999
	
	lang = m_languages.getByCode(lang) or m_languages.err(lang, "lang")

	local key, i = 'from', 1
	while args do
		local k = args
		k = m_labeldata.aliases or k
		local data = m_labeldata.labels
		local label = data and data.display or k
		local category1, category2
		
		if not nocat and data then
			if data.regional_categories then
				for j, cat in ipairs(data.regional_categories) do
					category1 = cat .. ' ' .. lang:getCanonicalName()
				end
			end
		
			if data.plain_categories then
				for j, cat in ipairs(data.plain_categories) do
					category2 = cat
				end
			end
		end

		table.insert(froms, label)
		table.insert(categories, category1)
		table.insert(categories, category2)
		i = i + 1
		if i > limit then
			break	
		end
		key = 'from' .. i
	end
	
	categories = m_utilities.format_categories(categories, lang)
	
	if #froms == 0 then
		return frame.args.default
	end
	
	if #froms == 2 then
		return froms .. " and " .. froms .. categories
	end
	
	local results = {}
	for i, item in ipairs(froms) do
		if i == 1 then
			-- nothing
		elseif i == #froms then
			table.insert(results, '<span class="serial-comma">,</span> <span class="serial-and"> and</span> ')
		else
			table.insert(results, ', ')
		end
		
		table.insert(results, item)
	end
	return table.concat(results) .. categories
end

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 },
		 = {},
		 = { type = "boolean" },
	}
	
	local args = m_params.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 = " &rarr; || "
	end
	
	local examples = mw.text.split(args, ";%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 = {
			 = "label",
			 = lang,
		}
		
		for i, parameter in ipairs(parameters) do
			table.insert(template_params, parameter)
		end
		
		local code = print_template(template_params)
		local result = m_labels.show_labels(parameters, m_languages.getByCode(lang), nil, nil, nil, nil, 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