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 {{la-adj-decl}} per a generar la taula de declinació d’un adjectiu en llatí. Vegeu la plantilla per al seu ús.

Utilitza com a suport: Mòdul:la-adj/decl i Mòdul:la-adj/taula.

local p = {}

local m_links = require("Module:enllaç")
local m_utilities = require("Module:utilitats")
local m_decl = require("Module:la-adj/decl")
local m_table = require("Module:la-adj/taula")

local lang = {code = "la", name = "llatí", sc = "Latn"}
NAMESPACE = NAMESPACE or mw.title.getCurrentTitle().nsText
PAGENAME = PAGENAME or mw.title.getCurrentTitle().text

local case_order = {
	"nom_s_m",
	"voc_s_m",
	"ac_s_m",
	"gen_s_m",
	"dat_s_m",
	"abl_s_m",
	"nom_s_f",
	"voc_s_f",
	"ac_s_f",
	"gen_s_f",
	"dat_s_f",
	"abl_s_f",
	"nom_s_n",
	"voc_s_n",
	"ac_s_n",
	"gen_s_n",
	"dat_s_n",
	"abl_s_n",
	"nom_p_m",
	"voc_p_m",
	"ac_p_m",
	"gen_p_m",
	"dat_p_m",
	"abl_p_m",
	"nom_p_f",
	"voc_p_f",
	"ac_p_f",
	"gen_p_f",
	"dat_p_f",
	"abl_p_f",
	"nom_p_n",
	"voc_p_n",
	"ac_p_n",
	"gen_p_n",
	"dat_p_n",
	"abl_p_n"
}

local function process(data, args)
	local noteindex = 1
	local notes = {}
	local redlink = false
	local ret_bot = ""
	for _, key in ipairs(case_order) do
		if args[key] or data.forms[key] then
			local user_specified = false
			if args[key] then
				val = args[key]
				user_specified = true
			else
				val = data.forms[key]
			end
			if type(val) == "string" then
				val = mw.text.split(val, "/")
			end
			if data.num == "p" and key:find("_s_") then
				data.forms[key] = ""
			elseif val[1] == "" or val == "" or val == {""} or val[1] == "-" or val[1] == "—" or val == "-" or val == "—" then
				data.forms[key] = "—"
			else
				for i, form in ipairs(val) do
					local word = data.prefix .. form .. data.suffix
					local title = m_links.sense_diacritics(lang.code, word)
					if args.bot then
						ret_bot = ret_bot .. "* " .. key .. "=" .. title .. "(" .. word .. ")\n"
					else
						if data.notes[key .. i] and not user_specified then
							val[i] = m_links.full_link({term = word, lang = lang}, nil, false) .. '<sup style="color: red">' .. noteindex .. '</sup>'
							table.insert(notes, '<sup style="color: red">' .. noteindex .. '</sup>' .. data.notes[key .. i])
							noteindex = noteindex + 1
						else
							val[i] = m_links.full_link({term = word, lang = lang}, nil, false)
						end
						if not redlink and NAMESPACE == '' then
							local t = mw.title.new(title)
							if t and not t.exists then
								table.insert(data.categories,'Termes en llatí amb flexions a crear')
								redlink = true
							end
						end
					end
				end
				data.forms[key] = table.concat(val, ", ")
			end
		end
	end
	data.bot = ret_bot
	data.footnote = table.concat(notes, "<br />") .. data.footnote
end

function p.show(frame)
	local data = {
		title = "",
		footnote = "",
		num = "",
		voc = true,
		forms = {},
		categories = {},
		notes = {},
	}

	local args = frame:getParent().args
	
	data.subtype = args["tipus"] or ""
	data.decl = args["decl"]
	data.num = args["nombre"] or ""
	data.prefix = args["prefix"] or ""
	data.suffix = args["sufix"] or ""
	data.forma1 = args[1] or ""
	data.forma2 = args[2] or ""
	data.forma3 = args[3] or ""
	if NAMESPACE == '' and (data.forma1 == '' or data.forma2 == '') then
		error("Falten paràmetres")
	end
	
	if data.decl and m_decl[data.decl] then
		m_decl[data.decl](data, args)
	elseif data.forma3 ~= "" then
		if data.forma2:match("a$") then
			m_decl["1i2"](data, args)
		elseif data.forma1:match("ic$") then
			data.subtype = data.subtype == '' and "ic" or data.subtype
			m_decl["1i2"](data, args)
		elseif data.forma2:match("is$") then
			m_decl["3-3"](data, args)
		end
	elseif data.forma2:match("e$") then
		m_decl["3-2"](data, args)
	elseif data.forma2:match("is$") then
		m_decl["3-1"](data, args)
	elseif data.forma1:match("or$") then
		m_decl["3-C"](data, args)
	end
	
	process(data, args)
	
	if args.bot then
		return data.bot
	else
		return m_table.make_table(data) .. m_utilities.format_categories(data.categories, lang)
	end
end

return p