Modul:category tree/topic name cat
A modult a Modul:category tree/topic name cat/doc lapon tudod dokumentálni
local export = {}
-- Category object
local Category = {}
Category.__index = Category
function Category.new_main(frame)
local params = {
[1] = {required = true},
[2] = {required = true},
[3] = {required = true},
}
args = require("Module:parameters").process(frame:getParent().args, params)
return Category.new({lang = args[1], source = args[2], nametype = args[3]})
end
function Category.new(info)
for key, val in pairs(info) do
if not (key == "nametype" or key == "lang" or key == "source") then
error("The parameter \"" .. key .. "\" was not recognized. "
.."Recognized parameters are \"nametype\", \"lang\", and \"source\".")
end
end
if not info.nametype then
error("No name type was specified.")
end
if not info.lang then
error("No current language code was specified.")
end
if not info.source then
error("No source was specified.")
end
local self = setmetatable({}, Category)
self._info = info
self._lang = type(info.lang) == "table" and info.lang.getCode and info.lang
or require("Module:languages").getByCode(info.lang, true)
self._source = type(info.source) == "table" and info.source.getCode and info.source
or require("Module:languages").getByCode(info.source, true, "allow etym")
return self
end
export.new = Category.new
export.new_main = Category.new_main
function Category:getInfo()
return self._info
end
function Category:getBreadcrumbName()
return "from " .. self._source:getCanonicalName()
end
function Category:getDataModule()
return "Module:category tree/topic name cat"
end
function Category:canBeEmpty()
return false
end
function Category:isHidden()
return false
end
function Category:getCategoryName()
return self._lang:getCode() .. ":" .. self._source:getCanonicalName() .. " " .. self._info.nametype
end
local function linkLanguage(lang)
return "[[:Category:" .. mw.getContentLanguage():ucfirst(lang:getCategoryName()) .. "|" .. lang:getCanonicalName() .. "]]"
end
function Category:getDescription()
return "Transliterations of " .. linkLanguage(self._source) .. " " .. self._info.nametype .. " into " .. linkLanguage(self._lang) .. "."
end
function Category:getParents()
local categories = {}
table.insert(categories,
{name = require("Module:category tree/topic cat").new{code = self._info.lang, label = "Transliteration of personal names"},
sort = self._source:getCanonicalName()})
table.insert(categories,
{name = require("Module:category tree/poscatboiler").new{code = self._source:getCode(), label = self._info.nametype},
sort = self._lang:getCanonicalName()})
return categories
end
function Category:getChildren()
return nil
end
function Category:getUmbrella()
return nil
end
return export
-- For Vim, so we get 4-space tabs
-- vim: set ts=4 sw=4 noet: