This module implements {{eu-decl-anim}} and {{eu-decl-inanim}}, among other templates. Its usage will be expanded to proper nouns in the future.


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

local export = {}

local function postprocess(args, data)
	data.lemma = data.forms["absv|indef"][1]
	
	-- Check if the lemma form matches the page name
	if (lang:makeEntryName(data.lemma)) ~= mw.title.getCurrentTitle().text then
		table.insert(data.categories, lang:getCanonicalName() .. " entries with inflection not matching pagename")
	end
end

-- Table-generating functions
local function make_table(data, tbl_type)
	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 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, lemma = data.lemma, no_store = no_store} or nil}))
		end
		
		return table.concat(ret, "<br/>")
	end
	
	local wikicode
	if tbl_type == "st" then
		wikicode = [=[
<div class="NavFrame" style="display: inline-block;min-width: 50em">
<div class="NavHead" style="background:#eff7ff" >{{{info}}}</div>
<div class="NavContent">
{| style="background:#F9F9F9;text-align:center;min-width:50em" class="inflection-table"
|- 
! style="width:25%;background:#d9ebff" |
! style="background:#d9ebff" | indefinite
! style="background:#d9ebff" | singular
! style="background:#d9ebff" | plural
|-
! style="background: #eff7ff;" | absolutive
| data-accel-col="1" | {{{absv|indef}}}
| data-accel-col="2" | {{{absv|s}}}
| data-accel-col="3" | {{{absv|p}}}
|-
! style="background: #eff7ff;" | ergative
| data-accel-col="1" | {{{erg|indef}}}
| data-accel-col="2" | {{{erg|s}}}
| data-accel-col="3" | {{{erg|p}}}
|-
! style="background: #eff7ff;" | dative
| data-accel-col="1" | {{{dat|indef}}}
| data-accel-col="2" | {{{dat|s}}}
| data-accel-col="3" | {{{dat|p}}}
|-
! style="background: #eff7ff;" | genitive
| data-accel-col="1" | {{{gen|indef}}}
| data-accel-col="2" | {{{gen|s}}}
| data-accel-col="3" | {{{gen|p}}}
|-
! style="background: #eff7ff;" | comitative
| data-accel-col="1" | {{{com|indef}}}
| data-accel-col="2" | {{{com|s}}}
| data-accel-col="3" | {{{com|p}}}
|-
! style="background: #eff7ff;" | causative
| data-accel-col="1" | {{{caus|indef}}}
| data-accel-col="2" | {{{caus|s}}}
| data-accel-col="3" | {{{caus|p}}}
|-
! style="background: #eff7ff;" | benefactive
| data-accel-col="1" | {{{ben|indef}}}
| data-accel-col="2" | {{{ben|s}}}
| data-accel-col="3" | {{{ben|p}}}
|-
! style="background: #eff7ff;" | instrumental
| data-accel-col="1" | {{{ins|indef}}}
| data-accel-col="2" | {{{ins|s}}}
| data-accel-col="3" | {{{ins|p}}}
|-
! style="background: #eff7ff;" | inessive
| data-accel-col="1" | {{{ine|indef}}}
| data-accel-col="2" | {{{ine|s}}}
| data-accel-col="3" | {{{ine|p}}}
|-
! style="background: #eff7ff;" | locative
| data-accel-col="1" | {{{loc|indef}}}
| data-accel-col="2" | {{{loc|s}}}
| data-accel-col="3" | {{{loc|p}}}
|-
! style="background: #eff7ff;" | allative
| data-accel-col="1" | {{{all|indef}}}
| data-accel-col="2" | {{{all|s}}}
| data-accel-col="3" | {{{all|p}}}
|-
! style="background: #eff7ff;" | terminative
| data-accel-col="1" | {{{ter|indef}}}
| data-accel-col="2" | {{{ter|s}}}
| data-accel-col="3" | {{{ter|p}}}
|-
! style="background: #eff7ff;" | directive
| data-accel-col="1" | {{{directive|indef}}}
| data-accel-col="2" | {{{directive|s}}}
| data-accel-col="3" | {{{directive|p}}}
|-
! style="background: #eff7ff;" | destinative
| data-accel-col="1" | {{{destinative|indef}}}
| data-accel-col="2" | {{{destinative|s}}}
| data-accel-col="3" | {{{destinative|p}}}
|-
! style="background: #eff7ff;" | ablative
| data-accel-col="1" | {{{abl|indef}}}
| data-accel-col="2" | {{{abl|s}}}
| data-accel-col="3" | {{{abl|p}}}
|-
! style="background: #eff7ff;" | partitive
| data-accel-col="1" | {{{par|indef}}}
| data-accel-col="2" | {{{par|s}}}
| data-accel-col="3" | {{{par|p}}}
|-
! style="background: #eff7ff;" | prolative
| data-accel-col="1" | {{{pro|indef}}}
| data-accel-col="2" | {{{pro|s}}}
| data-accel-col="3" | {{{pro|p}}}
|}</div></div>]=]
	elseif tbl_type == "both" then
		wikicode = [=[
<div class="NavFrame" style="display: inline-block;min-width: 50em">
<div class="NavHead" style="background:#eff7ff" >{{{info}}}</div>
<div class="NavContent">
{| style="background:#F9F9F9;text-align:center;min-width:50em" class="inflection-table"
|- 
! style="width:25%;background:#d9ebff" colspan="2"|
! style="background:#d9ebff" | indefinite
! style="background:#d9ebff" | singular
! style="background:#d9ebff" | plural
|-
! style="background: #eff7ff;" colspan="2"| absolutive
| data-accel-col="1" | {{{absv|indef}}}
| data-accel-col="2" | {{{absv|s}}}
| data-accel-col="3" | {{{absv|p}}}
|-
! style="background: #eff7ff;" colspan="2"| ergative
| data-accel-col="1" | {{{erg|indef}}}
| data-accel-col="2" | {{{erg|s}}}
| data-accel-col="3" | {{{erg|p}}}
|-
! style="background: #eff7ff;" colspan="2"| dative
| data-accel-col="1" | {{{dat|indef}}}
| data-accel-col="2" | {{{dat|s}}}
| data-accel-col="3" | {{{dat|p}}}
|-
! style="background: #eff7ff;" colspan="2"| genitive
| data-accel-col="1" | {{{gen|indef}}}
| data-accel-col="2" | {{{gen|s}}}
| data-accel-col="3" | {{{gen|p}}}
|-
! style="background: #eff7ff;" colspan="2"| comitative
| data-accel-col="1" | {{{com|indef}}}
| data-accel-col="2" | {{{com|s}}}
| data-accel-col="3" | {{{com|p}}}
|-
! style="background: #eff7ff;" colspan="2"| causative
| data-accel-col="1" | {{{caus|indef}}}
| data-accel-col="2" | {{{caus|s}}}
| data-accel-col="3" | {{{caus|p}}}
|-
! style="background: #eff7ff;" colspan="2"| benefactive
| data-accel-col="1" | {{{ben|indef}}}
| data-accel-col="2" | {{{ben|s}}}
| data-accel-col="3" | {{{ben|p}}}
|-
! style="background: #eff7ff;" colspan="2"| instrumental
| data-accel-col="1" | {{{ins|indef}}}
| data-accel-col="2" | {{{ins|s}}}
| data-accel-col="3" | {{{ins|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| inessive
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{ine|animate|indef}}}
| data-accel-col="2" | {{{ine|animate|s}}}
| data-accel-col="3" | {{{ine|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{ine|inanimate|indef}}}
| data-accel-col="2" | {{{ine|inanimate|s}}}
| data-accel-col="3" | {{{ine|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| locative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{loc|animate|indef}}}
| data-accel-col="2" | {{{loc|animate|s}}}
| data-accel-col="3" | {{{loc|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{loc|inanimate|indef}}}
| data-accel-col="2" | {{{loc|inanimate|s}}}
| data-accel-col="3" | {{{loc|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| allative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{all|animate|indef}}}
| data-accel-col="2" | {{{all|animate|s}}}
| data-accel-col="3" | {{{all|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{all|inanimate|indef}}}
| data-accel-col="2" | {{{all|inanimate|s}}}
| data-accel-col="3" | {{{all|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| terminative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{ter|animate|indef}}}
| data-accel-col="2" | {{{ter|animate|s}}}
| data-accel-col="3" | {{{ter|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{ter|inanimate|indef}}}
| data-accel-col="2" | {{{ter|inanimate|s}}}
| data-accel-col="3" | {{{ter|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| directive
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{directive|animate|indef}}}
| data-accel-col="2" | {{{directive|animate|s}}}
| data-accel-col="3" | {{{directive|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{directive|inanimate|indef}}}
| data-accel-col="2" | {{{directive|inanimate|s}}}
| data-accel-col="3" | {{{directive|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| destinative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{destinative|animate|indef}}}
| data-accel-col="2" | {{{destinative|animate|s}}}
| data-accel-col="3" | {{{destinative|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{destinative|inanimate|indef}}}
| data-accel-col="2" | {{{destinative|inanimate|s}}}
| data-accel-col="3" | {{{destinative|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| ablative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{abl|animate|indef}}}
| data-accel-col="2" | {{{abl|animate|s}}}
| data-accel-col="3" | {{{abl|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{abl|inanimate|indef}}}
| data-accel-col="2" | {{{abl|inanimate|s}}}
| data-accel-col="3" | {{{abl|inanimate|p}}}
|-
! style="background: #eff7ff;" colspan="2"| partitive
| data-accel-col="1" | {{{par|indef}}}
| data-accel-col="2" | {{{par|s}}}
| data-accel-col="3" | {{{par|p}}}
|-
! style="background: #eff7ff;" colspan="2"| prolative
| data-accel-col="1" | {{{pro|indef}}}
| data-accel-col="2" | {{{pro|s}}}
| data-accel-col="3" | {{{pro|p}}}
|}</div></div>]=]
	elseif tbl_type == "both-pl" then
		wikicode = [=[
<div class="NavFrame" style="display: inline-block;min-width: 42em">
<div class="NavHead" style="background:#eff7ff" >{{{info}}}</div>
<div class="NavContent">
{| style="background:#F9F9F9;text-align:center;min-width:42em" class="inflection-table"
|- 
! style="width:25%;background:#d9ebff" colspan="2"|
! style="background:#d9ebff" | indefinite
! style="background:#d9ebff" | plural
|-
! style="background: #eff7ff;" colspan="2"| absolutive
| data-accel-col="1" | {{{absv|indef}}}
| data-accel-col="3" | {{{absv|p}}}
|-
! style="background: #eff7ff;" colspan="2"| ergative
| data-accel-col="1" | {{{erg|indef}}}
| data-accel-col="3" | {{{erg|p}}}
|-
! style="background: #eff7ff;" colspan="2"| dative
| data-accel-col="1" | {{{dat|indef}}}
| data-accel-col="3" | {{{dat|p}}}
|-
! style="background: #eff7ff;" colspan="2"| genitive
| data-accel-col="1" | {{{gen|indef}}}
| data-accel-col="3" | {{{gen|p}}}
|-
! style="background: #eff7ff;" colspan="2"| comitative
| data-accel-col="1" | {{{com|indef}}}
| data-accel-col="3" | {{{com|p}}}
|-
! style="background: #eff7ff;" colspan="2"| causative
| data-accel-col="1" | {{{caus|indef}}}
| data-accel-col="3" | {{{caus|p}}}
|-
! style="background: #eff7ff;" colspan="2"| benefactive
| data-accel-col="1" | {{{ben|indef}}}
| data-accel-col="3" | {{{ben|p}}}
|-
! style="background: #eff7ff;" colspan="2"| instrumental
| data-accel-col="1" | {{{ins|indef}}}
| data-accel-col="3" | {{{ins|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| inessive
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{ine|animate|indef}}}
| data-accel-col="3" | {{{ine|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{ine|inanimate|indef}}}
| data-accel-col="3" | {{{ine|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| locative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{loc|animate|indef}}}
| data-accel-col="3" | {{{loc|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{loc|inanimate|indef}}}
| data-accel-col="3" | {{{loc|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| allative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{all|animate|indef}}}
| data-accel-col="3" | {{{all|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{all|inanimate|indef}}}
| data-accel-col="3" | {{{all|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| terminative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{ter|animate|indef}}}
| data-accel-col="3" | {{{ter|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{ter|inanimate|indef}}}
| data-accel-col="3" | {{{ter|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| directive
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{directive|animate|indef}}}
| data-accel-col="3" | {{{directive|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{directive|inanimate|indef}}}
| data-accel-col="3" | {{{directive|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| destinative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{destinative|animate|indef}}}
| data-accel-col="3" | {{{destinative|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{destinative|inanimate|indef}}}
| data-accel-col="3" | {{{destinative|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| ablative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{abl|animate|indef}}}
| data-accel-col="3" | {{{abl|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{abl|inanimate|indef}}}
| data-accel-col="3" | {{{abl|inanimate|p}}}
|-
! style="background: #eff7ff;" colspan="2"| partitive
| data-accel-col="1" | {{{par|indef}}}
| data-accel-col="3" | {{{par|p}}}
|-
! style="background: #eff7ff;" colspan="2"| prolative
| data-accel-col="1" | {{{pro|indef}}}
| data-accel-col="3" | {{{pro|p}}}
|}</div></div>]=]
	elseif tbl_type == "ind" then
		wikicode = [=[
<div class="NavFrame" style="width:35em">
<div class="NavHead" style="background:#eff7ff" >{{{info}}}</div>
<div class="NavContent">
{| style="background:#F9F9F9;text-align:center;width:35em" class="inflection-table"
|- 
! style="width:50%;background:#d9ebff" |
! style="background:#d9ebff" | indefinite
|-
! style="background: #eff7ff;" | absolutive
| data-accel-col="1" | {{{absv|indef}}}
|-
! style="background: #eff7ff;" | ergative
| data-accel-col="1" | {{{erg|indef}}}
|-
! style="background: #eff7ff;" | dative
| data-accel-col="1" | {{{dat|indef}}}
|-
! style="background: #eff7ff;" | genitive
| data-accel-col="1" | {{{gen|indef}}}
|-
! style="background: #eff7ff;" | comitative
| data-accel-col="1" | {{{com|indef}}}
|-
! style="background: #eff7ff;" | causative
| data-accel-col="1" | {{{caus|indef}}}
|-
! style="background: #eff7ff;" | benefactive
| data-accel-col="1" | {{{ben|indef}}}
|-
! style="background: #eff7ff;" | instrumental
| data-accel-col="1" | {{{ins|indef}}}
|-
! style="background: #eff7ff;" | inessive
| data-accel-col="1" | {{{ine|indef}}}
|-
! style="background: #eff7ff;" | locative
| data-accel-col="1" | {{{loc|indef}}}
|-
! style="background: #eff7ff;" | allative
| data-accel-col="1" | {{{all|indef}}}
|-
! style="background: #eff7ff;" | terminative
| data-accel-col="1" | {{{ter|indef}}}
|-
! style="background: #eff7ff;" | directive
| data-accel-col="1" | {{{directive|indef}}}
|-
! style="background: #eff7ff;" | destinative
| data-accel-col="1" | {{{destinative|indef}}}
|-
! style="background: #eff7ff;" | ablative
| data-accel-col="1" | {{{abl|indef}}}
|-
! style="background: #eff7ff;" | partitive
| data-accel-col="1" | {{{par|indef}}}
|-
! style="background: #eff7ff;" | prolative
| data-accel-col="1" | {{{pro|indef}}}
|}</div></div>]=]
	elseif tbl_type == "sing" then
		wikicode = [=[
<div class="NavFrame" style="display: inline-block;min-width: 42em">
<div class="NavHead" style="background:#eff7ff" >{{{info}}}</div>
<div class="NavContent">
{| style="background:#F9F9F9;text-align:center;min-width:42em" class="inflection-table"
|- 
! style="width:33%;background:#d9ebff" |
! style="background:#d9ebff" | indefinite
! style="background:#d9ebff" | singular
|-
! style="background: #eff7ff;" | absolutive
| data-accel-col="1" | {{{absv|indef}}}
| data-accel-col="2" | {{{absv|s}}}
|-
! style="background: #eff7ff;" | ergative
| data-accel-col="1" | {{{erg|indef}}}
| data-accel-col="2" | {{{erg|s}}}
|-
! style="background: #eff7ff;" | dative
| data-accel-col="1" | {{{dat|indef}}}
| data-accel-col="2" | {{{dat|s}}}
|-
! style="background: #eff7ff;" | genitive
| data-accel-col="1" | {{{gen|indef}}}
| data-accel-col="2" | {{{gen|s}}}
|-
! style="background: #eff7ff;" | comitative
| data-accel-col="1" | {{{com|indef}}}
| data-accel-col="2" | {{{com|s}}}
|-
! style="background: #eff7ff;" | causative
| data-accel-col="1" | {{{caus|indef}}}
| data-accel-col="2" | {{{caus|s}}}
|-
! style="background: #eff7ff;" | benefactive
| data-accel-col="1" | {{{ben|indef}}}
| data-accel-col="2" | {{{ben|s}}}
|-
! style="background: #eff7ff;" | instrumental
| data-accel-col="1" | {{{ins|indef}}}
| data-accel-col="2" | {{{ins|s}}}
|-
! style="background: #eff7ff;" | inessive
| data-accel-col="1" | {{{ine|indef}}}
| data-accel-col="2" | {{{ine|s}}}
|-
! style="background: #eff7ff;" | locative
| data-accel-col="1" | {{{loc|indef}}}
| data-accel-col="2" | {{{loc|s}}}
|-
! style="background: #eff7ff;" | allative
| data-accel-col="1" | {{{all|indef}}}
| data-accel-col="2" | {{{all|s}}}
|-
! style="background: #eff7ff;" | terminative
| data-accel-col="1" | {{{ter|indef}}}
| data-accel-col="2" | {{{ter|s}}}
|-
! style="background: #eff7ff;" | directive
| data-accel-col="1" | {{{directive|indef}}}
| data-accel-col="2" | {{{directive|s}}}
|-
! style="background: #eff7ff;" | destinative
| data-accel-col="1" | {{{destinative|indef}}}
| data-accel-col="2" | {{{destinative|s}}}
|-
! style="background: #eff7ff;" | ablative
| data-accel-col="1" | {{{abl|indef}}}
| data-accel-col="2" | {{{abl|s}}}
|-
! style="background: #eff7ff;" | partitive
| data-accel-col="1" | {{{par|indef}}}
| data-accel-col="2" | {{{par|s}}}
|-
! style="background: #eff7ff;" | prolative
| data-accel-col="1" | {{{pro|indef}}}
| data-accel-col="2" | {{{pro|s}}}
|}</div></div>]=]
	elseif tbl_type == "pl" then
		wikicode = [=[
<div class="NavFrame" style="display: inline-block;min-width: 42em">
<div class="NavHead" style="background:#eff7ff" >{{{info}}}</div>
<div class="NavContent">
{| style="background:#F9F9F9;text-align:center;min-width:42em" class="inflection-table"
|- 
! style="width:33%;background:#d9ebff" |
! style="background:#d9ebff" | indefinite
! style="background:#d9ebff" | plural
|-
! style="background: #eff7ff;" | absolutive
| data-accel-col="1" | {{{absv|indef}}}
| data-accel-col="2" | {{{absv|p}}}
|-
! style="background: #eff7ff;" | ergative
| data-accel-col="1" | {{{erg|indef}}}
| data-accel-col="2" | {{{erg|p}}}
|-
! style="background: #eff7ff;" | dative
| data-accel-col="1" | {{{dat|indef}}}
| data-accel-col="2" | {{{dat|p}}}
|-
! style="background: #eff7ff;" | genitive
| data-accel-col="1" | {{{gen|indef}}}
| data-accel-col="2" | {{{gen|p}}}
|-
! style="background: #eff7ff;" | comitative
| data-accel-col="1" | {{{com|indef}}}
| data-accel-col="2" | {{{com|p}}}
|-
! style="background: #eff7ff;" | causative
| data-accel-col="1" | {{{caus|indef}}}
| data-accel-col="2" | {{{caus|p}}}
|-
! style="background: #eff7ff;" | benefactive
| data-accel-col="1" | {{{ben|indef}}}
| data-accel-col="2" | {{{ben|p}}}
|-
! style="background: #eff7ff;" | instrumental
| data-accel-col="1" | {{{ins|indef}}}
| data-accel-col="2" | {{{ins|p}}}
|-
! style="background: #eff7ff;" | inessive
| data-accel-col="1" | {{{ine|indef}}}
| data-accel-col="2" | {{{ine|p}}}
|-
! style="background: #eff7ff;" | locative
| data-accel-col="1" | {{{loc|indef}}}
| data-accel-col="2" | {{{loc|p}}}
|-
! style="background: #eff7ff;" | allative
| data-accel-col="1" | {{{all|indef}}}
| data-accel-col="2" | {{{all|p}}}
|-
! style="background: #eff7ff;" | terminative
| data-accel-col="1" | {{{ter|indef}}}
| data-accel-col="2" | {{{ter|p}}}
|-
! style="background: #eff7ff;" | directive
| data-accel-col="1" | {{{directive|indef}}}
| data-accel-col="2" | {{{directive|p}}}
|-
! style="background: #eff7ff;" | destinative
| data-accel-col="1" | {{{destinative|indef}}}
| data-accel-col="2" | {{{destinative|p}}}
|-
! style="background: #eff7ff;" | ablative
| data-accel-col="1" | {{{abl|indef}}}
| data-accel-col="2" | {{{abl|p}}}
|-
! style="background: #eff7ff;" | partitive
| data-accel-col="1" | {{{par|indef}}}
| data-accel-col="2" | {{{par|p}}}
|-
! style="background: #eff7ff;" | prolative
| data-accel-col="1" | {{{pro|indef}}}
| data-accel-col="2" | {{{pro|p}}}
|}</div></div>]=]
	elseif tbl_type == "hiru-lau" then
		wikicode = [=[
<div class="NavFrame" style="display: inline-block;min-width: 50em">
<div class="NavHead" style="background:#eff7ff" >{{{info}}}</div>
<div class="NavContent">
{| style="background:#F9F9F9;text-align:center;min-width:50em" class="inflection-table"
|- 
! style="width:25%;background:#d9ebff" colspan="2"|
! style="background:#d9ebff" | indefinite
! style="background:#d9ebff" | singular
! style="background:#d9ebff" | plural
|-
! style="background: #eff7ff;" colspan="2"| absolutive
| data-accel-col="1" | {{{absv|indef}}}
| data-accel-col="2" | {{{absv|s}}}
| data-accel-col="3" | {{{absv|p}}}, {{{absvp|p}}}
|-
! style="background: #eff7ff;" colspan="2"| ergative
| data-accel-col="1" | {{{erg|indef}}}
| data-accel-col="2" | {{{erg|s}}}
| data-accel-col="3" | {{{erg|p}}}, {{{ergp|p}}}
|-
! style="background: #eff7ff;" colspan="2"| dative
| data-accel-col="1" | {{{dat|indef}}}
| data-accel-col="2" | {{{dat|s}}}
| data-accel-col="3" | {{{dat|p}}}, {{{datp|p}}}
|-
! style="background: #eff7ff;" colspan="2"| genitive
| data-accel-col="1" | {{{gen|indef}}}
| data-accel-col="2" | {{{gen|s}}}
| data-accel-col="3" | {{{gen|p}}}, {{{genp|p}}}
|-
! style="background: #eff7ff;" colspan="2"| comitative
| data-accel-col="1" | {{{com|indef}}}
| data-accel-col="2" | {{{com|s}}}
| data-accel-col="3" | {{{com|p}}}, {{{comp|p}}}
|-
! style="background: #eff7ff;" colspan="2"| causative
| data-accel-col="1" | {{{caus|indef}}}
| data-accel-col="2" | {{{caus|s}}}
| data-accel-col="3" | {{{caus|p}}}, {{{causp|p}}}
|-
! style="background: #eff7ff;" colspan="2"| benefactive
| data-accel-col="1" | {{{ben|indef}}}
| data-accel-col="2" | {{{ben|s}}}
| data-accel-col="3" | {{{ben|p}}}, {{{benp|p}}}
|-
! style="background: #eff7ff;" colspan="2"| instrumental
| data-accel-col="1" | {{{ins|indef}}}, {{{insp|indef}}}
| data-accel-col="2" | {{{ins|s}}}
| data-accel-col="3" | {{{ins|p}}}, {{{insp|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| inessive
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{ine|animate|indef}}}
| data-accel-col="2" | {{{ine|animate|s}}}
| data-accel-col="3" | {{{ine|animate|p}}}, {{{inep|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{ine|inanimate|indef}}}
| data-accel-col="2" | {{{ine|inanimate|s}}}
| data-accel-col="3" | {{{ine|inanimate|p}}}, {{{inep|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| locative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{loc|animate|indef}}}
| data-accel-col="2" | {{{loc|animate|s}}}
| data-accel-col="3" | {{{loc|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{loc|inanimate|indef}}}
| data-accel-col="2" | {{{loc|inanimate|s}}}
| data-accel-col="3" | {{{loc|inanimate|p}}}, {{{locp|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| allative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{all|animate|indef}}}
| data-accel-col="2" | {{{all|animate|s}}}
| data-accel-col="3" | {{{all|animate|p}}}, {{{allp|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{all|inanimate|indef}}}
| data-accel-col="2" | {{{all|inanimate|s}}}
| data-accel-col="3" | {{{all|inanimate|p}}}, {{{allp|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| terminative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{ter|animate|indef}}}
| data-accel-col="2" | {{{ter|animate|s}}}
| data-accel-col="3" | {{{ter|animate|p}}}, {{{terp|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{ter|inanimate|indef}}}
| data-accel-col="2" | {{{ter|inanimate|s}}}
| data-accel-col="3" | {{{ter|inanimate|p}}}, {{{terp|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| directive
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{directive|animate|indef}}}
| data-accel-col="2" | {{{directive|animate|s}}}
| data-accel-col="3" | {{{directive|animate|p}}}, {{{directivep|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{directive|inanimate|indef}}}
| data-accel-col="2" | {{{directive|inanimate|s}}}
| data-accel-col="3" | {{{directive|inanimate|p}}}, {{{directivep|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| destinative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{destinative|animate|indef}}}
| data-accel-col="2" | {{{destinative|animate|s}}}
| data-accel-col="3" | {{{destinative|animate|p}}}, {{{destinativep|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{destinative|inanimate|indef}}}
| data-accel-col="2" | {{{destinative|inanimate|s}}}
| data-accel-col="3" | {{{destinative|inanimate|p}}}, {{{destinativep|inanimate|p}}}
|-
! style="background: #eff7ff;" rowspan="2"| ablative
! style="background: #eff7ff;" | anim.
| data-accel-col="1" | {{{abl|animate|indef}}}
| data-accel-col="2" | {{{abl|animate|s}}}
| data-accel-col="3" | {{{abl|animate|p}}}, {{{ablp|animate|p}}}
|-
! style="background: #eff7ff;" | inanim.
| data-accel-col="1" | {{{abl|inanimate|indef}}}
| data-accel-col="2" | {{{abl|inanimate|s}}}
| data-accel-col="3" | {{{abl|inanimate|p}}}, {{{ablp|inanimate|p}}}
|-
! style="background: #eff7ff;" colspan="2"| partitive
| data-accel-col="1" | {{{par|indef}}}
| data-accel-col="2" | {{{par|s}}}
| data-accel-col="3" | {{{par|p}}}
|-
! style="background: #eff7ff;" colspan="2"| prolative
| data-accel-col="1" | {{{pro|indef}}}
| data-accel-col="2" | {{{pro|s}}}
| data-accel-col="3" | {{{pro|p}}}
|}</div></div>]=]
	end
	return mw.ustring.gsub(wikicode, "{{{[#!]?([a-z0-9|]+)}}}", repl) .. require("Module:utilities").format_categories(data.categories, lang)
end --normal table

-- Inflection functions (common nouns)
function export.anim(frame)
	local args = frame:getParent().args
		
	local data = {
		forms = {},
		info = "Declension of ",
		categories = {},
	}
	
	local ending_text = 0
	
	-- add the lemma form
	local base = mw.title.getCurrentTitle().text
	data.forms["absv|indef"] = {base}
	data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(animate, ending in "

	-- add the prolative
	data.forms["pro|indef"] = {base .. "tzat"}
	if	base:sub(-2,-1) == "tz" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "ztzat"}
	elseif base:sub(-2,-1) == "ts" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "stzat"}
	elseif base:sub(-2,-1) == "tx" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "xtzat"}
	elseif base:sub(-1) == "t" then
		data.forms["pro|indef"] = {base .. "-tzat"}
	end
	if args.hyph then 
		data.forms["pro|indef"] = {base .. "-tzat"}
	end
	
	-- epenthetic "e" and "r", ending in vowel/-a
	local e = "e"
	if base:sub(-1) == "a"  then 
		e = ""
		ending_text = 1
	elseif base:sub(-1) == "e" or base:sub(-1) == "i" or base:sub(-1) == "o" or base:sub(-1) == "u" or args.ending == "V" or args.ending == "orthV" then -- FIXME, this can be written in a cleaner way for sure
		e = ""
		ending_text = 2
		if args.ending == "orthV" then
			ending_text = 5
		end
	elseif args.ending == "orthC" then
		ending_text = 6
	end
	local r = "r"
	if e == "e" then
		r = ""
	end
	
	-- exception for monosyllabic nouns ending in a dipthong
	local e2 = ""
	if args.dip then
		e2 = "e"
	end
	
	--modifications if a hyphen is needed
	if args.hyph then
		base = base .. "-"
	end

	-- modifications if the word ends in -r
	if	base:sub(-1) == "r" then
		if args.tap then
			ending_text = 3
		else
			base = base .. 'r' --add an r if the word ends in r
			ending_text = 4
		end
	else
		
	end
	
	-- modifications if the word ends in -a
	local base_pl = base
	if base:sub(-1) == "a" then
		base_pl = base:sub(1,-2)
	end
	
	-- write "ending in ..."
	if ending_text == 0 then
		data.info = data.info .. "consonant)</small>"
	elseif ending_text == 1 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-a"}, "term") .. ")</small>"
	elseif ending_text == 2 then
		data.info = data.info .. "vowel" .. ")</small>"
	elseif ending_text == 3 then
		data.info = data.info .. "tap " .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	elseif ending_text == 4 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	elseif ending_text == 5 then
		data.info = data.info .. "orthographical vowel)</small>"
	elseif ending_text == 6 then
		data.info = data.info .. "orthographical consonant)</small>"

	end
	
	data.forms["absv|s"] = {base_pl .. "a"}
	data.forms["absv|p"] = {base_pl .. "ak"}

	data.forms["erg|indef"] = {base .. e .. "k"}
	data.forms["erg|s"] = {base_pl .. "ak"}
	data.forms["erg|p"] = {base_pl .. "ek"}
	
	data.forms["dat|indef"] = {base .. r .. "i"}
	data.forms["dat|s"] = {base_pl .. "ari"}
	data.forms["dat|p"] = {base_pl .. "ei"}
	
	data.forms["gen|indef"] = {base .. r .. "en"}
	data.forms["gen|s"] = {base_pl .. "aren"}
	data.forms["gen|p"] = {base_pl .. "en"}
	
	data.forms["com|indef"] = {base .. r .. "ekin"}
	data.forms["com|s"] = {base_pl .. "arekin"}
	data.forms["com|p"] = {base_pl .. "ekin"}
	
	data.forms["caus|indef"] = {base .. r .. "engatik"}
	data.forms["caus|s"] = {base_pl .. "arengatik"}
	data.forms["caus|p"] = {base_pl .. "engatik"}
	
	data.forms["ben|indef"] = {base .. r .. "entzat"}
	data.forms["ben|s"] = {base_pl .. "arentzat"}
	data.forms["ben|p"] = {base_pl .. "entzat"}
	
	data.forms["ins|indef"] = {base .. e .. e2 .. "z"}
	data.forms["ins|s"] = {base_pl .. "az"}
	data.forms["ins|p"] = {base_pl .. "ez"}
	
	data.forms["ine|indef"] = {base .. r .. "engan"}
	data.forms["ine|s"] = {base_pl .. "arengan"}
	data.forms["ine|p"] = {base_pl .. "engan"}
	
	data.forms["all|indef"] = {base .. r .. "engana"}
	data.forms["all|s"] = {base_pl .. "arengana"}
	data.forms["all|p"] = {base_pl .. "engana"}
	
	data.forms["ter|indef"] = {base .. r .. "enganaino"}
	data.forms["ter|s"] = {base_pl .. "arenganaino"}
	data.forms["ter|p"] = {base_pl .. "enganaino"}
	
	data.forms["directive|indef"] = {base .. r .. "enganantz"}
	data.forms["directive|s"] = {base_pl .. "arenganantz"}
	data.forms["directive|p"] = {base_pl .. "enganantz"}
	
	data.forms["destinative|indef"] = {base .. r .. "enganako"}
	data.forms["destinative|s"] = {base_pl .. "arenganako"}
	data.forms["destinative|p"] = {base_pl .. "enganako"}
	
	data.forms["abl|indef"] = {base .. r .. "engandik"}
	data.forms["abl|s"] = {base_pl .. "arengandik"}
	data.forms["abl|p"] = {base_pl .. "engandik"}
	
	data.forms["par|indef"] = {base .. r .. "ik"}

	postprocess(args, data)
	
	return make_table(data, "st")
end

function export.inanim(frame)
	local args = frame:getParent().args
		
	local data = {
		forms = {},
		info = "Declension of ",
		categories = {},
	}
	
	local ending_text = 0
	
	-- add the lemma form
	local base = mw.title.getCurrentTitle().text
	data.forms["absv|indef"] = {base}
	if args.s then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(inanimate, singular only, ending in "
	elseif args.p then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(inanimate, plural only, ending in "
	else
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(inanimate, ending in "
	end
	-- add the prolative
	data.forms["pro|indef"] = {base .. "tzat"}
	if	base:sub(-2,-1) == "tz" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "ztzat"}
	elseif base:sub(-2,-1) == "ts" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "stzat"}
	elseif base:sub(-2,-1) == "tx" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "xtzat"}
	elseif base:sub(-1) == "t" then
		data.forms["pro|indef"] = {base .. "-tzat"}
	end
	if args.hyph then 
		data.forms["pro|indef"] = {base .. "-tzat"}
	end
	
	-- epenthetic "e" and "r", ending in vowel/-a. The vocalic ending can be forced in acronyms
	local e = "e"
	if base:sub(-1) == "a"  then 
		e = ""
		ending_text = 1
	elseif base:sub(-1) == "e" or base:sub(-1) == "i" or base:sub(-1) == "o" or base:sub(-1) == "u" or args.ending == "V" or args.ending == "orthV" then -- FIXME, this can be written in a cleaner way for sure
		e = ""
		ending_text = 2
		if args.ending == "orthV" then
			ending_text = 5
		end
	elseif args.ending == "orthC" then
		ending_text = 6
	end
	local r = "r"
	if e == "e" then
		r = ""
	end
	
	-- exception for monosyllabic nouns ending in a dipthong and the word "gau"
	local e2 = ""
	if args.dip then
		e2 = "e"
	end
	local e3 = ""
	if args.gau then
		e3 = "e"
	end
	
	--modifications if a hyphen is needed
	if args.hyph then
		base = base .. "-"
	end
	
	-- modifications if the word ends in -r
	if	base:sub(-1) == "r" then
		if args.tap then
			ending_text = 3
		else
			base = base .. 'r' --add an r if the word ends in r
			ending_text = 4
		end
	else
		
	end
	
	-- modifications if the word ends in -a
	local base_pl = base
	if base:sub(-1) == "a" then
		base_pl = base:sub(1,-2)
	end
	
	-- write "ending in ..."
	if ending_text == 0 then
		data.info = data.info .. "consonant)</small>"
	elseif ending_text == 1 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-a"}, "term") .. ")</small>"
	elseif ending_text == 2 then
		data.info = data.info .. "vowel" .. ")</small>"
	elseif ending_text == 3 then
		data.info = data.info .. "tap " .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	elseif ending_text == 4 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	elseif ending_text == 5 then
		data.info = data.info .. "orthographical vowel)</small>"
	elseif ending_text == 6 then
		data.info = data.info .. "orthographical consonant)</small>"
	end
	
	if not args.s then -- ignore these forms in singular-only nouns
		data.forms["absv|p"] = {base_pl .. "ak"}
		
		data.forms["erg|indef"] = {base .. e .. "k"}
		data.forms["erg|p"] = {base_pl .. "ek"}
	
		data.forms["dat|indef"] = {base .. r .. "i"}
		data.forms["dat|p"] = {base_pl .. "ei"}
	
		data.forms["gen|indef"] = {base .. r .. "en"}
		data.forms["gen|p"] = {base_pl .. "en"}
	
		data.forms["com|indef"] = {base .. r .. "ekin"}
		data.forms["com|p"] = {base_pl .. "ekin"}
	
		data.forms["caus|indef"] = {base .. r .. "engatik"}
		data.forms["caus|p"] = {base_pl .. "engatik"}
	
		data.forms["ben|indef"] = {base .. r .. "entzat"}
		data.forms["ben|p"] = {base_pl .. "entzat"}
	
		data.forms["ins|p"] = {base_pl .. "ez"}
	
		data.forms["ine|indef"] = {base .. e  .. "tan"}
		data.forms["ine|p"] = {base_pl .. "etan"}
	
		data.forms["loc|indef"] = {base .. e .. "tako"}
		data.forms["loc|s"] = {base .. e .. e3 .. "ko"}
		data.forms["loc|p"] = {base_pl .. "etako"}
	
		data.forms["all|indef"] = {base .. e .. "tara"}
		data.forms["all|s"] = {base .. e .. e3 .. "ra"}
		data.forms["all|p"] = {base_pl .. "etara"}
	
		data.forms["ter|indef"] = {base .. e .. "taraino"}
		data.forms["ter|s"] = {base .. e .. e3 .. "raino"}
		data.forms["ter|p"] = {base_pl .. "etaraino"}
	
		data.forms["directive|indef"] = {base .. e .. "tarantz"}
		data.forms["directive|s"] = {base .. e .. e3 .. "rantz"}
		data.forms["directive|p"] = {base_pl .. "etarantz"}
	
		data.forms["destinative|indef"] = {base .. e .. "tarako"}
		data.forms["destinative|s"] = {base .. e .. e3 .. "rako"}
		data.forms["destinative|p"] = {base_pl .. "etarako"}
	
		data.forms["abl|indef"] = {base .. e .. "tatik"}
		data.forms["abl|s"] = {base .. e .. e3 .. "tik"}
		data.forms["abl|p"] = {base_pl .. "etatik"}
	end
	
	data.forms["absv|s"] = {base_pl .. "a"}
	data.forms["erg|s"] = {base_pl .. "ak"}
	data.forms["dat|s"] = {base_pl .. "ari"}
	data.forms["gen|s"] = {base_pl .. "aren"}
	data.forms["com|s"] = {base_pl .. "arekin"}
	data.forms["caus|s"] = {base_pl .. "arengatik"}
	data.forms["ben|s"] = {base_pl .. "arentzat"}
	data.forms["ins|indef"] = {base .. e .. e2 .. e3 .. "z"}
	data.forms["ins|s"] = {base_pl .. "az"}
	data.forms["ine|s"] = {base_pl .. e .. e3 .. "an"}
	data.forms["par|indef"] = {base .. r .. "ik"}

	postprocess(args, data)
	
	if args.s then
		return make_table(data, "sing")
	elseif args.p then
		table.insert(data.categories, "Basque pluralia tantum")
		return make_table(data, "pl")
	else
		return make_table(data, "st")
	end
end

function export.both(frame)
	local args = frame:getParent().args
		
	local data = {
		forms = {},
		info = "Declension of ",
		categories = {},
	}
	
	local ending_text = 0
	
	-- add the lemma form
	local base = mw.title.getCurrentTitle().text
	data.forms["absv|indef"] = {base}
	if frame.args["adj"] then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(adjective, ending in "
	elseif frame.args["num"] then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(numeral, ending in "
	else
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(animate and inanimate, ending in "
	end
	-- add the prolative
	data.forms["pro|indef"] = {base .. "tzat"}
	if	base:sub(-2,-1) == "tz" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "ztzat"}
	elseif base:sub(-2,-1) == "ts" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "stzat"}
	elseif base:sub(-2,-1) == "tx" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "xtzat"}
	elseif base:sub(-1) == "t" then
		data.forms["pro|indef"] = {base .. "-tzat"}
	end
	
	-- epenthetic "e" and "r", ending in vowel/-a
	local e = "e"
	if base:sub(-1) == "a"  then 
		e = ""
		ending_text = 1
	elseif base:sub(-1) == "e" or base:sub(-1) == "i" or base:sub(-1) == "o" or base:sub(-1) == "u" then -- FIXME, this can be written in a cleaner way for sure
		e = ""
		ending_text = 2
	end
	local r = "r"
	if e == "e" then
		r = ""
	end
	
	-- exception for monosyllabic nouns ending in a dipthong and the word "gau"
	local e2 = ""
	if args.dip then
		e2 = "e"
	end
	local e3 = ""
	if args.gau then
		e3 = "e"
	end
	
	-- modifications if the word ends in -r
	if	base:sub(-1) == "r" then
		if args.tap then
			ending_text = 3
		else
			base = base .. 'r' --add an r if the word ends in r
			ending_text = 4
		end
	else
		
	end
	
	-- modifications if the word ends in -a
	local base_pl = base
	local base_plp = base .. "r"
	if base:sub(-1) == "a" then
		base_pl = base:sub(1,-2)
	end
	
	-- write "ending in ..."
	if ending_text == 0 then
		data.info = data.info .. "consonant)</small>"
	elseif ending_text == 1 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-a"}, "term") .. ")</small>"
	elseif ending_text == 2 then
		data.info = data.info .. "vowel" .. ")</small>"
	elseif ending_text == 3 then
		data.info = data.info .. "tap " .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	elseif ending_text == 4 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	end
	
	data.forms["absv|s"] = {base_pl .. "a"}
	data.forms["absv|p"] = {base_pl .. "ak"}
	data.forms["absvp|p"] = {base_plp .. "ak"}
		
	data.forms["erg|indef"] = {base .. e .. "k"}
	data.forms["erg|s"] = {base_pl .. "ak"}
	data.forms["erg|p"] = {base_pl .. "ek"}
	data.forms["ergp|p"] = {base_plp .. "ek"}
	
	data.forms["dat|indef"] = {base .. r .. "i"}
	data.forms["dat|s"] = {base_pl .. "ari"}
	data.forms["dat|p"] = {base_pl .. "ei"}
	data.forms["datp|p"] = {base_plp .. "ei"}
	
	data.forms["gen|indef"] = {base .. r .. "en"}
	data.forms["gen|s"] = {base_pl .. "aren"}
	data.forms["gen|p"] = {base_pl .. "en"}
	data.forms["genp|p"] = {base_plp .. "en"}
	
	data.forms["com|indef"] = {base .. r .. "ekin"}
	data.forms["com|s"] = {base_pl .. "arekin"}
	data.forms["com|p"] = {base_pl .. "ekin"}
	data.forms["comp|p"] = {base_plp .. "ekin"}
	
	data.forms["caus|indef"] = {base .. r .. "engatik"}
	data.forms["caus|s"] = {base_pl .. "arengatik"}
	data.forms["caus|p"] = {base_pl .. "engatik"}
	data.forms["causp|p"] = {base_plp .. "engatik"}
	
	data.forms["ben|indef"] = {base .. r .. "entzat"}
	data.forms["ben|s"] = {base_pl .. "arentzat"}
	data.forms["ben|p"] = {base_pl .. "entzat"}
	data.forms["benp|p"] = {base_plp .. "entzat"}
	
	data.forms["ins|indef"] = {base .. e .. e2 .. e3 .. "z"}
	data.forms["ins|s"] = {base_pl .. "az"}
	data.forms["ins|p"] = {base_pl .. "ez"}
	data.forms["insp|p"] = {base_plp .. "ez"}
	if base == "hiru" then
		data.forms["insp|indef"] = {"hirurez"}
	elseif base == "lau" then
		data.forms["insp|indef"] = {"laurez"}
	end
	
	data.forms["ine|inanimate|indef"] = {base .. e  .. "tan"}
	data.forms["ine|inanimate|s"] = {base_pl .. e .. e3 .. "an"}
	data.forms["ine|inanimate|p"] = {base_pl .. "etan"}
	data.forms["inep|inanimate|p"] = {base_plp .. "etan"}
	data.forms["ine|animate|indef"] = {base .. r .. "engan"}
	data.forms["ine|animate|s"] = {base_pl .. "arengan"}
	data.forms["ine|animate|p"] = {base_pl .. "engan"}
	data.forms["inep|animate|p"] = {base_plp .. "engan"}

	data.forms["loc|inanimate|indef"] = {base .. e .. "tako"}
	data.forms["loc|inanimate|s"] = {base .. e .. e3 .. "ko"}
	data.forms["loc|inanimate|p"] = {base_pl .. "etako"}
	data.forms["locp|inanimate|p"] = {base_plp .. "etako"}
	
	data.forms["all|inanimate|indef"] = {base .. e .. "tara"}
	data.forms["all|inanimate|s"] = {base .. e .. e3 .. "ra"}
	data.forms["all|inanimate|p"] = {base_pl .. "etara"}
	data.forms["allp|inanimate|p"] = {base_plp .. "etara"}
	data.forms["all|animate|indef"] = {base .. r .. "engana"}
	data.forms["all|animate|s"] = {base_pl .. "arengana"}
	data.forms["all|animate|p"] = {base_pl .. "engana"}
	data.forms["allp|animate|p"] = {base_plp .. "engana"}

	data.forms["ter|inanimate|indef"] = {base .. e .. "taraino"}
	data.forms["ter|inanimate|s"] = {base .. e .. e3 .. "raino"}
	data.forms["ter|inanimate|p"] = {base_pl .. "etaraino"}
	data.forms["terp|inanimate|p"] = {base_plp .. "etaraino"}
	data.forms["ter|animate|indef"] = {base .. r .. "enganaino"}
	data.forms["ter|animate|s"] = {base_pl .. "arenganaino"}
	data.forms["ter|animate|p"] = {base_pl .. "enganaino"}
	data.forms["terp|animate|p"] = {base_plp .. "enganaino"}

	data.forms["directive|inanimate|indef"] = {base .. e .. "tarantz"}
	data.forms["directive|inanimate|s"] = {base .. e .. e3 .. "rantz"}
	data.forms["directive|inanimate|p"] = {base_pl .. "etarantz"}
	data.forms["directivep|inanimate|p"] = {base_plp .. "etarantz"}
	data.forms["directive|animate|indef"] = {base .. r .. "enganantz"}
	data.forms["directive|animate|s"] = {base_pl .. "arenganantz"}
	data.forms["directive|animate|p"] = {base_pl .. "enganantz"}
	data.forms["directivep|animate|p"] = {base_plp .. "enganantz"}

	data.forms["destinative|inanimate|indef"] = {base .. e .. "tarako"}
	data.forms["destinative|inanimate|s"] = {base .. e .. e3 .. "rako"}
	data.forms["destinative|inanimate|p"] = {base_pl .. "etarako"}
	data.forms["destinativep|inanimate|p"] = {base_plp .. "etarako"}
	data.forms["destinative|animate|indef"] = {base .. r .. "enganako"}
	data.forms["destinative|animate|s"] = {base_pl .. "arenganako"}
	data.forms["destinative|animate|p"] = {base_pl .. "enganako"}
	data.forms["destinativep|animate|p"] = {base_plp .. "enganako"}

	data.forms["abl|inanimate|indef"] = {base .. e .. "tatik"}
	data.forms["abl|inanimate|s"] = {base .. e .. e3 .. "tik"}
	data.forms["abl|inanimate|p"] = {base_pl .. "etatik"}
	data.forms["ablp|inanimate|p"] = {base_plp .. "etatik"}
	data.forms["abl|animate|indef"] = {base .. r .. "engandik"}
	data.forms["abl|animate|s"] = {base_pl .. "arengandik"}
	data.forms["abl|animate|p"] = {base_pl .. "engandik"}
	data.forms["ablp|animate|p"] = {base_plp .. "engandik"}

	data.forms["par|indef"] = {base .. r .. "ik"}

	postprocess(args, data)
	
	if frame.args.num and (base == "hiru" or base == "lau") then
		return make_table(data, "hiru-lau")
	elseif args.p and frame.args.num then
		return make_table(data, "both-pl")
	else
		return make_table(data, "both")
	end
end

-- Inflection functions (proper nouns)
function export.proper_anim(frame)
	local args = frame:getParent().args
		
	local data = {
		forms = {},
		info = "Declension of ",
		categories = {},
	}
	
	local ending_text = 0
	
	-- add the lemma form
	local base = mw.title.getCurrentTitle().text
	if args.s then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(animate with article, ending in "
		base = args[1]
	else
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(animate, ending in "
	end
	data.forms["absv|indef"] = {base}

	-- add the prolative
	data.forms["pro|indef"] = {base .. "tzat"}
	if	base:sub(-2,-1) == "tz" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "ztzat"}
	elseif base:sub(-2,-1) == "ts" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "stzat"}
	elseif base:sub(-2,-1) == "tx" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "xtzat"}
	elseif base:sub(-1) == "t" then
		data.forms["pro|indef"] = {base .. "-tzat"}
	end
	
	-- epenthetic "e" and "r", ending in vowel/-a
	local e = "e"
	if base:sub(-1) == "a"  then 
		e = ""
		ending_text = 1
	elseif base:sub(-1) == "e" or base:sub(-1) == "i" or base:sub(-1) == "o" or base:sub(-1) == "u" then -- FIXME, this can be written in a cleaner way for sure
		e = ""
		ending_text = 2
	end
	local r = "r"
	if e == "e" then
		r = ""
	end
	
	-- modifications if the word ends in -r
	if	base:sub(-1) == "r" then
		base = base .. "r"
		ending_text = 4
	else
		
	end
	
	-- write "ending in ..."
	if ending_text == 0 then
		data.info = data.info .. "consonant)</small>"
	elseif ending_text == 1 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-a"}, "term") .. ")</small>"
	elseif ending_text == 2 then
		data.info = data.info .. "vowel" .. ")</small>"
	elseif ending_text == 3 then
		data.info = data.info .. "tap " .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	elseif ending_text == 4 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	end

	if args.s then
		data.forms["absv|s"] = {base .. "a"}
		data.forms["erg|s"]  = {base .. "ak"}
		data.forms["dat|s"]  = {base .. "ari"}
		data.forms["gen|s"]  = {base .. "aren"}
		data.forms["com|s"]  = {base .. "arekin"}
		data.forms["caus|s"] = {base .. "arengatik"}
		data.forms["ben|s"]  = {base .. "arentzat"}
		data.forms["ins|s"]  = {base .. "az"}
		data.forms["ine|s"]  = {base .. "arengan"}
		data.forms["all|s"]  = {base .. "arengana"}
		data.forms["ter|s"]  = {base .. "arenganaino"}
		data.forms["directive|s"] = {base .. "arenganantz"}
		data.forms["destinative|s"] = {base .. "arenganako"}
		data.forms["abl|s"]  = {base .. "arengandik"}
	else
		data.forms["erg|indef"]  = {base .. e .. "k"}
		data.forms["dat|indef"]  = {base .. r .. "i"}
		data.forms["gen|indef"]  = {base .. r .. "en"}
		data.forms["com|indef"]  = {base .. r .. "ekin"}
		data.forms["caus|indef"] = {base .. r .. "engatik"}
		data.forms["ben|indef"]  = {base .. r .. "entzat"}
		data.forms["ins|indef"]  = {base .. e .. "z"}
		data.forms["ine|indef"]  = {base .. r .. "engan"}
		data.forms["all|indef"]  = {base .. r .. "engana"}
		data.forms["ter|indef"]  = {base .. r .. "enganaino"}
		data.forms["directive|indef"] = {base .. r .. "enganantz"}
		data.forms["destinative|indef"] = {base .. r .. "enganako"}
		data.forms["abl|indef"]  = {base .. r .. "engandik"}
	end
	
	data.forms["par|indef"] = {base .. r .. "ik"}

	if args.s then
		return make_table(data, "sing")
	else
		return make_table(data, "ind")
	end
end

function export.proper_inanim(frame)
	local args = frame:getParent().args
		
	local data = {
		forms = {},
		info = "Declension of ",
		categories = {},
	}
	
	local ending_text = 0
	
	-- add the lemma form
	local base = mw.title.getCurrentTitle().text
	if args.s then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(inanimate with article, ending in "
		base = args[1]
	elseif args.p then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(inanimate, plural only, ending in "
		base = args[1]		
	else
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(inanimate, ending in "
	end
	data.forms["absv|indef"] = {base}

	-- add the prolative
	data.forms["pro|indef"] = {base .. "tzat"}
	if	base:sub(-2,-1) == "tz" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "ztzat"}
	elseif base:sub(-2,-1) == "ts" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "stzat"}
	elseif base:sub(-2,-1) == "tx" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "xtzat"}
	elseif base:sub(-1) == "t" then
		data.forms["pro|indef"] = {base .. "-tzat"}
	end
	if args.hyph and args.ending == "V" then 
		data.forms["pro|indef"] = {base .. "-tzat"}
	end
	
	-- epenthetic "e" and "r", ending in vowel/-a. The vocalic ending can be forced in acronyms
	local e = "e"
	if base:sub(-1) == "a" or args.ending == "A"  then 
		e = ""
		ending_text = 1
	elseif base:sub(-1) == "e" or base:sub(-1) == "i" or base:sub(-1) == "o" or base:sub(-1) == "u" or args.ending == "V" then -- FIXME, this can be written in a cleaner way for sure
		e = ""
		ending_text = 2
	end
	local r = "r"
	if e == "e" then
		r = ""
	end
	
	--modifications if a hyphen is needed
	if args.hyph then
		base = base .. "-"
	end
	
	-- modifications if the word ends in -r
	if	base:sub(-1) == "r" then
		if args.tap then
			ending_text = 3
		else
			base = base .. 'r' --add an r if the word ends in r
			ending_text = 4
		end
	else
		
	end
	
	-- modifications if the word ends in -a
	local base_pl = base
	if base:sub(-1) == "a" then
		base_pl = base:sub(1,-2)
	end
	
	-- write "ending in ..."
	if ending_text == 0 then
		data.info = data.info .. "consonant)</small>"
	elseif ending_text == 1 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-a"}, "term") .. ")</small>"
	elseif ending_text == 2 then
		data.info = data.info .. "vowel" .. ")</small>"
	elseif ending_text == 3 then
		data.info = data.info .. "tap " .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	elseif ending_text == 4 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	end
	
	data.forms["par|indef"] = {base .. r .. "ik"}

	if args.p then
		data.forms["absv|p"] = {base_pl .. "ak"}
		data.forms["erg|p"]  = {base_pl .. "ek"}
		data.forms["dat|p"]  = {base_pl .. "ei"}
		data.forms["gen|p"]  = {base_pl .. "en"}
		data.forms["com|p"]  = {base_pl .. "ekin"}
		data.forms["caus|p"] = {base_pl .. "engatik"}
		data.forms["ben|p"]  = {base_pl .. "entzat"}
		data.forms["ine|p"]  = {base_pl .. "etan"}
		data.forms["ins|p"]  = {base_pl .. "ez"}
		data.forms["loc|p"]  = {base_pl .. "etako"}
		data.forms["all|p"]  = {base_pl .. "etara"}
		data.forms["ter|p"]  = {base_pl .. "etaraino"}
		data.forms["directive|p"] = {base_pl .. "etarantz"}
		data.forms["destinative|p"] = {base_pl .. "etarako"}
		data.forms["abl|p"]  = {base_pl .. "etatik"}
	elseif args.s then
		data.forms["absv|s"] = {base_pl .. "a"}
		data.forms["erg|s"]  = {base_pl .. "ak"}
		data.forms["dat|s"]  = {base_pl .. "ari"}
		data.forms["gen|s"]  = {base_pl .. "aren"}
		data.forms["com|s"]  = {base_pl .. "arekin"}
		data.forms["caus|s"] = {base_pl .. "arengatik"}
		data.forms["ben|s"]  = {base_pl .. "arentzat"}
		data.forms["ins|s"]  = {base_pl .. "az"}
		data.forms["ine|s"]  = {base_pl .. e .. "an"}
		data.forms["loc|s"]  = {base .. e .. "ko"}
		data.forms["all|s"]  = {base .. e .. "ra"}
		data.forms["ter|s"]  = {base .. e .. "raino"}
		data.forms["directive|s"] = {base .. e .. "rantz"}
		data.forms["destinative|s"] = {base .. e .. "rako"}
		data.forms["abl|s"]  = {base .. e .. "tik"}
	else
		data.forms["erg|indef"] = {base .. e .. "k"}
		data.forms["dat|indef"] = {base .. r .. "i"}
		data.forms["gen|indef"] = {base .. r .. "en"}
		data.forms["com|indef"] = {base .. r .. "ekin"}
		data.forms["caus|indef"] = {base .. r .. "engatik"}
		data.forms["ben|indef"] = {base .. r .. "entzat"}
		data.forms["ins|indef"] = {base .. e .. "z"}
		data.forms["ine|indef"] = {base .. e  .. "n"}
		data.forms["loc|indef"] = {base .. e .. "ko"}
		data.forms["all|indef"] = {base .. e .. "ra"}
		data.forms["ter|indef"] = {base .. e .. "raino"}
		data.forms["directive|indef"] = {base .. e .. "rantz"}
		data.forms["destinative|indef"] = {base .. e .. "rako"}
		data.forms["abl|indef"] = {base .. e .. "tik"}
		if	base:sub(-2,-1) == "tz" then
			data.forms["loc|indef"] = {base:sub(1,-3) .. "zko"}
			data.forms["abl|indef"] = {base:sub(1,-3) .. "ztik"}
		elseif base:sub(-1,-1) == "z" or base:sub(-1,-1) == "s" then
			data.forms["loc|indef"] = {base .. "ko"}
			data.forms["abl|indef"] = {base .. "tik"}	
		elseif base:sub(-1,-1) == "r" then
			data.forms["loc|indef"] = {base:sub(1,-2) .. "ko"}
			data.forms["abl|indef"] = {base:sub(1,-2) .. "tik"}
		elseif base:sub(-1,-1) == "n" or base:sub(-1,-1) == "l" then
			data.forms["loc|indef"] = {base .. "go"}
			data.forms["abl|indef"] = {base .. "dik"}	
		end
	end
	
	if args.s then
		return make_table(data, "sing")
	elseif args.p then
		return make_table(data, "pl")
	else
		return make_table(data, "ind")
	end
end

function export.proper_both(frame)
	local args = frame:getParent().args
		
	local data = {
		forms = {},
		info = "Declension of ",
		categories = {},
	}
	
	local ending_text = 0
	
	-- add the lemma form
	local base = mw.title.getCurrentTitle().text
	if args.s then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(animate and inanimate, singular only, ending in "
		base = args[1]
	elseif args.p then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(animate and inanimate, plural only, ending in "
		base = args[1]		
	else
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = base}, "term") .. " <small>(animate and inanimate, ending in "
	end
	data.forms["absv|indef"] = {base}

	-- add the prolative
	data.forms["pro|indef"] = {base .. "tzat"}
	if	base:sub(-2,-1) == "tz" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "ztzat"}
	elseif base:sub(-2,-1) == "ts" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "stzat"}
	elseif base:sub(-2,-1) == "tx" then
		data.forms["pro|indef"] = {base:sub(1,-3) .. "xtzat"}
	elseif base:sub(-1) == "t" then
		data.forms["pro|indef"] = {base .. "-tzat"}
	end
	if args.hyph and args.ending == "V" then 
		data.forms["pro|indef"] = {base .. "-tzat"}
	end
	
	-- epenthetic "e" and "r", ending in vowel/-a. The vocalic ending can be forced in acronyms
	local e = "e"
	if base:sub(-1) == "a"  then 
		e = ""
		ending_text = 1
	elseif base:sub(-1) == "e" or base:sub(-1) == "i" or base:sub(-1) == "o" or base:sub(-1) == "u" or args.ending == "V" then -- FIXME, this can be written in a cleaner way for sure
		e = ""
		ending_text = 2
	end
	local r = "r"
	if e == "e" then
		r = ""
	end
	
	--modifications if a hyphen is needed
	if args.hyph then
		base = base .. "-"
	end
	
	-- modifications if the word ends in -r
	if	base:sub(-1) == "r" then
		if args.tap then
			ending_text = 3
		else
			base = base .. 'r' --add an r if the word ends in r
			ending_text = 4
		end
	end
	
	-- write "ending in ..."
	if ending_text == 0 then
		data.info = data.info .. "consonant)</small>"
	elseif ending_text == 1 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-a"}, "term") .. ")</small>"
	elseif ending_text == 2 then
		data.info = data.info .. "vowel" .. ")</small>"
	elseif ending_text == 3 then
		data.info = data.info .. "tap " .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	elseif ending_text == 4 then
		data.info = data.info .. require("Module:links").full_link({lang = lang, alt = "-r"}, "term") .. ")</small>"
	end
	
	data.forms["par|indef"] = {base .. r .. "ik"}

	data.forms["erg|indef"] = {base .. e .. "k"}
	data.forms["dat|indef"] = {base .. r .. "i"}
	data.forms["gen|indef"] = {base .. r .. "en"}
	data.forms["com|indef"] = {base .. r .. "ekin"}
	data.forms["caus|indef"] = {base .. r .. "engatik"}
	data.forms["ben|indef"] = {base .. r .. "entzat"}
	data.forms["ins|indef"] = {base .. e .. "z"}
	
	data.forms["ine|inanimate|indef"] = {base .. e  .. "n"}
	data.forms["loc|inanimate|indef"] = {base .. e .. "ko"}
	data.forms["all|inanimate|indef"] = {base .. e .. "ra"}
	data.forms["ter|inanimate|indef"] = {base .. e .. "raino"}
	data.forms["directive|inanimate|indef"] = {base .. e .. "rantz"}
	data.forms["destinative|inanimate|indef"] = {base .. e .. "rako"}
	data.forms["abl|inanimate|indef"] = {base .. e .. "tik"}
	
	data.forms["ine|animate|indef"] = {base .. r .. "engan"}
	data.forms["all|animate|indef"] = {base .. r .. "engana"}
	data.forms["ter|animate|indef"] = {base .. r .. "enganaino"}
	data.forms["directive|animate|indef"] = {base .. r .. "enganantz"}
	data.forms["destinative|animate|indef"] = {base .. r .. "enganako"}
	data.forms["abl|animate|indef"] = {base .. r .. "engandik"}
	
	if	base:sub(-2,-1) == "tz" then
		data.forms["loc|inanimate|indef"] = {base:sub(1,-3) .. "zko"}
		data.forms["abl|inanimate|indef"] = {base:sub(1,-3) .. "ztik"}
	elseif base:sub(-1,-1) == "z" or base:sub(-1,-1) == "s" then
		data.forms["loc|inanimate|indef"] = {base .. "ko"}
		data.forms["abl|inanimate|indef"] = {base .. "tik"}	
	elseif base:sub(-1,-1) == "r" then
		data.forms["loc|inanimate|indef"] = {base:sub(1,-2) .. "ko"}
		data.forms["abl|inanimate|indef"] = {base:sub(1,-2) .. "tik"}
	elseif base:sub(-1,-1) == "n" or base:sub(-1,-1) == "l" then
		data.forms["loc|inanimate|indef"] = {base .. "go"}
		data.forms["abl|inanimate|indef"] = {base .. "dik"}
	end
	
	return make_table(data, "both")
end

return export