Module:pl-noun

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:pl-noun/documentation. [edit]
See also: subpages of this module.

This module implements {{pl-decl-noun}}, {{pl-decl-noun-sing}}, {{pl-decl-noun-pl}} and {{pl-decl-noun-dual}}.


local m_links = require('Module:links')
 
local export = {}
 
local lang = require("Module:languages").getByCode("pl")
 
local cases_en = {
	"nominative",
	"genitive",
	"dative",
	"accusative",
	"instrumental",
	"locative",
	"vocative"
}
 
local cases_pl = {
	"mianownik (kto? co?)",
	"dopełniacz (kogo? czego?)",
	"celownik (komu? czemu?)",
	"biernik (kogo? co?)",
	"narzędnik (kim? czym?)",
	"miejscownik (o kim? o czym?)",
	"wołacz (o!)"
}
 
local function make_table(items, heads, width, title, curtitle)
	local result = {}
 
	title = title or ('declension of <i class="Latn mention" lang="pl" xml:lang="pl">%s</i>'):format(items[1][1])
 
	if heads and (#heads > 0) then
		table.insert(result, '|-\n! style="width: 8em;" |\n')
		for _, head in ipairs(heads) do
			table.insert(result, ('! scope="col" | %s\n'):format(head))
		end
	end
 
	local maxl = 0
	for i = 1, 7 do
		table.insert(result, ('|-\n! title="%s" scope="row" | %s\n'):format(cases_pl[i], cases_en[i]))
		for _, item in ipairs(items[i]) do
			table.insert(result, (item == "-") and '| lang="" xml:lang="" title="none" | —\n' or ('| lang="pl" xml:lang="pl" | %s\n'):format(
				m_links.language_link(item, nil, lang, nil, curtitle)
			))
			if not width then -- speed
				local l = mw.ustring.len(m_links.remove_links(item))
				if maxl < l then
					maxl = l
				end
			end
		end
	end
 
	if not width then
		width = math.floor(maxl * 0.78) -- number obtained by anecdotal evidence
		width = (width < 10) and 10 or width
		width = 9 + (width * #heads)
	end
 
	return ([=[<div class="NavFrame inflection-table-noun" style="width: %uem">
<div class="NavHead">%s</div>
<div class="NavContent">
{| style="width: %uem; margin: 0;" class="wikitable inflection-table"
]=]):format(width, title, width) .. table.concat(result, "") .. "|}</div></div>"
end
 
local function make_table_sg(declinfo, width, curtitle)
	return make_table({
		{ declinfo.nom },
		{ declinfo.gen },
		{ declinfo.dat },
		{ declinfo.acc },
		{ declinfo.ins },
		{ declinfo.loc },
		{ declinfo.voc }
	}, { "singular only" }, width, nil, curtitle)
end
 
local function make_table_pl(declinfo, width, curtitle)
	return make_table({
		{ declinfo.nomp },
		{ declinfo.genp },
		{ declinfo.datp },
		{ declinfo.accp },
		{ declinfo.insp },
		{ declinfo.locp },
		{ declinfo.vocp }
	}, { "plural only" }, width, nil, curtitle)
end
 
local function make_table_dual(declinfo, width, curtitle)
	return make_table({
		{ declinfo.nom, declinfo.nomd, declinfo.nomp },
		{ declinfo.gen, declinfo.gend, declinfo.genp },
		{ declinfo.dat, declinfo.datd, declinfo.datp },
		{ declinfo.acc, declinfo.accd, declinfo.accp },
		{ declinfo.ins, declinfo.insd, declinfo.insp },
		{ declinfo.loc, declinfo.locd, declinfo.locp },
		{ declinfo.voc, declinfo.vocd, declinfo.vocp }
	}, { "singular", "dual", "plural" }, width, nil, curtitle)
end
 
local function make_table_both(declinfo, width, curtitle)
	return make_table({
		{ declinfo.nom, declinfo.nomp },
		{ declinfo.gen, declinfo.genp },
		{ declinfo.dat, declinfo.datp },
		{ declinfo.acc, declinfo.accp },
		{ declinfo.ins, declinfo.insp },
		{ declinfo.loc, declinfo.locp },
		{ declinfo.voc, declinfo.vocp }
	}, { "singular", "plural" }, width, nil, curtitle)
end
 
local function get_mode()
	local frame = mw.getCurrentFrame()
	if frame.args.subst == 'SUBST' then
		return 'subst'
	elseif frame.args.subst == 'substcheck' then
		return 'demo'
	else
		return 'xclude'
	end
end
 
function export.template_decl_noun_dual(frame)
	local pargs = frame:getParent().args
	local width = pargs.width and tonumber(pargs.width)
	local title = mw.title.getCurrentTitle()
 
	local declinfo
	if get_mode() == 'demo' then
		declinfo = {
			nom = '{{{nom| {{{1}}} }}}' , nomd = '{{{nomd| {{{2}}} }}}' , nomp = '{{{nomp| {{{3}}} }}}',
			gen = '{{{gen| {{{4}}} }}}' , gend = '{{{gend| {{{5}}} }}}' , genp = '{{{genp| {{{6}}} }}}',
			dat = '{{{dat| {{{7}}} }}}' , datd = '{{{datd| {{{8}}} }}}' , datp = '{{{datp| {{{9}}} }}}',
			acc = '{{{acc| {{{10}}} }}}', accd = '{{{accd| {{{11}}} }}}', accp = '{{{accp| {{{12}}} }}}',
			ins = '{{{ins| {{{13}}} }}}', insd = '{{{insd| {{{14}}} }}}', insp = '{{{insp| {{{15}}} }}}',
			loc = '{{{loc| {{{16}}} }}}', locd = '{{{locd| {{{17}}} }}}', locp = '{{{locp| {{{18}}} }}}',
			voc = '{{{voc| {{{19}}} }}}', vocd = '{{{vocd| {{{20}}} }}}', vocp = '{{{vocp| {{{21}}} }}}'
		}
	else
		declinfo = {
			nom = mw.text.trim(pargs.nom or pargs[ 1]), nomd = mw.text.trim(pargs.nomd or pargs[ 2]), nomp = mw.text.trim(pargs.nomp or pargs[ 3]),
			gen = mw.text.trim(pargs.gen or pargs[ 4]), gend = mw.text.trim(pargs.gend or pargs[ 5]), genp = mw.text.trim(pargs.genp or pargs[ 6]),
			dat = mw.text.trim(pargs.dat or pargs[ 7]), datd = mw.text.trim(pargs.datd or pargs[ 8]), datp = mw.text.trim(pargs.datp or pargs[ 9]),
			acc = mw.text.trim(pargs.acc or pargs[10]), accd = mw.text.trim(pargs.accd or pargs[11]), accp = mw.text.trim(pargs.accp or pargs[12]),
			ins = mw.text.trim(pargs.ins or pargs[13]), insd = mw.text.trim(pargs.insd or pargs[14]), insp = mw.text.trim(pargs.insp or pargs[15]),
			loc = mw.text.trim(pargs.loc or pargs[16]), locd = mw.text.trim(pargs.locd or pargs[17]), locp = mw.text.trim(pargs.locp or pargs[18]),
			voc = mw.text.trim(pargs.voc or pargs[19]), vocd = mw.text.trim(pargs.vocd or pargs[20]), vocp = mw.text.trim(pargs.vocp or pargs[21])
		}
	end
 
	return make_table_dual(declinfo, width, title.fullText)
end
 
function export.template_decl_noun_pl(frame)
	local pargs = frame:getParent().args
	local width = pargs.width and tonumber(pargs.width)
	local title = mw.title.getCurrentTitle()
 
	local declinfo
	if get_mode() == 'demo' then
		declinfo = {
			nom = '{{{nom}}}', nomd = '{{{nomd}}}', nomp = '{{{nomp| {{{1}}} }}}',
			gen = '{{{gen}}}', gend = '{{{gend}}}', genp = '{{{genp| {{{2}}} }}}',
			dat = '{{{dat}}}', datd = '{{{datd}}}', datp = '{{{datp| {{{3}}} }}}',
			acc = '{{{acc}}}', accd = '{{{accd}}}', accp = '{{{accp| {{{4}}} }}}',
			ins = '{{{ins}}}', insd = '{{{insd}}}', insp = '{{{insp| {{{5}}} }}}',
			loc = '{{{loc}}}', locd = '{{{locd}}}', locp = '{{{locp| {{{6}}} }}}',
			voc = '{{{voc}}}', vocd = '{{{vocd}}}', vocp = '{{{vocp| {{{7}}} }}}'
		}
	else
		declinfo = {
			nomp = mw.text.trim(pargs.nomp or pargs[1]),
			genp = mw.text.trim(pargs.genp or pargs[2]),
			datp = mw.text.trim(pargs.datp or pargs[3]),
			accp = mw.text.trim(pargs.accp or pargs[4]),
			insp = mw.text.trim(pargs.insp or pargs[5]),
			locp = mw.text.trim(pargs.locp or pargs[6]),
			vocp = mw.text.trim(pargs.vocp or pargs[7])
		}
	end
 
	return make_table_pl(declinfo, width, title.fullText)
end
 
function export.template_decl_noun_sg(frame)
	local pargs = frame:getParent().args
	local width = pargs.width and tonumber(pargs.width)
	local title = mw.title.getCurrentTitle()
 
	local declinfo
	if get_mode() == 'demo' then
		declinfo = {
			nom = '{{{nom| {{{1}}} }}}', nomd = '{{{nomd}}}', nomp = '{{{nomp}}}',
			gen = '{{{gen| {{{2}}} }}}', gend = '{{{gend}}}', genp = '{{{genp}}}',
			dat = '{{{dat| {{{3}}} }}}', datd = '{{{datd}}}', datp = '{{{datp}}}',
			acc = '{{{acc| {{{4}}} }}}', accd = '{{{accd}}}', accp = '{{{accp}}}',
			ins = '{{{ins| {{{5}}} }}}', insd = '{{{insd}}}', insp = '{{{insp}}}',
			loc = '{{{loc| {{{6}}} }}}', locd = '{{{locd}}}', locp = '{{{locp}}}',
			voc = '{{{voc| {{{7}}} }}}', vocd = '{{{vocd}}}', vocp = '{{{vocp}}}'
		}
	else
		declinfo = {
			nom = mw.text.trim(pargs.nom or pargs[1]),
			gen = mw.text.trim(pargs.gen or pargs[2]),
			dat = mw.text.trim(pargs.dat or pargs[3]),
			acc = mw.text.trim(pargs.acc or pargs[4]),
			ins = mw.text.trim(pargs.ins or pargs[5]),
			loc = mw.text.trim(pargs.loc or pargs[6]),
			voc = mw.text.trim(pargs.voc or pargs[7])
		}
	end
 
	return make_table_sg(declinfo, width, title.fullText)
end
 
function export.template_decl_noun(frame)
	local pargs = frame:getParent().args
	local width = pargs.width and tonumber(pargs.width)
	local title = mw.title.getCurrentTitle()
 
	local declinfo 
	if get_mode() == 'demo' then
		declinfo = {
			nom = '{{{nom| {{{1}}} }}}' , nomd = '{{{nomd}}}', nomp = '{{{nomp| {{{2}}} }}}',
			gen = '{{{gen| {{{3}}} }}}' , gend = '{{{gend}}}', genp = '{{{genp| {{{4}}} }}}',
			dat = '{{{dat| {{{5}}} }}}' , datd = '{{{datd}}}', datp = '{{{datp| {{{6}}} }}}',
			acc = '{{{acc| {{{7}}} }}}' , accd = '{{{accd}}}', accp = '{{{accp| {{{8}}} }}}',
			ins = '{{{ins| {{{9}}} }}}' , insd = '{{{insd}}}', insp = '{{{insp| {{{10}}} }}}',
			loc = '{{{loc| {{{11}}} }}}', locd = '{{{locd}}}', locp = '{{{locp| {{{12}}} }}}',
			voc = '{{{voc| {{{13}}} }}}', vocd = '{{{vocd}}}', vocp = '{{{vocp| {{{14}}} }}}'
		}
	else
		declinfo = {
			nom = mw.text.trim(pargs.nom or pargs[ 1]), nomp = mw.text.trim(pargs.nomp or pargs[ 2]),
			gen = mw.text.trim(pargs.gen or pargs[ 3]), genp = mw.text.trim(pargs.genp or pargs[ 4]),
			dat = mw.text.trim(pargs.dat or pargs[ 5]), datp = mw.text.trim(pargs.datp or pargs[ 6]),
			acc = mw.text.trim(pargs.acc or pargs[ 7]), accp = mw.text.trim(pargs.accp or pargs[ 8]),
			ins = mw.text.trim(pargs.ins or pargs[ 9]), insp = mw.text.trim(pargs.insp or pargs[10]),
			loc = mw.text.trim(pargs.loc or pargs[11]), locp = mw.text.trim(pargs.locp or pargs[12]),
			voc = mw.text.trim(pargs.voc or pargs[13]), vocp = mw.text.trim(pargs.vocp or pargs[14])
		}
	end
 
	return make_table_both(declinfo, width, title.fullText)
end
 
return export