Module:Category tree/langcatboiler

local export = {}

local function linkbox(lang, setwiki, setsister, entryname) local wiktionarylinks = "None." if #lang:getWikimediaLanguages > 0 then wiktionarylinks = {} for _, wikimedialang in ipairs(lang:getWikimediaLanguages) do			table.insert(wiktionarylinks,				(wikimedialang:getCanonicalName ~= lang:getCanonicalName and "(" .. wikimedialang:getCanonicalName .. ") " or "") ..				"" .. wikimedialang:getCode .. ".wiktionary.org") end wiktionarylinks = table.concat(wiktionarylinks, " ") end return [=[ ''']=] .. lang:getCategoryName .. [=['''

]=] end

function export.country_categories(frame) local categories = {} for i, country in ipairs(frame:getParent.args) do		if i > 1 then table.insert(categories, "") end end if #categories > 0 then return table.concat(categories) else return "" end end

-- 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 = 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 == "entryname" then self._info.entryname = val elseif key == "setsister" then self._info.setsister = val elseif key == "setwiki" then self._info.setwiki = val elseif key == "setwikt" then self._info.setwikt = val else error("The parameter \"" .. key .. "\" was not recognized.") end end if not self._info.code then error("No language code was specified.") end return self end

export.new = Category.new

function Category:getBreadcrumbName return mw.getContentLanguage:ucfirst(self._lang:getCategoryName) end

function Category:getDataModule return "Module:category tree/langcatboiler" end

function Category:canBeEmpty return true end

function Category:isHidden return false end

function Category:getCategoryName return mw.getContentLanguage:ucfirst(self._lang:getCategoryName) end

function Category:getDescription if self._lang:getCode == "und" then return "This is the main category of the '''" .. self._lang:getCategoryName .. ", represented in Wiktionary by the code " .. self._lang:getCode .. "'''. " ..			"This language contains terms in historical writing, whose meaning has not yet been determined by scholars." end local ret = linkbox(self._lang, self._info.setwiki, self._info.setsister, self._info.entryname) ret = ret .. "This is the main category of the '''" .. self._lang:getCategoryName .. "'''.\n\nInformation about " .. self._lang:getCanonicalName .. ":\n\n" ret = ret .. " \n \n" ret = ret .. " \n Language family \n" local fam = self._lang:getFamily if fam:getCode == "qfa-iso" then ret = ret .. " language isolate " elseif fam:getCode == "qfa-mix" then ret = ret .. " mixed language " elseif fam:getCode == "qfa-und" then ret = ret .. " unclassified " elseif fam:getCode == "sgn" then ret = ret .. " sign language " elseif fam:getCode == "crp" then ret = ret .. " creole or pidgin " elseif fam:getCode == "art" then ret = ret .. " constructed language " else ret = ret .. " " .. fam:getCanonicalName .. " " end if #self._lang:getAncestors > 0 then for _, anc in ipairs(self._lang:getAncestors) do ret = ret .. ""		end end ret = ret .. "\n \n \n Ancestors \n" if #self._lang:getAncestors > 1 then local ancestors = {} for _, anc in ipairs(self._lang:getAncestors) do table.insert(ancestors, "" .. anc:getCanonicalName .. "") end ret = ret .. " \n" .. table.concat(ancestors, "\n") .. " \n" elseif #self._lang:getAncestorChain > 0 then ret = ret .. " \n" local chain = {} for _, anc in ipairs(self._lang:getAncestorChain) do table.insert(chain, "" .. anc:getCanonicalName .. "") end ret = ret .. table.concat(chain, "\n\n") for _, _ in ipairs(chain) do ret = ret .. "" end ret = ret .. " \n" else ret = ret .. " unknown \n" end ret = ret .. " \n" if #self._lang:getScripts > 0 then local scripts = {} for _, sc in ipairs(self._lang:getScripts) do local text = "" .. sc:getCanonicalName .. "" if sc:getCode == "Jpan" then local m_scripts = require("Module:scripts") local Hani = m_scripts.getByCode("Hani") local Hira = m_scripts.getByCode("Hira") local Kana = m_scripts.getByCode("Kana") text = text .. "\n\n" .. "" .. Hani:getCanonicalName .. "\n" .. "" .. Hira:getCanonicalName .. "\n" .. "" .. Kana:getCanonicalName .. "</li>\n" .. "</ul>\n" elseif sc:getCode == "Kore" then local m_scripts = require("Module:scripts") local Hang = m_scripts.getByCode("Hang") local Hani = m_scripts.getByCode("Hani") text = text .. "\n\n" .. "" .. Hang:getCanonicalName .. "</li>\n" .. "" .. Hani:getCanonicalName .. "</li>\n" .. "</ul>\n" end text = text .. "</li>" table.insert(scripts, text) end ret = ret .. " \n Scripts \n \n" .. table.concat(scripts, "\n") .. "</ul> \n \n" else ret = ret .. " \n Scripts \n not specified \n \n" end ret = ret .. " "	if self._lang:getType == "reconstructed" then ret = ret .. "\n\n" .. self._lang:getCanonicalName .. " is a reconstructed language. Its words and roots are not directly attested in any written works, but have been reconstructed through the comparative method, " .. "which finds regular similarities between languages that cannot be explained by coincidence or word-borrowing, and extrapolates ancient forms from these similarities.\n\n" .. "According to our criteria for inclusion, terms in " .. self._lang:getCanonicalName .. " should not be present in entries in the main namespace, but may be added to the Reconstruction: namespace." elseif self._lang:getType == "appendix-constructed" then ret = ret .. "\n\n" .. self._lang:getCanonicalName .. " is a constructed language that is only in sporadic use. " .. "According to our criteria for inclusion, terms in " .. self._lang:getCanonicalName .. " should not be present in entries in the main namespace, but may be added to the Appendix: namespace. " .. "All terms in this language may be available at Appendix:" .. self._lang:getCanonicalName .. "." end local about = mw.title.new("Wiktionary:About " .. self._lang:getCanonicalName) if about.exists then ret = ret .. "\n\n" .. "Please see Wiktionary:About " .. self._lang:getCanonicalName .. " for information and special considerations for creating " .. self._lang:getCategoryName .. " entries." end return ret end

function Category:getParents local ret = local fam = self._lang:getFamily if fam:getCode == "qfa-iso" then table.insert(ret, {name = "Category:Language isolates", sort = self._lang:getCanonicalName}) elseif fam:getCode == "qfa-und" or fam:getCode == "qfa-not" then table.insert(ret, {name = "Category:Unclassified languages", sort = self._lang:getCanonicalName}) elseif fam:getCode == "qfa-mix" then table.insert(ret, {name = "Category:Mixed languages", sort = self._lang:getCanonicalName}) elseif fam:getCode == "sgn" then table.insert(ret, {name = "Category:All sign languages", sort = self._lang:getCanonicalName}) elseif fam:getCode == "crp" then table.insert(ret, {name = "Category:Creole or pidgin languages", sort = self._lang:getCanonicalName}) for _, anc in ipairs(self._lang:getAncestors) do table.insert(ret, {name = "Category:" .. anc:getCanonicalName .. "-based creole or pidgin languages", sort = self._lang:getCanonicalName}) end elseif fam:getCode == "art" then if self._lang:getType == "appendix-constructed" then table.insert(ret, {name = "Category:Appendix-only constructed languages", sort = self._lang:getCanonicalName}) else table.insert(ret, {name = "Category:Constructed languages", sort = self._lang:getCanonicalName}) end for _, anc in ipairs(self._lang:getAncestors) do table.insert(ret, {name = "Category:" .. anc:getCanonicalName .. "-based constructed languages", sort = self._lang:getCanonicalName}) end else table.insert(ret, {name = "Category:" .. mw.getContentLanguage:ucfirst(fam:getCategoryName), sort = self._lang:getCanonicalName}) if self._lang:getType == "reconstructed" then table.insert(ret, {name = "Category:Reconstructed languages", sort = (mw.ustring.gsub(self._lang:getCanonicalName, "^Proto%-", ""))}) end end for _, sc in ipairs(self._lang:getScripts) do table.insert(ret, {name = "Category:" .. mw.getContentLanguage:ucfirst(sc:getCategoryName .. " languages"), sort = self._lang:getCanonicalName}) if sc:getCode == "Jpan" then table.insert(ret, {name = "Category:" .. mw.getContentLanguage:ucfirst(require("Module:scripts").getByCode("Hani"):getCategoryName .. " languages"), sort = self._lang:getCanonicalName}) table.insert(ret, {name = "Category:" .. mw.getContentLanguage:ucfirst(require("Module:scripts").getByCode("Hira"):getCategoryName .. " languages"), sort = self._lang:getCanonicalName}) table.insert(ret, {name = "Category:" .. mw.getContentLanguage:ucfirst(require("Module:scripts").getByCode("Kana"):getCategoryName .. " languages"), sort = self._lang:getCanonicalName}) elseif sc:getCode == "Kore" then table.insert(ret, {name = "Category:" .. mw.getContentLanguage:ucfirst(require("Module:scripts").getByCode("Hang"):getCategoryName .. " languages"), sort = self._lang:getCanonicalName}) table.insert(ret, {name = "Category:" .. mw.getContentLanguage:ucfirst(require("Module:scripts").getByCode("Hani"):getCategoryName .. " languages"), sort = self._lang:getCanonicalName}) end end return ret end

function Category:getChildren local ret = {} local m_poscatboiler = require("Module:category tree/poscatboiler") for _, label in ipairs({"appendices", "entry maintenance", "lemmas", "names", "phrases", "rhymes", "symbols", "templates", "terms by etymology", "terms by usage", "transliterations"}) do		local child = m_poscatboiler.new({code = self._lang:getCode, label = label}) local parents = child:getParents if parents then -- Find the current category among the child's parents, to find its sort key for _, parent in ipairs(parents) do if type(parent.name) == "string" and parent.name == "Category:" .. self:getCategoryName then table.insert(ret, {name = child, sort = parent.sort}) break end end end end local m_derivcatboiler = require("Module:category tree/derivcatboiler") local child = m_derivcatboiler.new({code = nil, label = self._lang:getCode}) local sortkey = nil local parents = child:getParents if parents then -- Find the current category among the child's parents, to find its sort key for _, parent in ipairs(parents) do if type(parent.name) == "string" and parent.name == "Category:" .. self:getCategoryName then sortkey = parent.sort break end end end table.insert(ret, {name = child, sort = sortkey}) local m_topic_cat = require("Module:category tree/topic cat") local child = m_topic_cat.new({code = self._lang:getCode, label = "all topics"}) local sortkey = nil local parents = child:getParents if parents then -- Find the current category among the child's parents, to find its sort key for _, parent in ipairs(parents) do if type(parent.name) == "string" and parent.name == "Category:" .. self:getCategoryName then sortkey = parent.sort break end end end table.insert(ret, {name = child, sort = sortkey}) -- FIXME: This is hacky, but it works as a stopgap measure. -- We should fix this when these categories get their own category tree modules. table.insert(ret, {name = {		_lang = self._lang,		getCategoryName = function(self) return "Regional " .. self._lang:getCanonicalName end,		getDescription = function(self) return self._lang:getCanonicalName .. " terms used in specific regions or dialects." end,		}, sort = "regional"}) table.insert(ret, {name = {		_lang = self._lang,		getCategoryName = function(self) return "Requests (" .. self._lang:getCanonicalName .. ")" end,		getDescription = function(self) return self._lang:getCanonicalName .. " entries that need attention of experienced editors." end,		}, sort = "requests"}) table.insert(ret, {name = {		_lang = self._lang,		getCategoryName = function(self) return "User " .. self._lang:getCode end,		getDescription = function(self) return "Wiktionary users categorized by fluency levels in " .. self._lang:getCanonicalName .. "." end,		}, sort = "user"}) return ret end

function Category:getUmbrella return nil end

return export