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

local m_headword = require("Module:headword")
local m_utilities = require("Module:utilities")

local export = {}
local pos_functions = {}

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

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local args = frame:getParent().args
	PAGENAME = mw.title.getCurrentTitle().text
	NAMESPACE = mw.title.getCurrentTitle().nsText
	
	local head = args["head"]; if head == "" then head = nil end
	
	-- The part of speech. This is also the name of the category that
	-- entries go in. However, the two are separate (the "cat" parameter)
	-- because you sometimes want something to behave as an adjective without
	-- putting it in the adjectives category.
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	local cat = args["cat"]; if cat == "" then cat = nil end
	
	local genders = {}
	local inflections = {}
	local categories = {"Galician " .. (cat or poscat)}
	
	if pos_functions[poscat] then
		pos_functions[poscat](args, genders, inflections, categories)
	end
	
	return
		m_headword.format_headword(head, lang, "Latn") ..
		m_headword.format_genders(genders, lang) ..
		m_headword.format_inflections(inflections, lang, "Latn") ..
		m_utilities.format_categories(categories, lang)
end

-- Display information for a noun's gender
-- This is separate so that it can also be used for proper nouns
function noun_gender(args, genders, inflections, categories)
	local categories = {}
	
	local gender = args[1]; if gender == "" then gender = nil end
	
	if gender == "m-p" or gender == "f-p" then
		table.insert(categories, "Galician pluralia tantum")
	end
	
	if gender == "mf" then
		table.insert(genders, "m")
		table.insert(genders, "f")
	else
		table.insert(genders, gender)
	end
 
	if #genders == 0 then
		table.insert(genders, "?")
	end
end

pos_functions["proper nouns"] = function(args, genders, inflections, categories)
	noun_gender(args, genders, inflections, categories)
end

-- Display additional inflection information for a noun
pos_functions["nouns"] = function(args, genders, inflections, categories)
	noun_gender(args, genders, inflections, categories)
	
	-- Plural
	if data.genders[1] == "m-p" or data.genders[1] == "f-p" then
		table.insert(data.inflections, {label = "[[Appendix:Glossary#plural only|plural only]]"})
	else
		local plural = args[2]; if plural == "" then plural = nil end
		
		if plural == "-" then
			table.insert(data.inflections, {label = "[[Appendix:Glossary#uncountable|uncountable]]"})
			table.insert(data.categories, "Galician uncountable nouns")
		else
			local infl_parts = {label = "plural", accel = {form = "p"}}
			local plural2 = args["pl2"]; if plural2 == "" then plural2 = nil end
			
			if not plural or plural == "s" then
				plural = PAGENAME .. "s"
			elseif plural == "es" then
				plural = PAGENAME .. "es"
			end
			
			table.insert(infl_parts, plural)
			
			if plural2 then
				table.insert(infl_parts, plural2)
			end
			if plural and not mw.title.new(plural).exists then
				table.insert(data.categories, "Galician nouns with missing plurals")
			end
			if plural2 and not mw.title.new(plural2).exists then
					table.insert(data.categories, "Galician nouns with missing plurals")
			end
			table.insert(inflections, infl_parts)
		end
	end
	
	-- Gendered forms
		local feminine = args["f"]; if feminine == "" then feminine = nil end
	local feminine_pl = args["fpl"]; if feminine_pl == "" then feminine_pl = nil end
	local masculine = args["m"]; if masculine == "" then masculine = nil end
	local masculine_pl = args["mpl"]; if masculine_pl == "" then masculine_pl = nil end
 
	if feminine then
		table.insert(inflections, {label = "feminine", feminine})
	end
	if feminine_pl then
		table.insert(inflections, {label = "feminine plural", feminine_pl})
	end
 
	if masculine then
		table.insert(inflections, {label = "masculine", masculine})
	end
	if masculine_pl then
		table.insert(inflections, {label = "masculine plural", masculine_pl})
	end
	
	return inflections, categories
end

function make_plural(base, gender)
	return base .. "s"
end

return export