Modul:dara kategoriyan/malbatkatbike
Documentation for this module may be created at Modul:dara kategoriyan/malbatkatbike/belge
local export = {}
-- Category object
local Category = {}
Category.__index = Category
local function infobox(fam)
local ret = {}
table.insert(ret, "<table class=\"wikitable\">\n")
table.insert(ret, "<tr>\n<th colspan=\"2\" class=\"plainlinks\">[//ku.wiktionary.org/w/index.php?title=Modul:families/data&action=edit Daneya malbatî biguherîne]</th>\n</tr>\n")
table.insert(ret, "<tr>\n<th>Navê malbatî</th><td>" .. mw.getContentLanguage():ucfirst(fam:getCanonicalName()) .. "</td>\n</tr>\n")
local otherNames = fam:getOtherNames(true)
if otherNames then
local names = {}
for _, name in ipairs(otherNames) do
table.insert(names, "<li>" .. mw.getContentLanguage():ucfirst(name) .. "</li>")
end
if #names > 0 then
table.insert(ret, "<tr>\n<th>Navên din</th><td><ul>" .. table.concat(names, "\n") .. "</ul></td>\n</tr>\n")
end
end
local aliases = fam:getAliases()
if aliases then
local names = {}
for _, name in ipairs(aliases) do
table.insert(names, "<li>" .. mw.getContentLanguage():ucfirst(name) .. "</li>")
end
if #names > 0 then
table.insert(ret, "<tr>\n<th>Bernav</th><td><ul>" .. table.concat(names, "\n") .. "</ul></td>\n</tr>\n")
end
end
local varieties = fam:getVarieties()
if varieties then
local names = {}
for _, name in ipairs(varieties) do
if type(name) == "string" then
table.insert(names, "<li>" .. mw.getContentLanguage():ucfirst(name) .. "</li>")
else
assert(type(name) == "table")
local first_var
local subvars = {}
for i, var in ipairs(name) do
if i == 1 then
first_var = var
else
table.insert(subvars, "<li>" .. var .. "</li>")
end
end
if #subvars > 0 then
table.insert(names, "<li><dl><dt>" .. first_var .. "</dt>\n<dd><ul>" .. table.concat(subvars, "\n") .. "</ul></dd></dl></li>")
elseif first_var then
table.insert(names, "<li>" .. first_var .. "</li>")
end
end
end
if #names > 0 then
table.insert(ret, "<tr>\n<th>Guhertoyên wê</th><td><ul>" .. table.concat(names, "\n") .. "</ul></td>\n</tr>\n")
end
end
table.insert(ret, "<tr>\n<th>[[Modul:families/data|Koda malbatî]]</th><td><code>" .. fam:getCode() .. "</code></td>\n</tr>\n")
table.insert(ret, "<tr>\n<th>[[w:Proto-ziman|Zimanê pêşî]]</th><td>")
local protoLanguage = fam:getProtoLanguage()
if protoLanguage then
table.insert(ret, "[[:Kategorî:" .. mw.getContentLanguage():ucfirst(protoLanguage:getCategoryName()) .. "|" .. mw.getContentLanguage():ucfirst(protoLanguage:getCanonicalName()) .. "]]")
else
table.insert(ret, "tine")
end
table.insert(ret, "</td>\n")
table.insert(ret, "\n</tr>\n")
local parent = fam:getFamily()
if not parent then
table.insert(ret, "<tr>\n<th>[[Modul:families/data|Malbatên jor]]</th>\n<td>")
table.insert(ret, "nehatiye sinifandin")
elseif parent:getCode() == "qfa-not" then
table.insert(ret, "<tr>\n<th>[[Modul:families/data|Malbatên jor]]</th>\n<td>")
table.insert(ret, "ne malbatekî ye")
else
local chain = {}
while parent do
table.insert(chain, "[[:Kategorî:" .. mw.ustring.gsub(parent:getCategoryName(), "^.", mw.ustring.upper) .. "|" .. mw.getContentLanguage():ucfirst(parent:getCanonicalName()) .. "]]")
parent = parent:getFamily()
end
table.insert(ret, "<tr>\n<th>[[Modul:families/data|Malbat"
.. (#chain == 1 and "a" or "ên") .. " jor]]</th>\n<td>")
for i = #chain, 1, -1 do
table.insert(ret, "<ul><li>" .. chain[i])
end
table.insert(ret, string.rep("</li></ul>", #chain))
end
table.insert(ret, "</td>\n</tr>\n")
if fam:getWikidataItem() and mw.wikibase then
local link = '[' .. mw.wikibase.getEntityUrl(fam:getWikidataItem()) .. ' ' .. fam:getWikidataItem() .. ']'
table.insert(ret, "<tr><th>Wîkîdane</th><td>" .. link .. "</td></tr>")
end
table.insert(ret, "</table>")
return table.concat(ret)
end
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._fam = require("Module:families").getByCode(val) or error("The family code \"" .. val .. "\" is not valid.")
else
error("The parameter \"" .. key .. "\" was not recognized.")
end
end
return self
end
export.new = Category.new
function Category:getInfo()
return self._info
end
function Category:getBreadcrumbName()
if not self._fam then
return "ziman li gorî malbatan"
else
return self._fam:getCanonicalName()
end
end
function Category:getDataModule()
return "Modul:dara kategoriyan/malbatkatbike"
end
function Category:canBeEmpty()
return true
end
function Category:isHidden()
return false
end
function Category:getCategoryName()
local ret = nil
if not self._fam then
ret = "ziman li gorî malbatan"
else
ret = self._fam:getCategoryName()
end
return mw.getContentLanguage():ucfirst(ret)
end
local function NavFrame(content, title)
return '<div class="NavFrame" title="collapsed"><div class="NavHead">'
.. (title or '{{{title}}}') .. '</div>'
.. '<div class="NavContent" style="text-align: left;">'
.. content
.. '</div></div>'
end
function Category:getDescription()
if not self._fam then
return nil
else
local ok, tree_of_descendants = pcall(
require("Module:family tree").print_children,
self._fam:getCode(), {
protolanguage_under_family = true,
must_have_descendants = true
})
if ok then
if tree_of_descendants then
ret = "Ev ji bo '''" .. mw.getContentLanguage():lc(self._fam:getCategoryName()) ..
"''' kategoriya sereke ye.\n\nDanasîna malbatê:\n\n" ..
infobox(self._fam) .. " __EXPECTUNUSEDCATEGORY__" .. -- it's OK if this category is empty
NavFrame(
tree_of_descendants,
"Dara malbatî")
end
else
ret = "Ev ji bo '''" .. mw.getContentLanguage():lc(self._fam:getCategoryName()) ..
"''' kategoriya sereke ye.\n\nDanasîna malbatê:\n\n" ..
infobox(self._fam) .. " __EXPECTUNUSEDCATEGORY__" -- it's OK if this category is empty
end
return ret
end
end
function Category:getParents()
if not self._fam then
return {
{
name = "Kategorî:Hemû ziman",
sort = " "
},
{
name = "Kategorî:Malbatên zimanan",
sort = " "
},
}
else
local pinfo = mw.clone(self._info)
local fam = self._fam:getFamily()
if not fam or fam:getCode() == "qfa-iso" or fam:getCode() == "qfa-not" then
pinfo.code = nil
else
pinfo.code = fam:getCode()
end
return {{name = Category.new(pinfo), sort = self._fam:getCanonicalName()}}
end
end
function Category:getChildren()
return nil
end
function Category:getUmbrella()
return "Kategorî:Malbatên zimanan"
end
return export