A modult a Modul:cs-headword/doc lapon tudod dokumentálni

local export = {}
local pos_functions = {}

local lang = require("Module:languages").getByCode("cs")

-- Table of all valid genders, mapping to the spelled-out base gender
-- (used for validation and categorization).
local valid_genders_to_base_gender = {
	["m"] = "hímnemű",
	["m-an"] = "hímnemű",
	["m-in"] = "hímnemű",
	["m-p"] = "hímnemű",
	["f"] = "nőnemű",
	["f-p"] = "nőnemű",
	["n"] = "semlegesnemű",
	["n-p"] = "semlegesnemű",
}

local rfind = mw.ustring.find

local function format(array, concatenater)
	if #array == 0 then
		return ""
	else
		local concatenated = table.concat(array, concatenater)
		if concatenated == "" then
			return ""
		elseif concatenated:find("'$") then
			concatenated = concatenated .. " "
		end
		return "; ''" .. concatenated .. "''"
	end
end

local function glossary_link(anchor, text)
	text = text or anchor
	return "[[Appendix:Glossary#" .. anchor .. "|" .. text .. "]]"
end

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local NAMESPACE = mw.title.getCurrentTitle().nsText
	local PAGENAME = mw.title.getCurrentTitle().text

	local iparams = {
		[1] = {required = true},
		["def"] = {},
		["suff_type"] = {},
	}
	local iargs = require("Module:parameters").process(frame.args, iparams)
	local args = frame:getParent().args
	local poscat = iargs[1]
	local def = iargs.def
	local suff_type = iargs.suff_type
	local postype = nil
	if suff_type then
		postype = poscat .. '-' .. suff_type
	else
		postype = poscat
	end

	local data = {lang = lang, categories = {}, heads = {}, genders = {}, inflections = {}}
	local infl_classes = {}
	local appendix = {}
	local postscript = {}

	if poscat == "suffixes" then
		--table.insert(data.categories, "Czech " .. suff_type .. "-forming suffixes")
	end

	if pos_functions[postype] then
		local new_poscat = pos_functions[postype](def, args, data, infl_classes, appendix, postscript)
		if new_poscat then
			poscat = new_poscat
		end
	end

	data.pos_category = (NAMESPACE == "Reconstruction" and "reconstructed " or "") .. poscat
	
	postscript = table.concat(postscript, ", ")
	
	return
		require("Module:headword").full_headword(data)
		.. format(infl_classes, "/")
		.. format(appendix, ", ")
		.. (postscript ~= "" and " (" .. postscript .. ")" or "")
end

pos_functions["főnevek"] = function(def, args, data, infl_classes, appendix)
	local params = {
		["head"] = {list = true},
		[1] = {alias_of = "g"},
		["g"] = {list = true},
		["m"] = {list = true},
		["f"] = {list = true},
		["sort"] = {},
		["indecl"] = {type = boolean},
		["id"] = {},
	}

	local args = require("Module:parameters").process(args, params)
	data.heads = args.head
	data.sort = args.sort
	data.id = args.id

	for _, g in ipairs(args.g) do
		local base_gender = valid_genders_to_base_gender[g]
		if not base_gender then
			error("Unrecognized gender: '" .. g .. "'")
		end
		table.insert(data.categories, "cseh " .. base_gender .. " főnevek")
	end
	data.genders = args.g
	if args.indecl then
		table.insert(data.inflections, {label = glossary_link("indeclinable")})
	end
	local masc = args.m
	if #masc > 0 then
		masc.label = "hímnemű"
		table.insert(data.inflections, masc)
	end
	local fem = args.f
	if #fem > 0 then
		fem.label = "nőnemű"
		table.insert(data.inflections, fem)
	end
end

pos_functions["suffixes-noun"] = pos_functions["nouns"]

return export