Module:da-adjectives

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local m_utilities = require("Module:utilities")
local m_links = require("Module:links")

local export = {}

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


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


--[=[
	Inflection functions
]=]--

function export.reg(frame)
	local params = {
		[1] = {},
		[2] = {}
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {forms = {}, info = nil, categories = {}}
	
	local base = mw.title.getCurrentTitle().subpageText
	local t = base .. "t"
	local e = (args[1] or base) .. "e"
	local comp
	local sup
	local supe
	
	if mw.ustring.find(base, "[et]$") or mw.ustring.find(base, "sk$") then
		t = base
	end
	
	if mw.ustring.find(base, "e$") then
		e = base
	end
	
	if args[2] == "peri" then
		comp = "[[mere]] [[" .. base .. "]]"
		sup  = "[[mest]] [[" .. base .. "]]"
		supe = "[[mest]] [[" .. e .. "]]"
	elseif args[2] == "st" then
		comp = (args[1] or base) .. "ere"
		sup  = base .. "st"
		supe = base .. "ste"
	elseif args[2] == "est" then
		comp = (args[1] or base) .. "ere"
		sup  = (args[1] or base) .. "est"
		supe = (args[1] or base) .. "este"
	end
	
	data.forms["pos_indf_c_sg"]  = {base}
	data.forms["pos_indf_n_sg"]  = {t}
	data.forms["pos_indf_pl"]    = {e}
	data.forms["pos_defn"]       = {e}
	
	data.forms["comp_indf_c_sg"] = {comp}
	data.forms["comp_indf_n_sg"] = {comp}
	data.forms["comp_indf_pl"]   = {comp}
	data.forms["comp_defn"]      = {comp}
	
	data.forms["sup_indf_c_sg"]  = {sup}
	data.forms["sup_indf_n_sg"]  = {sup}
	data.forms["sup_indf_pl"]    = {sup}
	data.forms["sup_defn"]       = {supe}
	
	postprocess(args, data)
	
	return make_table(data)
end


-- Make the table
function make_table(data)
	local function repl(param)
		if param == "info" then
			return data.info and " (" .. mw.getContentLanguage():ucfirst(data.info or "") .. ")" or ""
		elseif param == "lemma" then
			return m_links.full_link({lang = lang, alt = mw.title.getCurrentTitle().text}, "term")
		end
		
		local form = data.forms[param]
		
		if not form or #form == 0 then
			return "—"
		end
		
		local ret = {}
		
		for key, subform in ipairs(form) do
			table.insert(ret, m_links.full_link({lang = lang, term = subform}))
		end
		
		return table.concat(ret, ", ")
	end
	
	local wikicode = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="border: solid 1px #CCCCFF; text-align:left;" cellspacing="1" cellpadding="2"
|- style="background: #CCCCFF; vertical-align: top;"
! class="vsToggleElement" colspan="4" | Inflection of {{{lemma}}}{{{info}}}
|- class="vsHide" style="background: #CCCCFF;"
! style="min-width: 12em;" |
! style="min-width: 12em;" | Positive
! style="min-width: 12em;" | Comparative
! style="min-width: 12em;" | Superlative
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E6E6FF;" | Indefinte common singular
| {{{pos_indf_c_sg}}}
| {{{comp_indf_c_sg}}}
| {{{sup_indf_c_sg}}}<sup>2</sup>
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E6E6FF;" | Indefinite neuter singular
| {{{pos_indf_n_sg}}}
| {{{comp_indf_n_sg}}}
| {{{sup_indf_n_sg}}}<sup>2</sup>
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E6E6FF;" | Plural
| {{{pos_indf_pl}}}
| {{{comp_indf_pl}}}
| {{{sup_indf_pl}}}<sup>2</sup>
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E6E6FF;" | Definite attributive<sup>1</sup>
| {{{pos_defn}}}
| {{{comp_defn}}}
| {{{sup_defn}}}
|- class="vsHide" style="background: #E6E6FF;"
| style="font-size: smaller;" colspan="4" | 1) When an adjective is applied predicatively to something definite, the corresponding "indefinite" form is used.<br/> 2) The "indefinite" superlatives may not be used attributively.
|}]=]
	
	return mw.ustring.gsub(wikicode, "{{{([a-z0-9_:]+)}}}", repl) .. m_utilities.format_categories(data.categories, lang)
end

return export