Module:sce-verb-form

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 export = {}
local m_links = require("Module:links")
local m_utilities = require("Module:utilities")

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

local data = mw.loadData("Module:sce-verb-form/data")

local function show_categories(data, lang, sort_key)
	local categories = {}
	
	for i, cat in ipairs(data.categories or {}) do
		table.insert(categories, lang:getCanonicalName() .. " " .. cat)
	end
	
	return m_utilities.format_categories(categories, lang, sort_key) 
end

function export.mn_verb_form(frame)
	local params = {
		[1] = {required = true, default = "suffix"},  --suffix
		[2] = {required = true, default = "term"},  --verb
		[3] = {},
		[4] = {alias_of = "gloss"},
		
		["dot"] = {},
		["gloss"] = {},
		["t"] = {alias_of = "gloss"},
		["id"] = {},
		["nodot"] = {type = "boolean"},
		["nocat"] = {type = "boolean"},
		["sc"] = {},
		["tr"] = {},
		["sort_key"] = {},
	}	
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local suffix = args[1]
	local text = ""
	local alias = false
	
	if data.aliases[args[1]] then
		alias = true
		suffix = data.aliases[args[1]]
	end
	
	if data.suffix[suffix] then
		local suffixinfo = {lang = lang, sc = Latn, term = "-"..suffix, alt = alias and "-" .. args[1], id = "verb suffix"}
		local suffixlink = m_links.full_link(suffixinfo, "term", false)
		text = data.suffix[suffix].name .. " in " .. suffixlink .. " of"
	else 
		error("suffix not found")
	end
	
	local lemma_obj = {lang = lang, sc = sc, term = args[2], alt = args[3], id = args["id"], gloss = args["gloss"], tr = args["tr"]}
	return require("Module:form of").format_form_of {
		text = text, lemmas = {lemma_obj}, lemma_face = "term"
	} .. (args.nocat and "" or show_categories(data.suffix[suffix], lang, args["sort_key"]))
end

function export.mn_suffix_name(frame)
	local params = {
		[1] = {required = true, default = "suffix"},
	}
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local suffix = args[1]
	
	if data.aliases[suffix] then
		suffix = data.aliases[suffix]
	end
	
	if data.suffix[suffix] then
		return data.suffix[suffix].name
	else 
		error("suffix not found")
	end
end
	
return export