Bước tới nội dung

Mô đun:category tree/topic/data

Từ điển mở Wiktionary
local labels = {}
local handlers = {}

local top_level_data_module = "Module:category tree/topic/data"
local data_module_prefix = "Module:category tree/topic/"

local subpages = {
	"Animals",
	"Body",
	"Buildings and structures",
	"Communication",
	"Culture",
		"Religion",
	"Food and drink",
	"Games",
	"History",
	"Human",
		"People",
	"Lifeforms",
	"Mathematics",
	"Music",
	"Names",
	"Nature",
	"Numbers",
	"Philosophy",
	"Places",
	"Plants",
	"Sciences",
	"Sex",
	"Society",
	"Sports",
	"Technology",
	"Time",
	"Transport",
}

labels["Tất cả chủ đề"] = {
	type = "toplevel",
	description = "Liệt kê các từ {{{langname}}} được xếp theo chủ đề, có thể là \"Gia đình\", \"Hóa học\", \"Hành tinh\", \"Họ Chó\", \"Địa danh\" hoặc \"Thành phố của Việt Nam\".",
	parents = {{name = "{{{langcat}}}", nontopic = true}},
}

for _, typ in ipairs { "chủ đề thuộc nhóm liên quan", "chủ đề thuộc nhóm tập hợp", "chủ đề thuộc nhóm loại hình", "chủ đề thuộc nhóm tên gọi", "chủ đề phân nhóm", "chủ đề thuộc nhóm hỗn hợp"} do
	labels["Danh sách " .. typ] = {
		type = "toplevel",
		description = "Tất cả " .. typ .. " có sẵn trong {{{langname}}}.",
		parents = {{name = "Tất cả chủ đề", sort = " *"}},
	}
end

labels["chủ đề thuộc nhóm hỗn hợp"] = {
	type = "toplevel",
	description = "All categories currently available in {{{langname}}} that belong to more than one type.",
	parents = {{name = "Tất cả chủ đề", sort = " *"}},
}

for label, data in pairs(labels) do
	data.module = top_level_data_module
end

-- Don't throw error on every single category, but on a subset of them, especially the top-level ones.
local function should_throw_error()
	local title = mw.title.getCurrentTitle().text
	return title:find("Danh sách ") or title:find("Tất cả ") or title:find(" mục từ")
end

-- Import subpages
for _, subpage in ipairs(subpages) do
	local datamodule = data_module_prefix .. subpage
	local retval = require(datamodule)
	if not retval["LABELS"] then
		retval = {LABELS = retval}
	end
	for label, data in pairs(retval["LABELS"]) do
		if labels[label] and not retval["IGNOREDUP"] then
			-- Avoid throwing an error on every single topic category and any other invoking category that calls the
			-- topic code.
			if should_throw_error() then
				error("Nhãn " .. label .. " trùng lặp ở [["
					.. datamodule .. "]] và [[" .. labels[label].module .. "]].")
			end
		end
		data.module = datamodule
		labels[label] = data
	end
	if retval["HANDLERS"] then
		for _, handler in ipairs(retval["HANDLERS"]) do
			table.insert(handlers, { module = datamodule, handler = handler })
		end
	end
end

return {LABELS = labels, HANDLERS = handlers}