Module:form of: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
No edit summary
Line 24: Line 24:
["past"] = {label = "past", glossary = "past tense"},
["past"] = {label = "past", glossary = "past tense"},
["nonpast"] = {label = "non-past", glossary = "non-past tense"},
["nonpast"] = {label = "non-past", glossary = "non-past tense"},
["present"] = {label = "present", glossary = "present tense"},
["future"] = {label = "future", glossary = "future tense"},
["future"] = {label = "future", glossary = "future tense"},
["aorist"] = {label = "aorist", glossary = "aorist tense"},
["aorist"] = {label = "aorist", glossary = "aorist tense"},
Line 62: Line 63:
["imp"] = "imperative",
["imp"] = "imperative",
["pst"] = "past",
["pst"] = "past",
["pres"] = "present",
["npst"] = "nonpast",
["npst"] = "nonpast",
["fut"] = "future",
["fut"] = "future",

Revision as of 14:59, 9 August 2023

local export = {}

local m_links = require("Module:links")

local labels = {
	["1"] = {label = "first-person", glossary = "first person"},
	["2"] = {label = "second-person", glossary = "second person"},
	["3"] = {label = "third-person", glossary = "third person"},
	["singular"] = {label = "singular", glossary = true},
	["dual"] = {label = "dual", glossary = true},
	["plural"] = {label = "plural", glossary = true},
	["inclusive"] = {label = "inclusive", glossary = "clusivity"},
	["exclusive"] = {label = "exclusive", glossary = "clusivity"},
	["impersonal"] = {label = "impersonal", glossary = true},
	["depersonal"] = {label = "depersonal", glossary = true},
	["active"] = {label = "active", glossary = "active voice"},
	["passive"] = {label = "passive", glossary = "passive voice"},
	["mediopassive"] = {label = "mediopassive", glossary = "mediopassive voice"},
	["indicative"] = {label = "indicative", glossary = "indicative mood"},
	["subjunctive"] = {label = "subjunctive", glossary = "subjunctive mood"},
	["conditional"] = {label = "conditional", glossary = "conditional mood"},
	["optative"] = {label = "optative", glossary = "optative mood"},
	["imperative"] = {label = "imperative", glossary = "imperative mood"},
	["past"] = {label = "past", glossary = "past tense"},
	["nonpast"] = {label = "non-past", glossary = "non-past tense"},
	["present"] = {label = "present", glossary = "present tense"},
	["future"] = {label = "future", glossary = "future tense"},
	["aorist"] = {label = "aorist", glossary = "aorist tense"},
	["negative"] = {label = "negative", glossary = true},
	["interrogative"] = {label = "interrogative", glossary = true},
	["perfective"] = {label = "perfective", glossary = "perfective aspect"},
	["imperfective"] = {label = "imperfective", glossary = "imperfective aspect"},
	["habitual"] = {label = "habitual", glossary = "habitual aspect"},
	["humble"] = {label = "humble", glossary = true},
	["animate"] = {label = "animate", glossary = true},
	["inanimate"] = {label = "inanimate", glossary = true},
	["nominative"] = {label = "nominative", glossary = "nominative case"},
	["accusative"] = {label = "accusative", glossary = "accusative case"},
}
local aliases = {
	["sg"] = "singular",
	["s"] = "singular",
	["du"] = "dual",
	["d"] = "du",
	["pl"] = "plural",
	["p"] = "pl",
	["inc"] = "inclusive",
	["incl"] = "inclusive",
	["exc"] = "exclusive",
	["excl"] = "exclusive",
	["impers"] = "impersonal",
	["impr"] = "impersonal",
	["deper"] = "depersonal",
	["depers"] = "depersonal",
	["act"] = "active",
	["pass"] = "passive",
	["ind"] = "indicative",
	["subj"] = "subjunctive",
	["sbj"] = "subjunctive",
	["sjv"] = "subjunctive",
	["cond"] = "conditional",
	["opt"] = "optative",
	["imp"] = "imperative",
	["pst"] = "past",
	["pres"] = "present",
	["npst"] = "nonpast",
	["fut"] = "future",
	["aor"] = "aorist",
	["neg"] = "negative",
	["interr"] = "interrogative",
	["intrg"] = "interrogative",
	["anim"] = "animate",
	["an"] = "animate",
	["in"] = "inanimate",
	["inan"] = "inanimate",
	["nom"] = "nominative",
	["acc"] = "accusative",
}

local function make_labels(inflections)
	local out = {}
	for _, inflection in ipairs(inflections) do
		if aliases[inflection] then inflection = aliases[inflection] end
		local l = labels[inflection]
		if l then
			local text = l.label or inflection
			if l.glossary then
				table.insert(out, "[[Appendix:Glossary#" .. (type(l.glossary) == "string" and l.glossary or text) .. "|" .. text .. "]]")
			else
				table.insert(out, text)
			end
		else
			table.insert(out, inflection)
		end
	end
	return table.concat(out, " ")
end

function export.make_form_of(data)
	local label
	local link = m_links.full_link(data, "term")
	if data.inflection then
		label = make_labels(data.inflection)
	else
		label = data.form or "alternative form"
	end
	return '<span class="form-of">' .. label .. ' of ' .. link .. '</span>'
end

return export