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 == "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
else
error("The parameter \"" .. key .. "\" was not recognized.")
end
end
if not self._info.label then
error("No label was specified.")
end
-- Check if the label exists
if self._info.label ~= "ROOT" then
self._source = require("Module:languages").getByCode(self._info.label) or error("The language code \"" .. self._info.label .. "\" is not valid.")
end
return self
end
export.new = Category.new
function Category:getInfo()
return self._info
end
function Category:getBreadcrumbName()
if self._source then
if self._lang then
return self._source:getCanonicalName()
else
return "Terms transliterated from " .. self._source:getCanonicalName()
end
else
if self._lang then
return "Transliterated terms"
else
return "Terms transliterated from other languages"
end
end
end
function Category:getDataModule()
return "Module:category tree/translit cat"
end
function Category:getCategoryName()
local ret = nil
if self._source then
ret = "transliterations of " .. self._source:getCanonicalName() .. " terms"
else
ret = "terms transliterated from other languages"
end
if self._lang then
return mw.getContentLanguage():ucfirst(self._lang:getCanonicalName() .. " " .. ret)
else
return mw.getContentLanguage():ucfirst(ret)
end
end
function Category:getDescription()
local ret
if self._lang then
if self._source then
ret = "the [[:Category:" .. mw.getContentLanguage():ucfirst(self._source:getCategoryName()) .. "|" .. self._source:getCategoryName() .. "]]"
else
ret = "other languages"
end
return "Terms in " .. self._lang:getCanonicalName() .. " that have been transliterated from " .. ret .. "."
else
if self._source then
ret = "transliterations of " .. self._source:getCanonicalName() .. " terms"
else
ret = "terms transliterated from other languages"
end
return "Categories with " .. ret .. " in various specific languages."
end
end
function Category:getParents()
if self._lang then
if self._source then
local pinfo = mw.clone(self._info)
pinfo.label = "ROOT"
return {
{name = Category.new(pinfo), sort = self._source:getCanonicalName()},
{name = require("Module:category tree/borrowed cat").new({code = self._info.code, label = self._source:getCode()}), sort = " "},
}
else
return {
{name = require("Module:category tree/poscatboiler").new({code = self._info.code, label = "borrowed terms"}), sort = " "},
}
end
else
if self._source then
return {{name = require("Module:category tree/borrowed cat").new({label = self._source:getCode()}), sort = " "}}
else
return {{name = "Category:Terms by etymology subcategories by language", sort = "terms transliterated from other languages"}}
end
end
end
function Category:getChildren()
return nil
end
function Category:canBeEmpty()
return false
end
function Category:isHidden()
return false
end
function Category:getUmbrella()
if not self._lang then
return nil
end
local uinfo = mw.clone(self._info)
uinfo.code = nil
return Category.new(uinfo)
end
return export