Jump to content

မေႃႇၵျူး:definition/templates

လုၵ်ႉတီႈ ဝိၵ်ႇသျိၼ်ႇၼရီႇ မႃး

Documentation for this module may be created at မေႃႇၵျူး:definition/templates/doc

local export = {}

local m_definition = require("Module:definition")

-- Used for [[Template:&lit]].
function export.and_lit_t(frame)
	local parent_args = frame.getParent and frame:getParent().args or frame
	local compat = parent_args["lang"]
	local offset = compat and 0 or 1
	local params = {
		[compat and "lang" or 1] = {required = true, default = "und"},
		[1 + offset] = {list = true, allow_holes = true},
		["alt"] = {list = true, allow_holes = true, require_index = true},
		["sc"] = {},
		["qualifier"] = {},
		["dot"] = {},
		["nodot"] = {type = "boolean"},
		["nocap"] = {type = "boolean"},
	}
	
	local args = require("Module:parameters").process(parent_args, params)
	local lang = args[compat and "lang" or 1]
	lang = require("Module:languages").getByCode(lang) or require("Module:languages").err(lang, 1)
	local sc = args["sc"]
	sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)

	-- Find the maximum index among any of the list parameters.
	local maxmaxindex = 0
	for k, v in pairs(params) do
		if v.list and v.allow_holes and not v.alias_of and args[k].maxindex > maxmaxindex then
			maxmaxindex = args[k].maxindex
		end
	end

	local terms = {}
	for i=1,maxmaxindex do
		table.insert(terms, {
			term = args[1 + offset][i],
			alt = args["alt"][i],
			lang = lang,
			sc = sc
		})
	end
	if next(terms) == nil then -- if no terms were provided
		title = mw.title.getCurrentTitle().text
		for word in title:gmatch("[^%s]+") do -- insert all words of the title
			table.insert(terms, {
				term = word,
				lang = lang,
				sc = sc
			})
		end
	end

	return m_definition.and_lit(terms, args["qualifier"], args["dot"], args["nodot"], args["nocap"])
end

return export