Module:form of

Avy amin'i Wikibolana — Rakibolana malagasy malalaka

local export = {}

local m_links = require("Module:links")

local inflection_tags = {
	-- Person
	["1"] = "olona voalohany",
	["2"] = "olona faharoa",
	["3"] = "olona fahatelo",
	["impers"] = "nampiseho ny maha",
	
	-- Number
	["s"] = "tokan-tena",
	["d"] = "amin'ny teny",
	["p"] = "amin'ny teny",
	
	-- Gender
	["m"] = "dehilahy",
	["f"] = "vehivavy",
	["n"] = "iombonana",
	["c"] = "aho",
	
	-- Animacy (may be useful sometimes for [[Module:object usage]].)
	["an"] = "mamelona",
	["in"] = "tsy nanana aina",
	["pr"] = "makokana",
	
	-- Tense/aspect
	["pres"] = "farany",
	["past"] = "lasa",
	["futr"] = "taty aoriana", ["fut"] = "taty aoriana",
	["pret"] = "lasa matoanteny",
	["perf"] = "tonga lafatra",
	["impf"] = "tsy lavorary", ["imperf"] = "tsy lavorary",
	["plup"] = "matoanteny lasa tanteraka", ["pluperf"] = "matoanteny lasa tanteraka",
	["aori"] = "assorti", ["aor"] = "assorti",
	["phis"] = "manan-tantara taloha",
	
	-- Mood
	["impr"] = "imperatif", ["imp"] = "imperatif",
	["indc"] = "indikatif", ["ind"] = "indikatif",
	["subj"] = "sembawa", ["sub"] = "sembawa",
	["cond"] = "bersyarat",
	
	-- Voice
	["actv"] = "mavitrika", ["act"] = "mavitrika",
	["midl"] = "afovoany", ["mid"] = "afovoany",
	["pasv"] = "matoantenin'ny atao", ["pass"] = "matoantenin'ny atao",
	["mpsv"] = "afovoany matoantenin'ny atao", ["mp"] = "afovoany matoantenin'ny atao",
	
	-- Non-finite
	["inf"] = "matoanteny",
	["part"] = "misitrika",
	
	-- Cases
	["abe"] = "abesiva",
	["abl"] = "ablativa",
	["abs"] = "absolutiva",
	["ade"] = "adesiva",
	["all"] = "rehetra",
	["acc"] = "mpanao ny atao",
	["cfi"] = "antony sy ny vokatry ny farany",
	["com"] = "fiarahana",
	["dat"] = "dativa",
	["del"] = "delativa",
	["ela"] = "elativa",
	["erg"] = "ergativa",
	["esf"] = "matoantenin'ny atao-tsekoly",
	["esm"] = "matoantenin'ny atao-modaly",
	["ess"] = "matoantenin'ny atao",
	["gen"] = "tokony hofenoina",
	["ill"] = "ilatif",
	["ine"] = "inessive",
	["ins"] = "perantian",
	["loc"] = "lokatif",
	["nom"] = "nominatif",
	["obl"] = "tidak langsung",
	["par"] = "partitif",
	["pre"] = "preposisi", ["prep"] = "preposisi",
	["sbl"] = "sublatif",
	["spe"] = "superesif",
	["ter"] = "terminatif",
	["tra"] = "fandikan-teny",
	["voc"] = "fiantsoana",
}

local matches = {}

for key, val in pairs(inflection_tags) do
	matches[val] = true
end


-- used by [[Module:object usage]] (experimental!)
export.abbr = inflection_tags

function format_t(args, iargs, text, term, alt, gloss)
	NAMESPACE = mw.title.getCurrentTitle().nsText
	
	local categories = {}
	local annotations = {}
	
	local lang = iargs["lang"] or args["lang"]; if lang == "" then lang = nil end
	local sc = iargs["sc"] or args["sc"]; if sc == "" then sc = nil end
	local id = iargs["id"] or args["id"]; if id == "" then id = nil end
	annotations.gloss = gloss
	annotations.tr = args["tr"]; if annotations.tr == "" then annotations.tr = nil end
	
	if not lang then
		lang = "en"
		table.insert(categories, "Kod bahasa hilang/bentuk")
	end
	
	lang = require("Module:languages").getByCode(lang) or error("Kod bahasa \"" .. lang .. "\" tidak sah.")
	sc = (sc and (require("Module:scripts").getByCode(sc) or error("Kod skrip \"" .. sc .. "\" tidak sah.")) or nil)
	
	if not term then
		if NAMESPACE == "Template" then
			term = "term"
		else
			error("You have not given a term to link to.")
		end
	end
	
	if not text then
		error("No definition text provided.")
	end
	
	if #categories > 0 then
		local m_utilities = require("Module:utilities")
		categories = m_utilities.format_categories(categories, lang, nil)
	else
		categories = ""
	end
	
	return
		"<span class='form-of-definition'>" .. text .. " " ..
		"<span class='form-of-definition-link'>" .. m_links.full_link(term, alt, lang, sc, "term", id, annotations, false) .. "</span>" ..
		"</span>" .. categories
end


function export.form_of_t(frame)
	local args = frame:getParent().args
	local iargs = frame.args
	
	local term_param = tonumber(iargs["term_param"]) or 1
	local text = iargs[1]; if text == "" then text = nil end
	
	local term = args[term_param]; if term == "" then term = nil end
	local alt = args[term_param + 1]; if alt == "" then alt = nil end
	local gloss = args[term_param + 2]; if gloss == "" then gloss = nil end
	
	local categories = ""
	
	return format_t(args, iargs, text, term, alt, gloss) .. categories
end


function export.inflection_t(frame)
	local args = frame:getParent().args
	local iargs = frame.args
	
	local term = args[1]; if term == "" then term = nil end
	local alt = args[2]; if alt == "" then alt = nil end
	local gloss = args["gloss"]; if gloss == "" then gloss = nil end
	
	local inflections = {}
	local i = 3
	local infl = args[i]
	
	while infl do
		if infl ~= "" then
			if inflection_tags[infl] then
				require("Module:debug").track("infleksi/diketahui")
				require("Module:debug").track("infleksi/diketahui/" .. infl)
			elseif matches[infl] then
				require("Module:debug").track("infleksi/kemungkinan")
				require("Module:debug").track("infleksi/kemungkinan/" .. infl:gsub("%[", "("):gsub("%]", ")"):gsub("|", "!"))
			else
				require("Module:debug").track("infleksi/tidak diketahui")
				require("Module:debug").track("infleksi/tidak diketahui/" .. infl:gsub("%[", "("):gsub("%]", ")"):gsub("|", "!"))
			end
			
			table.insert(inflections, inflection_tags[infl] or infl)
		end
		
		i = i + 1
		infl = args[i]
	end
	
	return format_t(args, iargs, table.concat(inflections, " ") .. " dari", term, alt, gloss)
end


return export