Module:root: Difference between revisions

From Laenkea
Jump to navigation Jump to search
(Created page with "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 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 der...")
 
No edit summary
Line 6: Line 6:
local root_prefix = (source.proto and "*") or ""
local root_prefix = (source.proto and "*") or ""
for _, root in ipairs(roots) do
for _, root in ipairs(roots) do
if mw.ustring.sub(root, -1) ~= "-" then root = root .. "-" end
if language.code == source.code then
if language.code == source.code then
table.insert(categories, "[[Category:" .. language.name .. " terms belonging to the root " .. root_prefix .. root .. "]]")
table.insert(categories, "[[Category:" .. language.name .. " terms belonging to the root " .. root_prefix .. root .. "]]")
Line 24: Line 25:
local language = m_languages.get_by_code(args[1])
local language = m_languages.get_by_code(args[1])
local source = m_languages.get_by_code(args[2])
local source = m_languages.get_by_code(args[2])
if args[2] == "*" then source = language end
return export.make_categories(language, source, args[3])
return export.make_categories(language, source, args[3])
end
end


return export
return export

Revision as of 17:30, 16 June 2024

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 = m_languages.get_by_code(args[2])
	if args[2] == "*" then source = language end
	return export.make_categories(language, source, args[3])
end

return export