Module:User:Victar/desctree2/templates

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


local export = {}

local m_languages = require("Module:languages")

function export.show(frame)
	local params = {
		[1] = {required = true, default = "la"},
		[2] = {required = true, default = "aqua"},
		[3] = {},
		[4] = {alias_of = "gloss"},
		["g"] = {list = true},
		["gloss"] = {},
		["id"] = {},
		["lit"] = {},
		["pos"] = {},
		["tr"] = {},
		["sc"] = {},
		["notext"] = { boolean = true },
		["bor"] = { boolean = true },
		["der"] = { boolean = true },
		["q"] = {},
	}
	
	if frame.args[1] then
		args = require("Module:parameters").process(frame.args, params)
	else
		args = require("Module:parameters").process(frame:getParent().args, params)
	end
	
	local lang = args[1]
	local term = args[2]
	local alt = args[3]
	local sc = args["sc"]
	
	if namespace == "Template" then
		if not sc and not lang then
			sc = "Latn"
		end
		if not lang then
			lang = "en"
		end
		if not term then
			term = "word"
		end
	end
	
	lang = m_languages.getByCode(lang)
		or require("Module:etymology languages").getByCode(lang)
		or m_languages.err(lang, 1)
		
	local entryLang = require("Module:etymology").getFull(lang)
	
	if lang:getCode() ~= entryLang:getCode() then
		-- [[Special:WhatLinksHere/Wiktionary:Tracking/descendant/etymological]]
		require("Module:debug").track("descendant/etymological")
		require("Module:debug").track("descendant/etymological/" .. lang:getCode())
	end
	
	if sc then
		sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
	end
	
	local languageName = lang:getCanonicalName()
	languageName = mw.ustring.gsub(languageName, "^Proto%-", "")
	
	local descendants = require("Module:User:Victar/desctree2").getDescendants(entryLang, term)
	
	local alts = require("Module:User:Victar/desctree2").getAlternativeForms(entryLang, term)
	
	local link = require("Module:links").full_link(
		{
			lang = entryLang,
			sc = sc,
			term = args[2],
			alt = args[3],
			id = args["id"],
			tr = args["tr"],
			genders = args["g"],
			gloss = args["gloss"],
			pos = args["pos"],
			lit = args["lit"],
		},
		nil,
		true
	)
	
	local arrow = ""
	if args["bor"] then
		arrow = "→ "
	elseif args["der"] then
		arrow = "⇒ "
	end
	
	local prefix = ""
	if args["notext"] then
		prefix = ""
	else
		prefix = table.concat{arrow, languageName, ": "}
	end
	
	local qual = ""
	if args["q"] then
		qual = " " .. require("Module:qualifier").format_qualifier(args["q"])
	end
	
	return table.concat{prefix, link, alts, qual, descendants}
	
end

return export