Module:sei-noun

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module implements {{sei-decl-rel}}. Its usage will be expanded in the future.


local lang = require("Module:languages").getByCode("sei")

local export = {}

-- Make the table
local function make_table(data)
	local function repl(param)
		if param == "info" then
			return mw.getContentLanguage():ucfirst(data.info or "")
		end
		
		local forms = data.forms[param]
		
		if not forms then
			return "—"
		end

		local ret = {}
		
		for key, subform in ipairs(forms) do
			table.insert(ret, require("Module:links").full_link({lang = lang, term = subform}))
		end
		
		return table.concat(ret, "<br/>")
	end

	local wikicode = [=[
<div class="NavFrame" style="display: inline-block;min-width: 35em">
<div class="NavHead" style="background:#eff7ff" >{{{info}}}</div>
<div class="NavContent">
{| style="background:#F9F9F9;text-align:center;min-width:35em" class="inflection-table"
|-
! style="width:33%;background:#d9ebff"|
! style="background:#d9ebff" | singular
! style="background:#d9ebff" | plural
|-
! style="background: #eff7ff;" | Absolutive
| data-accel-col="2" | {{{absv|s}}}
| data-accel-col="3" | {{{absv|p}}}
|-
! style="background: #eff7ff;" | 1st person
| data-accel-col="2" | {{{first|s}}}
| data-accel-col="3" | {{{first|p}}}
|-
! style="background: #eff7ff;" | 2nd person
| data-accel-col="2" | {{{second|s}}}
| data-accel-col="3" | {{{second|p}}}
|-
! style="background: #eff7ff;" | 3rd person
| data-accel-col="2" | {{{third|s}}}
| data-accel-col="3" | {{{third|p}}}
|}</div></div>]=]

	return mw.ustring.gsub(wikicode, "{{{[#!]?([a-z0-9|]+)}}}", repl) .. require("Module:utilities").format_categories(data.categories, lang)
end

-- Inflection functions (common nouns)

function export.relative(frame)
	local args = frame:getParent().args
		
	local data = {
		forms = {},
		info = "Declension of ",
		categories = {},
	}
	
	-- add the base singular/plural forms
	local base

	if args[1] then
		base = args[1]
	elseif args["3s"] then
		base = args["3s"]
	else
		base = mw.title.getCurrentTitle().text
	end

	data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term")

	--absolutive forms
	if args["a"] then
		data.forms["absv|s"] = {args["a"]}
	end
	if args["ap"] then
		data.forms["absv|p"] = {args["ap"]}
	end
	
	--First person forms
	if args["1s"] then
		data.forms["first|s"] = {args["1s"]}
	end
	if args["1p"] then
		data.forms["first|p"] = {args["1p"]}
	end
	
	--Second person forms
	if args["2s"] then
		data.forms["second|s"] = {args["2s"]}
	end
	if args["2p"] then
		data.forms["second|p"] = {args["2p"]}
	end
	
	--Third person forms
	if args["3p"] then
		data.forms["third|p"] = {args["3p"]}
	end
	data.forms["third|s"] = {base}
	
	return make_table(data)
end

return export