local export = {}
local labels = require("Module:category tree/poscatboiler/data")
-- Category object
local Category = {}
Category.__index = Category
local valid_parameters = {
code = true,
label = true,
sc = true,
}
function Category.new(info)
local self = setmetatable({}, Category)
assert(type(info) == "table", "Den \"info\" parameter mot ne tabel waen.")
self._info = {}
for key, val in pairs(info) do
if not valid_parameters[key] then
return nil
end
self._info[key] = val
end
assert(self._info.label and type(self._info.label) == "string", "De \"info\" tabel mot ne \"label\"-stringweerde hebben.")
-- Umbrella categories cannot have a script
if self._info.sc and not self._info.code then
return nil
end
-- Check if the label exists
if labels[self._info.label] then
self._data = labels[self._info.label]
return self
else
return nil
end
end
export.new = Category.new
function Category:getBreadcrumbName()
local ret = self._info.label
if self._info.sc then
local sc = require("Module:scripts").getByCode(self._info.sc)
ret = ret .. " in " .. sc:getCategoryName()
end
return ret
end
function Category:getDataModule()
return self._data["edit"]
end
function Category:getCategoryName()
if self._info.code then
local lang = require("Module:languages").getByCode(self._info.code)
local ret = lang:getCanonicalName() .. " " .. self._info.label
if self._info.sc then
local sc = require("Module:scripts").getByCode(self._info.sc)
ret = ret .. " in " .. sc:getCategoryName()
end
return mw.getContentLanguage():ucfirst(ret)
else
return mw.getContentLanguage():ucfirst(self._info.label .. " bi Spraak")
end
end
function Category:getDescription()
if self._info.code then
if self._info.sc then
return self:getCategoryName() .. "."
else
local lang = require("Module:languages").getByCode(self._info.code)
local ret = self._data["description"]
if ret then
ret = ret:gsub("{{{langname}}}", lang:getCanonicalName())
ret = ret:gsub("{{{langcat}}}", lang:getCategoryName())
end
return ret
end
else
return "Kategorieën met " .. self._info.label .. " in verscheidene spesifieke spraoken."
end
end
function Category:getParents()
if self._info.code then
if self._info.sc then
local pinfo = mw.clone(self._info)
pinfo.sc = nil
local parent = Category.new(pinfo)
return {{name = parent, sort = require("Module:scripts").getByCode(self._info.sc):getCanonicalName()}}
else
local lang = require("Module:languages").getByCode(self._info.code)
local parents = self._data["parents"]
if not parents or #parents == 0 then
return nil
end
local ret = {}
for _, parent in ipairs(parents) do
local parent = mw.clone(parent)
if type(parent) == "table" then
parent.sort = parent.sort:gsub("{{{langname}}}", lang:getCanonicalName())
parent.sort = parent.sort:gsub("{{{langcat}}}", lang:getCategoryName())
else
parent = {name = parent, sort = self._info.label}
end
if parent.name:find("^Kategorie:") then
parent.name = parent.name:gsub("{{{langname}}}", lang:getCanonicalName())
parent.name = parent.name:gsub("{{{langcat}}}", lang:getCategoryName())
else
local pinfo = mw.clone(self._info)
pinfo.label = parent.name
parent.name = Category.new(pinfo)
end
table.insert(ret, parent)
end
return ret
end
else
if self._data["fundamental"] then
return {{name = "Kategorie:" .. self._data["fundamental"], sort = self._data["sortparentumbrella"] or self._info.label}}
else
return nil
end
end
end
function Category:getChildren()
local children = self._data["children"]
if not self._info.code or not children or #children == 0 then
return nil
end
local ret = {}
for _, child in ipairs(children) do
child = mw.clone(child)
if type(child) ~= "table" then
child = {name = child, sort = child}
end
local cinfo = mw.clone(self._info)
cinfo.label = child.name
child.name = Category.new(cinfo)
table.insert(ret, child)
end
return ret
end
function Category:getUmbrella()
if not self._info.code then
return nil
end
local uinfo = mw.clone(self._info)
uinfo.code = nil
return Category.new(uinfo)
end
function Category:getBild()
return nil
end
return export