Mòdul:de-lema

De Viccionari
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 de suport per la plantilla {{de-nom}}. Vegeu la documentació de la plantilla per a la seva utilització.

local p = {}

local lang = {code = "de", name = "alemany", sc = "Latn"}
local pos_functions = {}

-- Funció d'entrada per mostrar el lema flexionat, l'única que s'invoca des d'una plantilla
function p.flex(frame)
	local args = frame:getParent().args
	pagename = args.pagename
	if not pagename or pagename == "" then
		pagename = mw.title.getCurrentTitle().subpageText
	end
	
	local data = {lang = lang, heads = {}, genders = {}, inflections = {}, categories = {}}
	local lema = args.lema; if lema == "" then lema = nil end
	table.insert(data.heads, lema)

	local poscat = frame.args[1] or error("Falta especificar la categoria lèxica com a primer paràmetre.")
	if pos_functions[poscat] then
		pos_functions[poscat].func(args, data, declinacions)
	else
		table.insert(data.categories, poscat .. " en " .. lang.name)
	end
	if args.cat and args.cat ~= "" then
		table.insert(data.categories, args.cat)
	end
	
	return require("Mòdul:lema").full_headword(data)
end

-- Informació de flexió per a substantius
pos_functions["Substantius"] = {func = function(args, data, declinacions)
	local genere = args[1]; if genere == "" then genere = nil end
	local genere2 = args.g2; if genere2 == "" then genere2 = nil end
	local genere3 = args.g3; if genere3 == "" then genere3 = nil end
	local genitiu = args[2]; if genitiu == "" then genitiu = nil end
	local genitiu2 = args.gen2; if genitiu2 == "" then genitiu2 = nil end
	local genitiu3 = args.gen3; if genitiu3 == "" then genitiu3 = nil end
	local plural = args[3]; if plural == "" then plural = nil end
	local plural2 = args.p2; if plural2 == "" then plural2 = nil end
	local plural3 = args.p3; if plural3 == "" then plural3 = nil end
	local diminutiu = args[4]; if diminutiu == "" then diminutiu = nil end
	local diminutiu2 = args.dim2; if diminutiu2 == "" then diminutiu2 = nil end
	local femeni = args.f; if femeni == "" then femeni = nil end
	local masculi = args.m; if masculi == "" then masculi = nil end
	
	table.insert(data.genders, (genere and genere or "?") .. (genere2 and "-" .. genere2 .. (genere3 and "-" .. genere3 or "") or "") )

	if mw.ustring.find(pagename, "[^ ]+ [^ ]+") then
		table.insert(data.categories, "Locucions nominals en " .. lang.name)
	else
		table.insert(data.categories, "Substantius en " .. lang.name)
	end
	
	if not genitiu then
		genitiu = pagename .. (genere == "f" and "" or "s")
	end
	if genitiu ~= "?" then
		local infl_parts = {label = "genitiu", accel = "genitiu-form-of gender-" .. genere}
		if genitiu2 == genitiu:gsub("es$", "s") then
			genitiu2 = genitiu
			genitiu = genitiu:gsub("es$", "s")
		end
		table.insert(infl_parts, genitiu)
		if genitiu2 then
			table.insert(infl_parts, genitiu2)
			if genitiu3 then
				table.insert(infl_parts, genitiu3)
			end
		end
		table.insert(data.inflections, infl_parts)
	end
	
	if not plural then
		if pagename:find("e$") then
			plural = pagename .. "n"
		elseif pagename:find("in$") then
			plural = pagename .. "nen"
		else
			plural = pagename .. "en"
		end
	end
	if plural == "-" then
		table.insert(data.inflections, {label = "sense plural"})
	elseif plural ~= "?" then
		local infl_parts = {label = "plural", accel = "plural-form-of gender-" .. genere}
		table.insert(infl_parts, plural)
		if plural2 then
			table.insert(infl_parts, plural2)
			if plural3 then
				table.insert(infl_parts, plural3)
			end
		end
		table.insert(data.inflections, infl_parts)
	end
	
	if diminutiu then
		local infl_parts = {label = "diminutiu", accel = "diminutiva-form-of gender-" .. genere}
		table.insert(infl_parts, {term = diminutiu, genders = genere == "n" and "" or {"n"}})
		if diminutiu2 then
			table.insert(infl_parts, {term = diminutiu2, genders = genere == "n" and "" or {"n"}})
		end
		table.insert(data.inflections, infl_parts)
	end
	
	if femeni then
		table.insert(data.inflections, {label = "femení", femeni})
	end
	
	if masculi then
		table.insert(data.inflections, {label = "masculí", masculi})
	end
end
}

pos_functions["Adjectius"] = {func = function(args, data)
	local comp = {args[1], args.comp2}
	local sup = {args[2], args.sup2}
	local inv = args.decl == '-'
	
	if mw.ustring.find(pagename, "[^ ]+ [^ ]+") then
		table.insert(data.categories, "Locucions adjectivals en " .. lang.name)
	else
		table.insert(data.categories, "Adjectius en " .. lang.name)
	end
	
	if comp[1] == '-' then
		table.insert(data.inflections, {label = 'no comparable'})
		if inv then
			table.insert(data.inflections, {label = 'invariable'})
		end
		return
	end
	
	if #comp > 0 then
		for i, form in ipairs(comp) do
			comp[i] = {term = (form == 'er' and pagename .. 'er' or form)}
		end
		comp.label = 'comparatiu'
		comp.accel = 'comparativa-form-of'
		table.insert(data.inflections, comp)
	end
	
	if #sup > 0 then
		for i, form in ipairs(sup) do
			sup[i] = {term = 'am [[' ..  (form == 'sten' and pagename .. 'sten' or form) .. ']]'}
		end
		sup.label = 'superlatiu'
		sup.accel = 'superlativa-form-of'
		table.insert(data.inflections, sup)
	end
end
}

return p