Module:Wt/lij/Genere e numero

Sto template vizoalîza e anotaçioìn in sce génere e nùmero di lèmmi. O l'ûza Mòdolo:Génere e nùmero, e o sèrve cómme scorsaieu.

O no se ûza insémme a 'n template che o l'à za 'n scistêma de anotaçioìn pe-i géneri.

Védde ascì

edit

--[=[
	Sto mòdolo o crêa vizoalizaçioìn stàndard pe géneri e nùmeri.
	O convèrte 'na specificaçión de génere into formâto Wiki/HTML.
	
	'Na specificaçión de génere a l'é 'na lìsta de un di eleménti elencæ chi de sótta,
	separæ da-i tratìn. Dötréi ezénpi: "c", "n", "f-p", "m-an-p"
]=]--

local export = {}

local codes = {}

-- 'Na lìsta de tùtte e poscìbili pàrti che pêuan formâ 'na specificaçión.

codes["?"] = {type = "other", display = '<abbr title="génere inconplêto">?</abbr>'}

-- Géneri
codes["m"] = {type = "gender", display = '<abbr title="génere mascolìn">m</abbr>'}
codes["f"] = {type = "gender", display = '<abbr title="génere feminìn">f</abbr>'}
codes["n"] = {type = "gender", display = '<abbr title="génere néotro">n</abbr>'}
codes["c"] = {type = "gender", display = '<abbr title="génere comùn">c</abbr>'}

-- Animaçión
codes["an"] = {type = "animacy", display = '<abbr title="animòu">anim</abbr>'}
codes["in"] = {type = "animacy", display = '<abbr title="inanimòu">inan</abbr>'}

-- Personâ
codes["pr"] = {type = "personal", display = '<abbr title="personâ">pers</abbr>'}
codes["np"] = {type = "personal", display = '<abbr title="non-personâ">npers</abbr>'}

-- Nùmeri
codes["s"] = {type = "number", display = '<abbr title="nùmero scingolâre">sg</abbr>'}
codes["d"] = {type = "number", display = '<abbr title="nùmero doâle">du</abbr>'}
codes["p"] = {type = "number", display = '<abbr title="nùmero plurâle">pl</abbr>'}

-- Qualificatôi verbâli
codes["impf"] = {type = "perfectivity", display = '<abbr title="inperfetîvo">impf</abbr>'}
codes["pf"] = {type = "perfectivity", display = '<abbr title="perfetîvo">pf</abbr>'}

-- Versción de format_list ch'a se pêu invocâ da in template.
function export.show_list(frame)
	local args = frame.args
	local lang = args["lang"]; if lang == "" then lang = nil end
	local list = {}
	local i = 1
	
	while args[i] and args[i] ~= "" do
		table.insert(list, args[i])
		i = i + 1
	end
	
	return export.format_list(list, lang)
end

-- Format one or more gender specifications, in the form of a table of specifications.
function export.format_list(list, lang)
	local is_nounclass = nil
	
	-- Iterate over each specification and format it
	for key, spec in ipairs(list) do
		local nc
		list[key], nc = export.format_specification(spec, lang)
		
		-- Ensure that the specifications are either all noun classes, or none are.
		if is_nounclass == nil then
			is_nounclass = nc
		elseif is_nounclass ~= nc then
			error("Clàsse nominâli e géneri no se pêuan mescciâ. Pe piâxéi, ûza sôlo unn-a ò l'âtro")
		end
	end
	
	if is_nounclass then
		-- Add the processed codes together with slashes
		return "<span class=\"gender\">clàsse " .. table.concat(list, "/") .. "</span>"
	else
		-- Add the processed codes together with commas
		return "<span class=\"gender\">" .. table.concat(list, " or ") .. "</span>"
	end
end

-- Format the sub-parts of a single gender specification.
function export.format_specification(spec, lang)
	local categories = ""
	local ret = ""
	local is_nounclass = false
	
	-- If the specification starts with cX, then it is a noun class specification.
	if spec:find("^[1-9]") or spec:find("^c[^-]") then
		is_nounclass = true
		code = spec:gsub("^c", "")
		
		if code == "?" then
			ret = "<abbr class=\"noun-class\" title=\"clàsse nominâle mancànte\">?</abbr>"
		else
			ret = "<abbr class=\"noun-class\" title=\"clàsse nominâle " .. code .. "\">" .. code .. "</abbr>"
		end
	else
		local types = {}
		
		-- Split the parts and iterate over each part, converting it into its display form
		local parts = mw.text.split(spec, "-")
		
		for key, code in ipairs(parts) do
			-- Is this code valid?
			if not codes[code] then
				error("A specificaçión de génere \"" .. spec .. "\" a no l'é vàlida.")
			end
			
			if codes[code].type ~= "other" and types[codes[code].type] then
				--require("Module:debug").track("gender and number/multiple")
				--require("Module:debug").track("gender and number/multiple/" .. spec)
				error("A specificaçión de génere \"" .. spec .. "\" a contégne tag mùltipli de tîpo \"" .. codes[code].type .. "\".")
			end
				
			parts[key] = codes[code].display
			types[codes[code].type] = true
		end
		
		-- Add the processed codes together with non-breaking spaces
		ret = table.concat(parts, "&nbsp;")
	end
	
	-- Do some additional checks if a language was given
	if lang then
		-- Is this an incomplete gender?
		if spec:find("?") then
			local m_utilities = require("Module:utilities")
			categories = m_utilities.format_categories({"Richièste de azónta de génere inte vôxe in " .. lang:getCanonicalName()}, nil)
		end
		
		-- Check if the specification is valid
		--elseif langinfo.genders then
		--	local valid_genders = {}
		--	for _, g in ipairs(langinfo.genders) do valid_genders[g] = true end
		--	
		--	if not valid_genders[spec] then
		--		local valid_string = {}
		--		for i, g in ipairs(langinfo.genders) do valid_string[i] = g end
		--		error("The gender specification \"" .. spec .. "\" is not valid for " .. langinfo.names[1] .. ". Valid are: " .. table.concat(valid_string, ", "))
		--	end
		--end
	end
	
	return ret .. categories, is_nounclass
end

return export