模組:Category tree/poscatboiler/data/families

維基詞典,自由的多語言詞典

此數據子模塊定義了維基詞典分類結構的一部分。

關於poscatboiler系統的介紹以及如何添加或更改分類,請參見Module:category tree/poscatboiler/data/documentation


local raw_categories = {}
local raw_handlers = {}



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


raw_categories["所有語系"] = {
	intro = "{{sisterlinks|Category: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["按語系分類的語言"] = {
	intro = "{{wikipedia|语言系属分类|语言系属分类|mul=语系列表|mullabel=语系列表}}",
	description = "本分類列出按語言系属分类的所有語言。",
	additional = "本分類列出按語言系属分类的所有語言。此處僅顯示最頂層的分類,完整列表請參閱[[:Category:所有语系]]或[[Wiktionary:語系列表]]。",
	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\">[//zh.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>其他名稱</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:語系|語系代碼]]</th><td><code>" .. fam:getCode() .. "</code></td>\n</tr>\n")
	table.insert(ret, "<tr>\n<th>[[w:祖語|共同祖語]]</th><td>")
	
	local protoLanguage = fam:getProtoLanguage()
	
	if protoLanguage then
		table.insert(ret, "[[:Category:" .. mw.getContentLanguage():ucfirst(protoLanguage:getCategoryName()) .. "|" .. protoLanguage:getCanonicalName() .. "]]")
	else
		table.insert(ret, "無")
	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:語系|父語系]]</th>\n<td>")
		table.insert(ret, "未分類")
	elseif parent:getCode() == "qfa-not" then
		table.insert(ret, "<tr>\n<th>[[Wiktionary:語系|父語系]]</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:" .. mw.ustring.gsub(parent:getCategoryName(), "^.", mw.ustring.upper) .. "|" .. parent:getCanonicalName() .. "]]")
			parent = parent:getFamily()
		end
		if #chain == 0 then
			table.insert(ret, "<tr>\n<th>[[Wiktionary:語系|父語系]]</th>\n<td>")
			table.insert(ret, "無")
		else
			table.insert(ret, "<tr>\n<th>[[Wiktionary:語系|父語系]]</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 = require("Module:families").getByCanonicalName(data.category)
	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 intro, description, additional = "", "", ""
	if not data.called_from_inside then
		local wikipedia_art = family:getWikipediaArticle()
		intro = "{{sisterlinks|" .. family:getCategoryName() .. "}}\n{{wikipedia|" .. wikipedia_art .. "}}"
		description = "本分類為'''" .. family:getCategoryName() .. "'''的主分類。"
		additional = "與" .. family:getCanonicalName() .. "有關的信息:\n\n" .. infobox(family)
	end
		
	return {
		intro = intro,
		description = description,
		additional = additional,
		parents = {
			{ name = first_parent, sort = family:getCode() },
			{ name = "所有語系", sort = family:getCode() },
		},
		breadcrumb = family:getCanonicalName(),
		can_be_empty = true,
	}
end)


return {RAW_CATEGORIES = raw_categories, RAW_HANDLERS = raw_handlers}