Модул:category tree/pbcatboiler
This module implements {{pbcatboiler}}
. 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.
Data modules[уреди]
The information on each label for this template is contained in Module:category tree/pbcatboiler/data.
The following values are recognised in this data module:
parents
- A table listing one or more parent labels of this label.
- An item in the table can be either a single string, or a table containing two elements called
name
andsort
. In the latter case,name
value specifies the parent label name, while thesort
value specifies the sort key to use to sort it in that category. - If a parent label begins with
Category:
it is interpreted as a raw category name, rather than as a label name. It can still have its own sort key as usual.
- An item in the table can be either a single string, or a table containing two elements called
description
- A plain English description for the label.
Special template-like parameters can be used inside the parents
and description
values. These are replaced by the equivalent text.
{{{langname}}}
- The name of the language that the category belongs to.
{{{langcat}}}
- The name of the languages's main category, which adds "language" to the regular name.
Горња документација је укључена са странице Модул:category tree/pbcatboiler/док. (уреди | историја) Уредници могу да експериментишу на подстраницама песак (направи | дуплирај) и тест (направи) овог модула. Подстранице овог модула. |
local export = {}
local labels = require("Module:category tree/pbcatboiler/data")
-- 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 == "code" then
self._info.code = val
self._lang = require("Module:languages").getByCode(val) or error("The language code \"" .. val .. "\" is not valid.")
elseif key == "label" then
self._info.label = val
self._data = labels[self._info.label]
else
error("The parameter \"" .. key .. "\" was not recognized.")
end
end
-- Check if the label exists
if not self._info.label then
error("No label was specified.")
elseif not self._data then
return nil
end
if self._info.label ~= "збирка израза" and not self._lang then
error("Phrasebook subcategories do not have umbrella categories.")
end
return self
end
export.new = Category.new
function Category:getInfo()
return self._info
end
function Category:getBreadcrumbName()
if self._lang then
return self._info.label:gsub(".+/([^/]+)$", "%1")
else
return "збирка израза"
end
end
function Category:getDataModule()
return "Module:category tree/pbcatboiler/data"
end
function Category:canBeEmpty()
return self._data["can_be_empty"]
end
function Category:isHidden()
return self._data["hidden"] and self._info.code
end
function Category:getCategoryName()
if self._lang then
return mw.getContentLanguage():ucfirst(self._lang:getCanonicalName() .. " " .. self._info.label)
else
return "Збирка израза по језику"
end
end
function Category:getDescription()
if self._lang then
local ret = self._data["description"]
if ret then
ret = ret:gsub("{{{langname}}}", self._lang:getCanonicalName())
ret = ret:gsub("{{{langcat}}}", self._lang:getCategoryName())
end
return ret
else
return "Categories with phrasebooks in various specific languages."
end
end
function Category:getParents()
if self._lang then
local parents = self._data["parents"]
if not parents or #parents == 0 then
return nil
end
local ret = {}
for key, parent in ipairs(parents) do
local parent = mw.clone(parent)
if type(parent) ~= "table" then
parent = {name = parent}
end
if not parent.sort then
parent.sort = self._info.label:gsub(".+/([^/]+)$", "%1")
end
parent.sort = parent.sort:gsub("{{{langname}}}", self._lang:getCanonicalName())
parent.sort = parent.sort:gsub("{{{langcat}}}", self._lang:getCategoryName())
if parent.name and parent.name:find("^Category:") then
parent.name = parent.name:gsub("{{{langname}}}", self._lang:getCanonicalName())
parent.name = parent.name:gsub("{{{langcat}}}", self._lang:getCategoryName())
else
local pinfo = mw.clone(self._info)
pinfo.label = parent.name
if parent.template then
parent.name = require("Module:category tree/" .. parent.template).new(pinfo)
else
parent.name = Category.new(pinfo)
end
end
table.insert(ret, parent)
end
return ret
else
return nil
end
end
function Category:getChildren()
return nil
end
function Category:getUmbrella()
if not self._lang or self._info.label ~= "збирка израза" then
return nil
end
local uinfo = mw.clone(self._info)
uinfo.code = nil
return Category.new(uinfo)
end
return export