Modul:category tree/affix cat

This module implements {{circumfixcat}}, {{infixcat}}, {{interfixcat}}, {{prefixcat}} and {{suffixcat}}. The documentation here describes how the module works, and how to add, modify or remove information from the category tree. For information on how to use the template itself, see its documentation.

This module does not use labels. Effectively, there is only one label, whose data is hard-coded into the module.

Dissen Vörlaag hef dokumentatsie neudig.
Maak de dokumentatsie veur dissen modul ovver t doel en gebroek op de dokumentatsieziede.

local m_links = require("Module:links")
local m_compound = require("Module:compound")
 
local export = {}
 
-- Category object
 
local Category = {}
Category.__index = Category
 
 
function Category.new(info)
	local self = setmetatable({}, Category)
	assert(type(info) == "table", "The \"info\" parameter must be a table.")
	self._info = {}
 
	for key, val in pairs(info) do
		if key == "affixtype" then
			self._info.affixtype = val
		elseif key == "alt" then
			self._info.alt = val
			self._alt = val
		elseif key == "code" then
			self._info.code = val
			self._lang = require("Module:languages").getByCode(val) or error("The language code \"" .. val .. "\" is not valid.")
		elseif key == "pos" then
			self._info.pos = val
		elseif key == "sc" then
			self._info.sc = val
			self._sc = require("Module:scripts").getByCode(val) or error("The script code \"" .. val .. "\" is not valid.")
		elseif key == "sort" then
			self._info.sort = val
		elseif key == "term" then
			self._info.term = val
			self._term = val
		elseif key == "tr" then
			self._info.tr = val
			self._tr = val
		else
			error("The parameter \"" .. key .. "\" was not recognized.")
		end
	end
 
	if not self._lang then
		error("No language code was specified.")
	end
 
	if not self._term then
		error("No term was specified.")
	end
 
	-- Convert term/alt into affixes if needed
	if self._info.affixtype == "Präfix" then
		self._desc = "dee't begint met de prefix"
	elseif self._info.affixtype == "suffix" then
		self._desc = "dee't endigt met de suffix"
	elseif self._info.affixtype == "circumfix" then
		self._desc = "bookended with the circumfix"
	elseif self._info.affixtype == "infix" then
		self._desc = "spliced with the infix"
	elseif self._info.affixtype == "interfix" then
		self._desc = "joined with the interfix"
	else
		error("Invalid affixtype specified.")
	end
 
	self._term = m_compound.make_affix(self._term, self._lang, self._sc, self._info.affixtype)
	self._alt = m_compound.make_affix(self._alt, self._lang, self._sc, self._info.affixtype)
	self._tr = m_compound.make_affix(self._tr, self._lang, self._sc, self._info.affixtype)
 
	self._pos = self._info.pos or "Wöör"
 
	return self
end
 
export.new = Category.new
 
 
function Category:getBreadcrumbName()
	local link = m_links.full_link(nil, self._alt or self._term, self._lang, self._sc, "term", nil, {tr = "-"}, false)
	return self._pos .. " mit " .. self._info.affixtype .. " " .. link
end
 
 
function Category:getDataModule()
	return "Module:category tree/affix cat"
end
 
 
function Category:canBeEmpty()
	return false
end
 
 
function Category:getCategoryName()
	return self._lang:getCanonicalName() .. " " .. self._pos .. " mit " .. mw.getContentLanguage():ucfirst(self._info.affixtype) .. " " ..self._lang:makeEntryName(self._term)
end
 
 
function Category:getDescription()
	local description =
		self._lang:getCanonicalName() .. " " .. self._pos .. " " .. self._desc .. " " ..
		m_links.full_link(self._term, self._alt, self._lang, self._sc, "term", nil, {tr = self._tr}, false) ..
		"."
 
	local displaytitle =
		"Kategorie:" .. self._lang:getCanonicalName() .. " " .. self._pos .. " mit " .. self._info.affixtype .. " " ..
		m_links.full_link(nil, self._alt or self._term, self._lang, self._sc, "term", nil, {tr = "-"}, false)
 
	return mw.getCurrentFrame():callParserFunction("DISPLAYTITLE", displaytitle) .. description
end
 
 
function Category:getParents()
	return {{name = "Kategorie:" .. self._lang:getCanonicalName() .. " Wöör bi " .. self._info.affixtype, sort = self._lang:makeSortKey(self._info.sort or self._term)}}
end
 
 
function Category:getChildren()
	return nil
end
 
 
function Category:getUmbrella()
	return nil
end
 
 function Category:getBild()
   return nil
end

return export