Module:root

Revision as of 17:31, 16 June 2024 by TheNightAvl (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:root/documentation

local export = {}
local m_languages = require("Module:languages")

function export.make_categories(language, source, roots)
	local categories = {}
	local root_prefix = (source.proto and "*") or ""
	for _, root in ipairs(roots) do
		if mw.ustring.sub(root, -1) ~= "-" then root = root .. "-" end
		if language.code == source.code then
			table.insert(categories, "[[Category:" .. language.name .. " terms belonging to the root " .. root_prefix .. root .. "]]")
		else
			table.insert(categories, "[[Category:" .. language.name .. " terms derived from the " .. source.name .. " root " .. root_prefix .. root .. "]]")
		end
	end
	return table.concat(categories)
end

function export.show(frame)
	local params = {
		[1] = {required = true},
		[2] = {required = true},
		[3] = {required = true, list = true},
	}
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local language = m_languages.get_by_code(args[1])
	local source = language
	if args[2] ~= "*" then source = m_languages.get_by_code(args[2]) end
	return export.make_categories(language, source, args[3])
end

return export