Пређи на садржај

Модул:category tree/derived cat

Script error: The function "main" does not exist.

local export = {}

-- Category object

local Category = {}
Category.__index = Category


function Category.new_main(frame)
	local params = {
		[1] = {},
		[2] = {required = true},
	}
	
	args = require("Модул:parameters").process(frame:getParent().args, params)
	
	return Category.new({code = args[1], label = args[2]})
end


function Category.new(info)
	for key, val in pairs(info) do
		if not (key == "code" or key == "label") then
			error("The parameter \"" .. key .. "\" was not recognized.")
		end
	end
	
	local self = setmetatable({}, Category)
	self._info = info
	
	if not self._info.label then
		error("No label was specified.")
	end
	
	self._lang = self._info.code and (require("Модул:languages").getByCode(self._info.code) or error("The language code \"" .. self._info.code .. "\" is not valid.")) or nil
	self._source = 
		require("Модул:families").getByCode(self._info.label) or
		require("Модул:etymology languages").getByCode(self._info.label) or
		require("Модул:languages").getByCode(self._info.label) or 
		error("\"" .. self._info.label .. "\" is not a valid language, family or etymology-only language code.")
	
	return self
end

export.new = Category.new
export.new_main = Category.new_main


function Category:getInfo()
	return self._info
end


function Category:getBreadcrumbName()
	local ret = nil
	
	if self._source:getType() == "family" then
		ret = self._source:getCategoryName()
	else
		ret = self._source:getCanonicalName()
	end
	
	return (not self._lang and "појмови изведени из " or "") .. ret
end


function Category:getDataModule()
	return "Модул:category tree/derived cat"
end


function Category:canBeEmpty()
	return false
end


function Category:isHidden()
	return false
end


function Category:getCategoryName()
	local ret = nil

	if self._source:getType() == "family" then
		ret = self._source:getCategoryName()
	else
		if self._source:getCode() == "mul-tax" then
			ret = "taxonomic names"
		else
			ret = self._source:getCanonicalName()
		end
	end
	
	if self._lang then
		return mw.getContentLanguage():ucfirst(self._lang:getCanonicalName() .. " појмови изведени из " .. ret)
	else
		return "Појмови изведени из " .. ret
	end
end


function Category:getDescription()
	local ret = nil
	
	if not self._lang then
		if self._source:getType() == "family" then
			return "Категорије са терминима изведеним из " .. self._source:getCategoryName() .. " у разним специфичним језицима."
		else
			return "Категорије са терминима изведеним из " .. self._source:getCanonicalName() .. " у разним специфичним језицима."
		end
	else
		if self._source:getType() == "family" then
			return
				"Термини у " .. self._lang:getCanonicalName() .. " that originate from " ..
				"[[:Категорија:" .. mw.getContentLanguage():ucfirst(self._source:getCategoryName()) .. "|" .. self._source:getCategoryName() .. "]].\n\n" ..
				"Ова категорија should, ideally, contain only other categories. Entries can be categorized here, too, when the proper subcategory is unclear. " ..
				"If you know the exact language from which an entry categorized here is derived, please edit its respective entry."
		elseif self._source:getType() == "etymology language" then
			return "Појмови у " .. self._lang:getCanonicalName() .. " потичу из " .. self._source:getCanonicalName() .. "."
		else
			return "Појмови у " .. self._lang:getCanonicalName() .. " потичу из [[:Категорија:" .. mw.getContentLanguage():ucfirst(self._source:getCategoryName()) .. "|" .. self._source:getCategoryName() .. "]]."
		end
	end
end


function Category:getParents()
	local derived_from_subvariety_of_self = false
	if self._lang then
		local parent = {}
		
		local pinfo = {
			code = self._lang:getCode()
		}
		local sortkey = nil
		
		if self._source:getType() == "family" then
			local fam = self._source:getFamily()
			
			if not fam or fam:getCode() == "qfa-iso" or fam:getCode() == "qfa-not" then
				pinfo.label = nil
			else
				pinfo.label = fam:getCode()
			end
			
			sortkey = self._source:getCategoryName()
		elseif self._source:getType() == "etymology language" then
			if self._source:getParentCode() == "qfa-iso" or self._source:getParentCode() == "qfa-not" or self._source:getParentCode() == "qfa-und" then
				pinfo.label = nil
			elseif self._source:getParentCode() == self._lang:getCode() then
				-- error("A language can't derive terms from a subvariety of itself.")
				derived_from_subvariety_of_self = true
				pinfo.label = self._lang:getFamily():getCode()
			else
				pinfo.label = self._source:getParentCode()
			end
			
			sortkey = self._source:getCanonicalName()
		else
			local fam = self._source:getFamily()
			
			if fam and not (fam:getCode() == "qfa-iso" or fam:getCode() == "qfa-not") then
				pinfo.label = fam:getCode()
			end -- else label is nil
			
			sortkey = self._source:getCanonicalName()
		end
		
		local additional_category = derived_from_subvariety_of_self and {
				name = "Категорија:Категорија за појмове у језицима изведеним из разних специфичности на овај језик",
				sort = self._lang:getCanonicalName()
			} or nil
		
		if not pinfo.label then
			return {
				{
					name = require("Модул:category tree/poscatboiler")
						.new {
							code = self._info.code,
							label = "појмови изведени из других језика"
						},
					sort = sortkey
				},
				additional_category,
			}
		else
			return {{name = Category.new(pinfo), sort = sortkey}, additional_category}
		end
	else
		if self._source:getType() == "family" then
			return {{name = require("Модул:category tree/famcatboiler").new({code = self._info.label}), sort = " "}}
		elseif self._source:getType() == "etymology language" then
			return {{name = "Категорија:" .. mw.getContentLanguage():ucfirst(self._source:getCategoryName()), sort = "појмови изведени из"}}
		else
			return {{name = require("Модул:category tree/langcatboiler").new({code = self._info.label}), sort = "термини изведени из"}}
		end
	end
end

function Category:getChildren()
	return nil
end


function Category:getUmbrella()
	if not self._lang then
		return nil
	end
	
	return Category.new({label = self._source:getCode()})
end


return export