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-decl}}. Genera una taula de declinació d’un substantiu alemany. Vegeu la documentació de la plantilla per a la seva utilització.

local p = {}

local lang = {code = "de", name = "alemany", sc = "Latn"}
local m_links = require("Module:enllaç")

local function notEmpty(var)
	if var == nil or (type(var) == 'string' and mw.text.trim(var) == '') then
		return nil
	end
	return var
end

local function formExists(forms)
	for _, form in pairs(forms) do
		if type(form) == "table" then
			for _, subform in ipairs(form) do
				if type(subform) ~= "table" then
					subform = {term = subform}
				end
				if not mw.title.new(subform.term).exists then
					do return false end
				end
			end
		else
			if not mw.title.new(form).exists then
				do return false end
			end
		end
	end
	return true
end

local function tagForm(form, linked)
	if form == nil or form == "" then
		return
	elseif form == "-" then
		return form
	elseif linked then
		return m_links.full_link({term = form, lang = lang}, nil, false)
	end
	return m_links.tag_text(form, lang.code, lang.sc)
end

function p.show(frame)
	local args = frame:getParent().args
	local pagename = notEmpty(args.pagename) or mw.title.getCurrentTitle().subpageText
	local gender = notEmpty(args[1])
	local genitive = notEmpty(args[2]) or pagename .. (gender == "f" and "" or "s")
	local genitive2 = notEmpty(args.gen2)
	local plural = notEmpty(args[3])
	local plural2 = notEmpty(args.p2)
	
	if genitive ~= "?" then
		if genitive2 == genitive:gsub("es$", "s") then
			genitive2 = genitive
			genitive = genitive:gsub("es$", "s")
		end
	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
	
	-- Casos de declinació
	if not gender or genitive == "?" or plural == "?" or args.decl == "no" then
		return
	end
	local table_bot, categories = {}, {}
	local noms = pagename
	local nomp = plural
	local nom2p = plural2
	local gens = genitive
	local gen2s = genitive2
	local genp = nomp
	local gen2p = nom2p
	local dats = pagename
	local dat2s = ""
	local datp = args.datp or nomp .. (nomp:find("[erl]$") and "n" or "")
	local dat2p = nom2p and nom2p .. (nom2p:find("[ains]$") and "" or "n") or nil
	local acs = noms
	local acp = nomp
	local ac2p = nom2p
	
	if (gens == noms .. "s" and gen2s == noms .. "es") or (mw.ustring.find(noms, "[sßxz]$") and gens == noms .. "es") then -- cas (e)s/
		dat2s = noms .. "e"
	elseif gens == noms .. "ses" then -- s-Verdoppelung
		dat2s = noms .. "se"
	elseif gens == noms .. "n" and nomp == "-" then -- cas llengua
		dats = gens
	elseif gens == noms .. "en" or gens == noms .. "n" then -- cas (e)n/(e)n
		dats = gens
		acs = gens
	elseif gens == noms .. "ns" then -- cas ns/n
		dats = noms .. "n"
		acs = noms .. "n"
	elseif gens == noms .. "ens" then -- cas ens/en
		dat2s = noms .. "en"
	end
	
	-- enllaços de declinacions
	if dats ~= noms and dats ~= gens then
		table.insert(table_bot, {label = "datiu singular", dats})
	end
	dats = tagForm(dats, dats ~= noms and dats ~= gens)
	if dat2s ~= "" and dat2s ~= nomp then
		table.insert(table_bot, {label = "datiu literari", dat2s})
	end
	dat2s = tagForm(dat2s, dat2s ~= nomp)
	
	local decl_dat = {label = "datiu plural"}
	if datp ~= "-" and datp ~= nomp then
		table.insert(decl_dat, datp)
	end
	datp = tagForm(datp, datp ~= nomp)
	if dat2p and dat2p ~= nom2p then
		table.insert(decl_dat, dat2p)
	end
	dat2p = tagForm(dat2p, dat2p ~= nom2p)
	if decl_dat[1] then
		table.insert(table_bot, decl_dat)
	end
	
	if acs ~= noms and acs ~= gens then
		table.insert(table_bot, {label = "acusatiu singular", acs})
	end
	acs = tagForm(acs, acs ~= noms and acs ~= gens)
	
	local decl_gen = {label = "genitiu"}
	if gens ~= noms then
		table.insert(decl_gen, gens)
	end
	gens = tagForm(gens, gens ~= noms)
	if gen2s then
		table.insert(decl_gen, gen2s)
		gen2s = tagForm(gen2s, true)
	end
	if decl_gen[1] then
		table.insert(table_bot, decl_gen)
	end

	local decl_nom = {label = "plural"}
	if nomp ~= "-" and nomp ~= noms then
		table.insert(decl_nom, nomp)
	end
	nomp = tagForm(nomp, nomp ~= noms)
	if nom2p and nom2p ~= noms then
		table.insert(decl_nom, nom2p)
	end
	nom2p = tagForm(nom2p, nom2p ~= noms)
	if decl_nom[1] then
		table.insert(table_bot, decl_nom)
	end
	
	noms = tagForm(noms)
	genp = tagForm(genp)
	gen2p = tagForm(gen2p)
	acp = tagForm(acp)
	ac2p = tagForm(ac2p)
	
	local function makeTable()
		local art_nom_s, art_gen_s, art_dat_s, art_ac_s
		if gender == "f" then
			art_nom_s = tagForm("die")
			art_gen_s = tagForm("der")
			art_dat_s = tagForm("der")
			art_ac_s = tagForm("die")
		elseif gender == "n" then
			art_nom_s = tagForm("das")
			art_gen_s = tagForm("des")
			art_dat_s = tagForm("dem")
			art_ac_s = tagForm("das")
		else
			art_nom_s = tagForm("der")
			art_gen_s = tagForm("des")
			art_dat_s = tagForm("dem")
			art_ac_s = tagForm("den")
		end
		local art_nom_p, art_gen_p, art_dat_p, art_ac_p
		if nomp == "-" then
			art_nom_p = " "
			art_gen_p = " "
			art_dat_p = " "
			art_ac_p = " "
		else
			art_nom_p = tagForm("die")
			art_gen_p = tagForm("der")
			art_dat_p = tagForm("den")
			art_ac_p = tagForm("die")
		end
		
		local taula_decl = [=[ 
{| class="wikitable" style="margin-left: 0.5em; float: left; font-size: 90%;"
|- style="background:#EEEEEE"
| ''Cas''
| colspan="2" style="text-align:center;" | ''Singular''
| colspan="2" style="text-align:center;" | ''Plural''
|-
| style="background:#EEEEEE" | ''Nominatiu''
| style="border-right-width: 0px; padding-left: 1em;" | ]=] .. art_nom_s .. [=[ 
| style="border-left-width: 0px; padding-right: 1em;" | ]=] .. noms .. [=[ 
| style="border-right-width: 0px; padding-left: 1em;" | ]=] .. art_nom_p .. [=[ 
| style="border-left-width: 0px; padding-right: 1em;" | ]=] .. nomp .. (nom2p and "<br />" .. nom2p or "") .. [=[ 
|-
| style="background:#EEEEEE" | ''Genitiu''
| style="border-right-width: 0px; padding-left: 1em;;" | ]=] .. art_gen_s .. [=[ 
| style="border-left-width: 0px; padding-right: 1em;" | ]=] .. gens .. (gen2s and "<br />" .. gen2s or "") .. [=[ 
| style="border-right-width: 0px; padding-left: 1em;;" | ]=] .. art_gen_p .. [=[ 
| style="border-left-width: 0px; padding-right: 1em;" | ]=] .. genp .. (gen2p and "<br />" .. gen2p or "") .. [=[ 
|-
| style="background:#EEEEEE" | ''Datiu''
| style="border-right-width: 0px; padding-left: 1em;" | ]=] .. art_dat_s .. [=[ 
| style="border-left-width: 0px; padding-right: 1em;" | ]=] .. dats .. (dat2s and "<br />" .. dat2s or "") .. [=[ 
| style="border-right-width: 0px; padding-left: 1em;" | ]=] .. art_dat_p .. [=[ 
| style="border-left-width: 0px; padding-right: 1em;" | ]=] .. datp .. (dat2p and "<br />" .. dat2p or "") .. [=[ 
|-
| style="background:#EEEEEE" | ''Acusatiu''
| style="border-right-width: 0px; padding-left: 1em;" | ]=] .. art_ac_s .. [=[ 
| style="border-left-width: 0px; padding-right: 1em;" | ]=] .. acs .. [=[ 
| style="border-right-width: 0px; padding-left: 1em;" | ]=] .. art_ac_p .. [=[ 
| style="border-left-width: 0px; padding-right: 1em;" | ]=] .. acp .. (ac2p and "<br />" .. ac2p or "") .. [=[ 
|}
<br clear="all>]=]
		return taula_decl
	end
	
	-- Comprovació de flexions existents
	if not formExists(table_bot) then
		table.insert(categories, "Termes en alemany amb flexions a crear")
	end
	
	if args.bot then
		return require('Module:lema').make_bot_list(table_bot)
	else
		local ret = makeTable()
		if #categories > 0 then
			ret = ret .. require("Module:utilitats").format_categories(categories, lang)
		end
		return ret
	end
end

return p