Mòdul:forma flexionada

De Viccionari
Salta a la navegació Salta a la cerca
Icona de documentació de mòdul Documentació del mòdul[mostra] [modifica] [refresca]

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]


Mòdul per presentar definicions de formes flexionades, declinades o conjugades. Les definicions es presenten en cursiva i enllaçant al lema principal. Dóna suport a la família de plantilla "forma-" de la Categoria:Plantilles de definicions de flexió. Vegeu la documentació de les plantilles per a la seva utilització.

local export = {}

local m_links = require("Mòdul:enllaç")

local inflection_tags = {
	-- Gènere
	["m"] = "masculí",
	["f"] = "femení",
	["n"] = "neutre",
	["c"] = "comú",
	
	-- Nombre
	["s"] = "singular",
	["p"] = "plural",
	["d"] = "dual",

	-- Gènere i nombre
	["ms"] = "masculí singular",
	["mp"] = "masculí plural",
	["fs"] = "femení singular",
	["fp"] = "femení plural",
	["ns"] = "neutre singular",
	["np"] = "neutre plural",
	
	-- Estat
	["def"] = "definit",
	["indef"] = "indefinit",
	
	-- Declinació
	["abl"] = "ablatiu",
	["abs"] = "absolutiu",
	["ac"] = "acusatiu",
	["al·l"] = "al·latiu",
	["aldir"] = "al·latiu direccional",
	["ben"] = "benefactiu",
	["caus"] = "causal",
	["com"] = "comitatiu",
	["dat"] = "datiu",
	["erg"] = "ergatiu",
	["gen"] = "genitiu",
	["genloc"] = "genitiu locatiu",
	["iness"] = "inessiu",
	["instr"] = "instrumental",
	["loc"] = "locatiu",
	["nom"] = "nominatiu",
	["partt"] = "partitiu",
	["prol"] = "prolatiu",
	["term"] = "terminatiu",
	["voc"] = "vocatiu",

	-- Conjugació
	-- Persona
	["1"] = "primera persona singular",
	["2"] = "segona persona singular",
	["3"] = "tercera persona singular",
	["4"] = "primera persona plural",
	["5"] = "segona persona plural",
	["6"] = "tercera persona plural",
 
	-- Temps
	["pres"] = "del present",
	["imperf"] = "de l'imperfet",
	["perf"] = "del perfet",
	["pret"] = "del pretèrit",
	["pass"] = "del passat",
	["fut"] = "del futur",
	["cond"] = "del condicional",

	-- Mode
	["imp"] = "de l'imperatiu",
	["ind"] = "d'indicatiu",
	["subj"] = "de subjuntiu",

	-- Veu
	["act"] = "actiu",
	["pas"] = "passiu",

	-- Impersonals
	["inf"] = "infinitiu",
	["part"] = "participi",
	["ger"] = "gerundi"
}

local pronoms = {}
pronoms["ca"] = {"jo", "tu", "[[ell]], [[ella]], [[vostè]]",
		"nosaltres", "[[vosaltres]], [[vós]]", "[[ells]], [[elles]], [[vostès]]"}
pronoms["de"] = {"ich", "du", "[[er]], [[sie]], [[es]]",
		"wir", "ihr", "sie"}
pronoms["fr"] = {"[[je]]/[[j']]", "tu", "[[il]], [[elle]], [[on]]",
		"nous", "vous", "[[ils]], [[elles]]"}
pronoms["it"] = {"io", "tu", "[[lui]]/[[lei]], [[esso]]/[[essa]]",
		"noi", "voi", "[[loro]], [[essi]]/[[esse]]"}
pronoms["oc"] = {"[[ieu]], [[jo]]", "tu", "[[el]]/[[eth]], [[ela]]/[[era]]",
		"[[nosautres]]/[[nosati]], [[nosautras]]/[[nosates]]", "[[vosautres]]/[[vosati]], [[vosautras]]/[[vosates]]", "[[eles]]/[[eri]], [[elas]]/[[eres]]"}
pronoms["pt"] = {"eu", "tu", "[[ele]], [[ela]], [[você]]",
		"nós", "vós", "[[eles]], [[elas]], [[vocês]]"}
pronoms["roa-oca"] = {"[[io]], [[yo]], [[jo]]", "tu", "[[él]], [[eyl]], [[ell]]",
		"[[nós]], [[nosaltres]]", "[[vós]], [[vosaltres]]", "[[éls]], [[eyls]], [[ells]]"}

local function get_terminfo(frame)
	local args = frame:getParent().args
	local iargs = frame.args
	
	local term = iargs["term"] or args[2]; if term == "" then term = nil end
	local alt = args["alt"]; if alt == "" then alt = nil end
	local lang = iargs["lang"] or args[1]; if lang == "" then lang = "ca" end
	local sc = iargs["sc"] or args["sc"]; if sc == "" then sc = nil end
	local id = iargs["id"] or args["id"]; if id == "" then id = nil end
	local gloss = args["glossa"]; if gloss == "" then gloss = nil end
	local tr = args["tr"]; if tr == "" then tr = nil end
	
	if not lang then
		lang = "ca"
	elseif not require("Mòdul:llengua").existeix(lang) then
		error("Codi de llengua incorrecte")
	end
	
	return {term = term, alt = alt, langcode = lang, sc = sc, id = id, gloss = gloss, tr = tr}
end

local function get_categories(frame, lang)
	local args = frame:getParent().args
	local iargs = frame.args
	
	local cat = iargs["cat"] or args["cat"]; if cat == "" then cat = nil end
	local cat2 = iargs["cat2"] or args["cat2"]; if cat2 == "" then cat2 = nil end
	
	local categories = {}
	if cat then table.insert(categories, cat) end
	if cat2 then table.insert(categories, cat2) end
	
	local ret = ""
	if #categories > 0  then
		ret = require("Mòdul:utilitats").format_categories(categories, lang, nil)
	end
	
	return ret
end
	
function format_t(text, terminfo, categories)
	if not terminfo.term then
		if mw.title.getCurrentTitle().nsText == "Plantilla" then
			terminfo.term = "terme"
		else
			error("No hi ha cap terme per enllaçar-hi.")
		end
	end
	
	if not text then
		error("No s'ha proporcionat cap definició.")
	end
	
	return
		"<i>" .. text .. "</i> "
		.. m_links.full_link(terminfo, "negreta", nil)
		.. categories
end

function export.form_of_t(frame)
	local text = frame.args[1]; if text == "" then text = nil end
	local terminfo = get_terminfo(frame)
	local categories = get_categories(frame, terminfo.langcode)
	
	return format_t(text, terminfo, categories)
end

function export.inflection_t(frame)
	local args = frame:getParent().args
	local terminfo = get_terminfo(frame)
	local categories = get_categories(frame, terminfo.langcode)
	
	local inflections = {}
	local i = 3
	local infl = args[i] or 'forma declinada'
	
	while infl do
		if infl ~= "" then
			table.insert(inflections, inflection_tags[infl] or infl)
			local person = tonumber(infl)
			-- tonumber("inf") returns number infinite instead of expected nil
			if person and person < 7 and pronoms[terminfo.langcode] then
				table.insert(inflections, "(" .. m_links.language_link({term = pronoms[terminfo.langcode][person], langcode = terminfo.langcode}) .. ")")
			end
		end
		
		i = i + 1
		infl = args[i]
	end
	
	return format_t(table.concat(inflections, " ") .. " de", terminfo, categories)
end

function export.form_eo_t(frame)
	local terminfo = get_terminfo(frame)
	local categories = get_categories(frame, terminfo.langcode)
	
	local args = frame:getParent().args
	local text = args[2]; if text == "" then text = nil end
	terminfo.term = args[1] or mw.title.getCurrentTitle().subpageText
	
	if not text then
		if terminfo.term:find("j$") then
			text = 'forma plural'
			terminfo.term = terminfo.term:gsub("j$", "")
		elseif terminfo.term:find("jn$") then
			text = 'acusatiu plural'
			terminfo.term = terminfo.term:gsub("jn$", "")
		elseif terminfo.term:find("n$") then
			text = 'acusatiu'
			terminfo.term = terminfo.term:gsub("n$", "")
		elseif terminfo.term:find("as$") then
			text = 'present'
			terminfo.term = terminfo.term:gsub("as$", "i")
		elseif terminfo.term:find("is$") then
			text = 'passat'
			terminfo.term = terminfo.term:gsub("is$", "i")
		elseif terminfo.term:find("os$") then
			text = 'futur'
			terminfo.term = terminfo.term:gsub("os$", "i")
		elseif terminfo.term:find("us$") then
			text = 'condicional'
			terminfo.term = terminfo.term:gsub("us$", "i")
		elseif terminfo.term:find("u$") then
			text = 'imperatiu'
			terminfo.term = terminfo.term:gsub("u$", "i")
		else
			text = 'forma desconeguda'
		end
	end
	
	return format_t(text .. " de", terminfo, categories)
end

return export