This data submodule defines part of Wiktionary's category structure.

For an introduction to the poscatboiler system and a description of how to add or modify categories, see Module:category tree/poscatboiler/data/documentation.


local raw_categories = {}
local raw_handlers = {}



-----------------------------------------------------------------------------
--                                                                         --
--                              RAW CATEGORIES                             --
--                                                                         --
-----------------------------------------------------------------------------


raw_categories["භාෂා පවුල් සියල්ල"] = {
	topright = "{{commonscat|Languages by family}}\n{{wikipedia|Language family|Language family|mul=List of language families|mullabel=List of language families}}",
	description = "This category lists all [[language family|language families]].",
	parents = {"මූලධර්ම"},
}

raw_categories["භාෂා පවුල අනුව භාෂා"] = {
	topright = "{{commonscat|Languages by family}}\n{{wikipedia|Language family|Language family|mul=List of language families|mullabel=List of language families}}",
	description = "This category contains all languages categorized hierarchically according to the [[language family]] they belong to.",
	additional = "Only top-level language families are shown here. For a full list of all language families, see [[:Category:All language families]] or [[Wiktionary:List of families]].",
	parents = {
		{name = "භාෂා සියල්ල", sort = " "},
		{name = "භාෂා පවුල් සියල්ල", sort = " "},
	},
}



-----------------------------------------------------------------------------
--                                                                         --
--                                RAW HANDLERS                             --
--                                                                         --
-----------------------------------------------------------------------------


local function family_is_not_a_family(fam)
	local famcode = fam:getCode()
	if famcode == "paa" then
		return false -- Papuan languages are not a family but have a category
	elseif famcode == "qfa-iso" or famcode == "qfa-not" then
		return true
	else
		local parfam = fam:getFamily()
		if parfam and parfam:getCode() == "qfa-not" then
			-- Constructed languages, sign languages, etc.; no category for them
			return true
		end
	end
	return false
end

	
local function infobox(fam)
	local ret = {}
	
	table.insert(ret, "<table class=\"wikitable\">\n")
	table.insert(ret, "<tr>\n<th colspan=\"2\" class=\"plainlinks\">[//si.wiktionary.org/w/index.php?title=Module:families/data&action=edit භාෂා පවුලේ දත්ත සංස්කරණය]</th>\n</tr>\n")
	table.insert(ret, "<tr>\n<th>කැනොනිකල් නාමය</th><td>" .. fam:getCanonicalName() .. "</td>\n</tr>\n")
	
	local otherNames = fam:getOtherNames(true)
	if otherNames then
		local names = {}
		
		for _, name in ipairs(otherNames) do
			table.insert(names, "<li>" .. name .. "</li>")
		end
		
		if #names > 0 then
			table.insert(ret, "<tr>\n<th>Other names</th><td><ul>" .. table.concat(names, "\n") .. "</ul></td>\n</tr>\n")
		end
	end
	
	local aliases = fam:getAliases()
	if aliases then
		local names = {}
		
		for _, name in ipairs(aliases) do
			table.insert(names, "<li>" .. name .. "</li>")
		end
		
		if #names > 0 then
			table.insert(ret, "<tr>\n<th>අන්වර්ථ නාම</th><td><ul>" .. table.concat(names, "\n") .. "</ul></td>\n</tr>\n")
		end
	end

	local varieties = fam:getVarieties()
	if varieties then
		local names = {}
		
		for _, name in ipairs(varieties) do
			if type(name) == "string" then
				table.insert(names, "<li>" .. name .. "</li>")
			else
				assert(type(name) == "table")
				local first_var
				local subvars = {}
				for i, var in ipairs(name) do
					if i == 1 then
						first_var = var
					else
						table.insert(subvars, "<li>" .. var .. "</li>")
					end
				end
				if #subvars > 0 then
					table.insert(names, "<li><dl><dt>" .. first_var .. "</dt>\n<dd><ul>" .. table.concat(subvars, "\n") .. "</ul></dd></dl></li>")
				elseif first_var then
					table.insert(names, "<li>" .. first_var .. "</li>")
				end
			end
		end
		
		if #names > 0 then
			table.insert(ret, "<tr>\n<th>Varieties</th><td><ul>" .. table.concat(names, "\n") .. "</ul></td>\n</tr>\n")
		end
	end

	table.insert(ret, "<tr>\n<th>[[Wiktionary:Families|භාෂා පවුලේ කේතය]]</th><td><code>" .. fam:getCode() .. "</code></td>\n</tr>\n")
	table.insert(ret, "<tr>\n<th>[[w:Proto-language|පොදු පූර්වජයා]]</th><td>")
	
	local protoLanguage = fam:getProtoLanguage()
	
	if protoLanguage then
		table.insert(ret, "[[:Category:" .. protoLanguage:getCategoryName() .. "|" .. protoLanguage:getCanonicalName() .. "]]")
	else
		table.insert(ret, "none")
	end
	
	table.insert(ret, "</td>\n")
	table.insert(ret, "\n</tr>\n")
	
	local parent = fam:getFamily()
	
	if not parent then
		table.insert(ret, "<tr>\n<th>[[Wiktionary:Families|ජනක භාෂා පවුල]]</th>\n<td>")
		table.insert(ret, "unclassified")
	elseif parent:getCode() == "qfa-not" then
		table.insert(ret, "<tr>\n<th>[[Wiktionary:Families|ජනක භාෂා පවුල]]</th>\n<td>")
		table.insert(ret, "not a family")
	else
		local chain = {}
		while parent do
			if family_is_not_a_family(parent) then
				break
			end
			table.insert(chain, "[[:Category:" .. parent:getCategoryName() .. "|" .. parent:getCanonicalName() .. "]]")
			parent = parent:getFamily()
		end
		if #chain == 0 then
			table.insert(ret, "<tr>\n<th>[[Wiktionary:Families|ජනක භාෂා පවුල]]</th>\n<td>")
			table.insert(ret, "no parents")
		else
			table.insert(ret, "<tr>\n<th>[[Wiktionary:Families|ජනක භාෂා පවුල"
				.. (#chain == 1 and "ල" or "ල්") .. "]]</th>\n<td>")
			
			for i = #chain, 1, -1 do
				table.insert(ret, "<ul><li>" .. chain[i])
			end
			table.insert(ret, string.rep("</li></ul>", #chain))
		end
	end
	
	table.insert(ret, "</td>\n</tr>\n")
	
	if fam:getWikidataItem() and mw.wikibase then
		local link = '[' .. mw.wikibase.getEntityUrl(fam:getWikidataItem()) .. ' ' .. fam:getWikidataItem() .. ']'
		table.insert(ret, "<tr><th>විකි දත්ත</th><td>" .. link .. "</td></tr>")
	end
	
	table.insert(ret, "</table>")
	
	return table.concat(ret)
end


table.insert(raw_handlers, function(data)
	local family_name = data.category:match("^(.+) භාෂා$") or
		data.category:match("^.+ භාෂා$") or
		data.category:match("^.+ [Ll]ects$")
	if not family_name then
		return nil
	end
	local family = require("Module:families").getByCanonicalName(family_name) or
		require("Module:families").getByCanonicalName(mw.ustring.lower(family_name))
	if not family then
		return nil
	end

	local parent_fam = family:getFamily()
	local first_parent
	
	if not parent_fam or family_is_not_a_family(parent_fam) then
		first_parent = "භාෂා පවුල අනුව භාෂා"
	else
		first_parent = parent_fam:getCategoryName()
	end

	local topright, description, additional = "", "", ""
	if not data.called_from_inside then
		local wikipedia_art = family:getWikipediaArticle()
		topright = "{{commonscat|" .. family:getCategoryName() .. "}}\n{{wikipedia|" .. wikipedia_art .. "}}"
		description = "මෙය '''" .. family:getDisplayForm() .. "''' සඳහා වන ප්‍රධාන ප්‍රවර්ගය වෙයි."
		additional = "" .. family:getCanonicalName() .. " පිළිබඳ තොරතුරු:\n\n" .. infobox(family)
	end

	local parents = {
		first_parent,
		"භාෂා පවුල් සියල්ල",
	}
	if parent_fam and parent_fam:getCode() == "sgn" then
		table.insert(parents, "All sign languages")
	end
	
	return {
		topright = topright,
		description = description,
		additional = additional,
		parents = parents,
		breadcrumb = family:getCanonicalName(),
		can_be_empty = true,
	}
end)


return {RAW_CATEGORIES = raw_categories, RAW_HANDLERS = raw_handlers}
"https://si.wiktionary.org/w/index.php?title=Module:category_tree/poscatboiler/data/families&oldid=182350" වෙතින් සම්ප්‍රවේශනය කෙරිණි