Module:labels/templates

ពីWiktionary

Documentation for this module may be created at Module:labels/templates/doc

local export = {}

--[=[
	Modules used:
	[[Module:labels]]
	[[Module:parameters]]
	[[Module:utilities]]
	[[Module:languages]]
	[[Module:template_link]]
]=]

function export.show(frame)
	local parent_args = frame:getParent().args
	local compat = (frame.args["compat"] or "") ~= "" and parent_args["lang"]
	local term_mode = (frame.args["term"] or "") ~= ""
	
	local params = {
		[1] = {required = true},
		[2] = {list = true},
		["nocat"] = {type = "boolean"},
		["script"] = {},
		["script2"] = {},
		["sort"] = {},
		["sort2"] = {},
	}
	
	if compat then
		params[1] = params[2]
		params[2] = nil
		params["lang"] = {required = true}
	end
	
	local args = require("Module:parameters").process(parent_args, params)
	
	-- Gather parameters
	local lang = args[compat and "lang" or 1]
	local labels = args[compat and 1 or 2]
	local nocat = args["nocat"]
	local script = args["script"]
	local script2 = args["script2"]
	local sort_key = args["sort"]
	local sort_key2 = args["sort2"]

	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 = require("Module:languages").getByCode(lang) or require("Module:languages").err(lang, compat and "lang" or 1)
	
	return require("Module:labels").show_labels(labels, lang, script, script2, sort_key, sort_key2, nocat, term_mode)
end

return export