Module:User:Per utramque cavernam/Etymology/Templates

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of Per utramque cavernam, for their own experimentation. Items in this module may be added and removed at Per utramque cavernam's discretion; do not rely on this module's stability.


local export = {}

local m_languages = require("Module:languages")


local function fetch_lang(lang, parameter)
	return m_languages.getByCode(lang) or m_languages.err(lang, parameter)
end


local function fetch_source(code, disallow_family)
	local source =
		m_languages.getByCode(code)
		or require("Module:etymology languages").getByCode(code)
		or not disallow_family and require("Module:families").getByCode(code)
	
	if source then
		return source
	else
		error("The language" .. (not disallow_family and ", family" or "") .. " or etymology language code \"" .. code .. "\" is not valid.")
	end
end


local function fetch_script(sc)
	if sc then
		return require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
	else
		return nil
	end
end

function export.psm(frame)
	
	local params = {
		[1] = {required = true, default = "und"},
		[2] = {required = true, default = "und"},
		[3] = {},
		[4] = {alias_of = "alt"},
		[5] = {alias_of = "t"},
		
		["alt"] = {},
		["g"] = {},
		["gloss"] = {alias_of = "t"},
		["id"] = {},
		["lit"] = {},
		["pos"] = {},
		["t"] = {},
		["tr"] = {},
		["sc"] = {},
		
		["nocap"] = {type = "boolean"},
		["notext"] = {type = "boolean"},
		["sort"] = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lang = fetch_lang(args[1], 1)
	local source = fetch_source(args[2])
	local sc = fetch_script(args["sc"])

	return require("Module:User:Per utramque cavernam/Etymology").psm(
		lang,
		{lang = source, sc = sc, term = args[3], alt = args["alt"], id = args["id"], genders = {args["g"]}, tr = args["tr"], gloss = args["t"], pos = args["pos"], lit = args["lit"]},
		args["sort"], args["nocap"], args["notext"])
end

return export