Module:bdk-noun

From Wiktionary, the free dictionary
Jump to navigation Jump to search
This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

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

local export = {}

function export.manual(frame)
	local params = {
		["abs_s"]     = {list = true},
		["erg_s"]     = {list = true},
		["gen_I_s"]   = {list = true},
		["gen_II_s"]  = {list = true},
		["dat_s"]     = {list = true},
		["ins_s"]     = {list = true},
		["loc_I_s"]   = {list = true},
		["abl_I_s"]   = {list = true},
		["loc_II_s"]  = {list = true},
		["abl_II_s"]  = {list = true},
		["loc_III_s"] = {list = true},
		["abl_III_s"] = {list = true},
		["abl_IV_s"]  = {list = true},

		["abs_p"]     = {list = true},
		["erg_p"]     = {list = true},
		["gen_I_p"]   = {list = true},
		["gen_II_p"]  = {list = true},
		["dat_p"]     = {list = true},
		["ins_p"]     = {list = true},
		["loc_I_p"]   = {list = true},
		["abl_I_p"]   = {list = true},
		["loc_II_p"]  = {list = true},
		["abl_II_p"]  = {list = true},
		["loc_III_p"] = {list = true},
		["abl_III_p"] = {list = true},
		["abl_IV_p"]  = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {
		forms = {},
		info = "",
		categories = {},
	}
	
	for param in pairs(params) do
		if args[param][1] then
			data.forms[(param:gsub("_", "|"))] = args[param]
		end
	end
	
	return make_table(data)
end


-- Make the table
function make_table(data)
	local function repl(param)
		local accel = true
		local no_store = false
		
		if param == "info" then
			return mw.getContentLanguage():ucfirst(data.info or "")
		elseif string.sub(param, 1, 1) == "!" then
			no_store = true
			param = string.sub(param, 2)
		elseif string.sub(param, 1, 1) == "#" then
			accel = false
			param = string.sub(param, 2)
		end
		
		local forms = data.forms[param]
		
		if not forms or not forms[1] then
			return "—"
		end
		
		local ret = {}
		
		for key, subform in ipairs(forms) do
			table.insert(ret, require("Module:links").full_link({lang = lang, term = subform, accel = accel and {form = param, no_store = no_store} or nil}))
		end
		
		return table.concat(ret, "<br/>")
	end
	
	local wikicode = [=[
{| class="inflection-table wikitable vsSwitcher" data-toggle-category="inflection"
|- style="text-align: left;"
! class="vsToggleElement" colspan="3" | {{{info}}}
|- class="vsShow"
! style="width: 9em;" | Absolutive&nbsp;sg.
| style="width: 15em;" colspan="2" | {{{!abs|s}}}
|- class="vsShow"
! Ergative&nbsp;sg.
| colspan="2" | {{{!erg|s}}}
|- class="vsShow"
! Absolutive&nbsp;pl.
| colspan="2" | {{{!abs|p}}}
|- class="vsHide"
! style="width: 9em;" |
! style="width: 12em;" | Singular
! style="width: 12em;" | Plural
|- class="vsHide"
! Absolutive
| data-accel-col="1" | {{{abs|s}}}
| data-accel-col="2" | {{{abs|p}}}
|- class="vsHide"
! Ergative
| data-accel-col="1" | {{{erg|s}}}
| data-accel-col="2" | {{{erg|p}}}
|- class="vsHide"
! Genitive I
| data-accel-col="1" | {{{gen|I|s}}}
| data-accel-col="2" | {{{gen|I|p}}}
|- class="vsHide"
! Genitive II
| data-accel-col="1" | {{{gen|II|s}}}
| data-accel-col="2" | {{{gen|II|p}}}
|- class="vsHide"
! Dative
| data-accel-col="1" | {{{dat|s}}}
| data-accel-col="2" | {{{dat|p}}}
|- class="vsHide"
! Instrumental
| data-accel-col="1" | {{{ins|s}}}
| data-accel-col="2" | {{{ins|p}}}
|- class="vsHide"
! Locative I
| data-accel-col="1" | {{{loc|I|s}}}
| data-accel-col="2" | {{{loc|I|p}}}
|- class="vsHide"
! Ablative I
| data-accel-col="1" | {{{abl|I|s}}}
| data-accel-col="2" | {{{abl|I|p}}}
|- class="vsHide"
! Locative II
| data-accel-col="1" | {{{loc|II|s}}}
| data-accel-col="2" | {{{loc|II|p}}}
|- class="vsHide"
! Ablative II
| data-accel-col="1" | {{{abl|II|s}}}
| data-accel-col="2" | {{{abl|II|p}}}
|- class="vsHide"
! Locative III
| data-accel-col="1" | {{{loc|III|s}}}
| data-accel-col="2" | {{{loc|III|p}}}
|- class="vsHide"
! Ablative III
| data-accel-col="1" | {{{abl|III|s}}}
| data-accel-col="2" | {{{abl|III|p}}}
|- class="vsHide"
! Ablative IV
| data-accel-col="1" | {{{abl|IV|s}}}
| data-accel-col="2" | {{{abl|IV|p}}}
|}]=]
	
	return mw.ustring.gsub(wikicode, "{{{([^{}]+)}}}", repl) .. require("Module:utilities").format_categories(data.categories, lang)
end

return export