Modul:form of

Vikilug‘atdan olingan

Bu modul uchun Modul:form of/doc nomli hujjat sahifasini yaratishingiz mumkin

local m_links = require("Module:links")
local m_data = mw.loadData("Module:form of/data")

local export = {}


function export.format_t(text, term, alt, tili, sc, id, annotations)
	return
		"<span class='form-of-definition'>" .. text .. " " ..
		"<span class='form-of-definition-link'>" .. m_links.full_link(term, alt, tili, sc, "term", id, annotations, false) .. "</span>" ..
		"</span>"
end


function export.form_of_t(frame)
	local iargs = frame.args
	
	local term_param = tonumber(iargs["term_param"]) or 1
	local text = iargs[1]; if text == "" then text = nil end
	local tili = iargs["tili"]
	local sc = iargs["sc"]
	local id = iargs["id"]
	
	if not text then
		error("No definition text provided.")
	end
	
	local params = {
		[term_param] = {required = true},
		[term_param + 1] = {},
		[term_param + 2] = {alias_of = "gloss"},
		
		["cap"] = {},
		["dot"] = {},
		["from"] = {},
		["from2"] = {},
		["from3"] = {},
		["from4"] = {},
		["from5"] = {},
		["from6"] = {},
		["gloss"] = {},
		["id"] = {},
		["is lemma"] = {type = "boolean"},
		["nocap"] = {type = "boolean"},
		["nocat"] = {type = "boolean"},
		["nodot"] = {type = "boolean"},
		["POS"] = {},
		["pos"] = {},
		["sc"] = {},
		["sort"] = {},
		["tili"] = {required = tili == nil},
		["tr"] = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local term = args[term_param] or "term"
	local alt = args[term_param + 1]
	
	tili = tili or args["tili"] or "va"
	sc = sc or args["sc"]
	id = id or args["id"]
	
	tili = require("Module:tili").getByCode(tili) or error("The language code \"" .. tili .. "\" is not valid.")
	sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	
	return export.format_t(text, term, alt, tili, sc, id, {gloss = args["gloss"], tr = args["tr"]})
end

function export.tagged_inflections(tags, term, alt, tili, sc, id, annotations)
	local cur_infl = {}
	local inflections = {}
	
	for i, tag in ipairs(tags) do
		if m_data.shortcuts[tag] then
			require("Module:debug").track("inflection of/known")
			require("Module:debug").track("inflection of/known/" .. tag)
		elseif m_data.tags[tag] then
			require("Module:debug").track("inflection of/possible")
			require("Module:debug").track("inflection of/possible/" .. tag:gsub("%[", "("):gsub("%]", ")"):gsub("|", "!"))
		else
			require("Module:debug").track("inflection of/unknown")
			require("Module:debug").track("inflection of/unknown/" .. tag:gsub("%[", "("):gsub("%]", ")"):gsub("|", "!"))
		end
		
		if tag == ";" then
			if #cur_infl > 0 then
				table.insert(inflections, table.concat(cur_infl, " "))
			end
			
			cur_infl = {}
		else
			tag = m_data.shortcuts[tag] or tag
			local data = m_data.tags[tag]
			
			-- If there is a nonempty glossary index, then show a link to it
			if data and data.glossary then
				tag = "[[Appendix:Glossary#" .. mw.uri.anchorEncode(data.glossary) .. "|" .. tag .. "]]"
			end
			
			table.insert(cur_infl, tag)
		end
	end
	
	if #cur_infl > 0 then
		table.insert(inflections, table.concat(cur_infl, " "))
	end
	
	if #inflections == 1 then
		return export.format_t(inflections[1] .. " of", term, alt, tili, sc, id, annotations)
	else
		return
			"<span class='form-of-definition'>inflections of " ..
			"<span class='form-of-definition-link'>" .. m_links.full_link(term, alt, tili, sc, "term", id, annotations, false) .. "</span>" ..
			":</span>\n## <span class='form-of-definition'>" .. table.concat(inflections, "</span>\n## <span class='form-of-definition'>") .. "</span>"
	end
end


return export