Modul:dara kategoriyan/zimankatbike

Documentation for this module may be created at Modul:dara kategoriyan/zimankatbike/belge

local export = {}

local function makeCategoryLink(object)
	return "[[:Kategorî:" .. object:getCategoryName() .. "|" .. object:getCanonicalName() .. "]]"
end

local function linkbox(lang, setwiki, setwikt, setsister, entryname)
	local wiktionarylinks = "''Tune.''"
	
	local canonicalName = lang:getCanonicalName()
	local wikimediaLanguages = lang:getWikimediaLanguages()
	local categoryName = lang:getCategoryName()
	local categoryName = mw.ustring.lower( categoryName )
	local wikipediaArticle = setwiki or lang:getWikipediaArticle()

	
	if setwikt then
		require "Module:debug".track "langcatboiler/setwikt"
		if setwikt == "-" then
			require "Module:debug".track "langcatboiler/setwikt/hyphen"
		end
	end
	
	if setwikt ~= "-" and wikimediaLanguages and wikimediaLanguages[1] then
		wiktionarylinks = {}
		
		for _, wikimedialang in ipairs(wikimediaLanguages) do
			table.insert(wiktionarylinks,
				(wikimedialang:getCanonicalName() ~= canonicalName and "(''" .. wikimedialang:getCanonicalName() .. "'') " or "") ..
				"'''[[:" .. wikimedialang:getCode() .. ":|" .. wikimedialang:getCode() .. ".wiktionary.org]]'''")
		end
		
		wiktionarylinks = table.concat(wiktionarylinks, "<br/>")
	end
	
	local plural = wikimediaLanguages[2] and "s" or ""
	
	return table.concat{
[=[<div style="clear: right; border: solid #aaa 1px; margin: 1 1 1 1; background: #f9f9f9; width: 270px; padding: 5px; margin: 5px; text-align: left; float: right">
<div style="text-align: center; margin-bottom: 10px; margin-top: 5px">'''Zimanê ]=], categoryName, [=['''</div>

{| style="font-size: 90%; background: #f9f9f9;"
|-
| style="vertical-align: middle; height: 35px; width: 35px;" | [[File:Wiktionary-logo-v2.svg|35px|none|Wiktionary]]
|| ''Çapa ]=], categoryName, [=[ ya Wîkîferhengê''
|-
| colspan="2" style="padding-left: 10px; border-bottom: 1px solid lightgray;" | ]=], wiktionarylinks, [=[

|-
| style="vertical-align: middle; height: 35px" | [[File:Wikipedia-logo.png|35px|none|Wikipedia]]
|| ''Gotara Wîkîpediyayê ya li ser ]=], categoryName, [=[''
|-
| colspan="2" style="padding-left: 10px; border-bottom: 1px solid lightgray;" | ]=], (setwiki == "-" and "''Tune.''" or "'''[[w:" .. wikipediaArticle .. "|" .. wikipediaArticle .. "]]'''"), [=[

|-
| style="vertical-align: middle; height: 35px" | [[File:Open book nae 02.svg|35px|none|Entry]]
|| Gotara Wîkîferhengê ya li ser ]=], categoryName,[=[

|-
| colspan="2" style="padding-left: 10px;" | ''']=], require("Module:links").full_link({lang = require("Modul:ziman").getByCode("ku"), term = categoryName}), [=['''
|}
</div>]=]
}
end

local function edit_link(title, text)
	return '<span class="plainlinks">['
		.. tostring(mw.uri.fullUrl(title, { action = "edit" }))
		.. ' ' .. text .. ']</span>'
end

-- Should perhaps use wiki syntax.
local function infobox(lang)
	local ret = {}
	
	table.insert(ret, '<table class="wikitable language-category-info"')
	
	if type(lang.getRawData) == "function" then
		local raw_data = lang:getRawData()
		if raw_data then
			local replacements = {
				[1] = "canonical-name",
				[2] = "wikidata-item",
				[3] = "family",
			}
			local function replacer(letter1, letter2)
				return letter1:lower() .. "-" .. letter2:lower()
			end
			-- For each key in the language data modules, returns a descriptive
			-- kebab-case version (containing ASCII lowercase words separated
			-- by hyphens).
			local function kebab_case(key)
				key = replacements[key] or key
				key = key:gsub("(%l)(%u)", replacer):gsub("(%l)_(%l)", replacer)
				return key
			end
			local function html_attribute_encode(str)
				str = mw.text.jsonEncode(str)
					:gsub('"', "&quot;")
					-- & in attributes is automatically escaped.
					-- :gsub("&", "&amp;")
					:gsub("<", "&lt;")
					:gsub(">", "&gt;")
				return str
			end
			pcall(function ()
				table.insert(ret, ' data-code="' .. lang:getCode() .. '"')
				for k, v in require("Module:table").sortedPairs(lang:getRawData()) do
					table.insert(ret, " data-" .. kebab_case(k)
						.. '="'
						.. html_attribute_encode(v)
						.. '"')
				end
			end)
		end
	end
	table.insert(ret, '>\n')
	table.insert(ret, '<tr class="language-category-data">\n<th colspan="2">'
		.. edit_link("Module:" .. require("Modul:ziman").getDataModuleName(lang:getCode()),
			"Daneyên vî zimanî biguherîne")
		.. "</th>\n</tr>\n")
	table.insert(ret, "<tr>\n<th>Navê zimanî</th><td>" .. mw.getContentLanguage():ucfirst(lang:getCanonicalName()) .. "</td>\n</tr>\n")

	local otherNames = lang: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 = lang: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 = lang:getVarieties()
	if varieties then
		local names = {}
		
		for _, name in ipairs(varieties) do
			if type(name) == "string" then
				table.insert(names, "<li>" .. 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>Cureyên wê</th><td><ul>" .. table.concat(names, "\n") .. "</ul></td>\n</tr>\n")
		end
	end

	table.insert(ret, "<tr>\n<th>[[Wîkîferheng:Lîsteya zimanan|Koda zimanî]]</th><td><code>" .. lang:getCode() .. "</code></td>\n</tr>\n")
	table.insert(ret, "<tr>\n<th>[[Modul:families/data|Malbata zimanî]]</th>\n")
	
	local fam = lang:getFamily()
	local famCode = fam and fam:getCode()
	
	if not fam then
		table.insert(ret, "<td>nehatiye sinifandin</td>")
	elseif famCode == "qfa-iso" then
		table.insert(ret, "<td>[[:Kategorî:Zimanên îzole|Zimanekî îzole]]</td>")
	elseif famCode == "qfa-mix" then
		table.insert(ret, "<td>[[:Kategorî:Zimanên têkilkirî|Zimanekî têkilkirî]]</td>")
	elseif famCode == "sgn" then
		table.insert(ret, "<td>[[:Kategorî:Zimanên destan|Zimanê destan]]</td>")
	elseif famCode == "crp" then
		table.insert(ret, "<td>[[:Kategorî:Zimanên kreyolî yan pîdgînî|Kreyolî yan pîdgînî]]</td>")
	elseif famCode == "art" then
		table.insert(ret, "<td>[[:Kategorî:Zimanên çêkirî|Zimanekî çêkirî]]</td>")
	else
		table.insert(ret, "<td>[[:Kategorî:" .. mw.getContentLanguage():ucfirst(fam:getCategoryName()) .. "|" .. mw.getContentLanguage():ucfirst(fam:getCanonicalName()) .. "]]</td>")
	end
	
	table.insert(ret, "\n</tr>\n<tr>\n<th>[[Modul:ziman/danex|Zimanên pêşî]]</th>\n")
	
	local ancestors, ancestorChain = lang:getAncestors(), lang:getAncestorChain()
	if ancestors[2] then
		local ancestorList = {}
		
		for i, anc in ipairs(ancestors) do
			ancestorList[i] = "<li>[[:Kategorî:" .. mw.getContentLanguage():ucfirst(anc:getCategoryName()) .. "|" .. mw.getContentLanguage():ucfirst(anc:getCanonicalName()) .. "]]</li>"
		end
		
		table.insert(ret, "<td><ul>\n" .. table.concat(ancestorList, "\n") .. "</ul></td>\n")
	elseif ancestorChain[1] then
		table.insert(ret, "<td><ul>\n")
		
		local chain = {}
		
		for i, anc in ipairs(ancestorChain) do
			chain[i] = "<li>[[:Kategorî:" .. mw.getContentLanguage():ucfirst(anc:getCategoryName()) .. "|" .. mw.getContentLanguage():ucfirst(anc:getCanonicalName()) .. "]]</li>"
		end
		
		table.insert(ret, table.concat(chain, "\n<ul>\n"))
		
		for _, _ in ipairs(chain) do
			table.insert(ret, "</ul>")
		end
		
		table.insert(ret, "</td>\n")
	else
		table.insert(ret, "<td>Nayê zanîn</td>\n")
	end
	
	table.insert(ret, "</tr>\n")
	

	
	if lang._rawData.translit_module then
		local translit_module = lang._rawData.translit_module
		local translit_module_info = {}
		table.insert(translit_module_info,
			("[[Module:%s]]"):format(translit_module))
		
		if translit_module == "translit-redirect" then
			local data = mw.loadData("Module:translit-redirect/data")[lang:getCode()]
			if data then
				table.insert(translit_module_info, ":")
				local redirects_to = {}
				local m_scripts = require "Module:scripts"
				for script, data in require "Module:table".sortedPairs(data) do
					-- Skip boolean fields like "debug_mode" and "noError".
					if type(data) == "table" then
						table.insert(redirects_to,
							("\n* <code>%s</code>: %s"):format(
								script,
								data.module and ("[[Module:%s]]"):format(data.module)
									or "(Tune)"))
					end
				end
				table.insert(translit_module_info, table.concat(redirects_to))
			end
		end
		
		table.insert(ret, [=[
<tr>
<th>Modulên<br>transliterayonê</th>
<td>]=] .. table.concat(translit_module_info) .. [=[</td>
</tr>
]=])
end
	local wikidataItem = lang:getWikidataItem()
	if lang:getWikidataItem() and mw.wikibase then
		local URL = mw.wikibase.getEntityUrl(wikidataItem)
		local link
		if URL then
			link = '[' .. URL .. ' ' .. wikidataItem .. ']'
		else
			link = '<span class="error">Invalid Wikidata item: <code>' .. wikidataItem .. '</code></span>'
		end
		table.insert(ret, "<tr><th>Wîkîdane</th><td>" .. link .. "</td></tr>")
	end
	
	table.insert(ret, "</table>")
	
	return table.concat(ret)
end

local function NavFrame(content, title)
	return '<div class="NavFrame"><div class="NavHead">'
		.. (title or '{{{title}}}') .. '</div>'
		.. '<div class="NavContent" style="text-align: left;">'
		.. content
		.. '</div></div>'
end

function export.country_categories(frame)

end


-- Category object

local Category = {}
Category.__index = Category


function Category.new(info)
	for key, val in pairs(info) do
		if not (key == "code" or key == "entryname" or key == "setsister" or key == "setwiki" or key == "setwikt") then
			error("The parameter \"" .. key .. "\" was not recognized.")
		end
	end
	
	local self = setmetatable({}, Category)
	self._info = info
	
	if not self._info.code then
		error("Koda zimanî nehatiye nivîsîn.")
	else
		self._lang = require("Modul:ziman").getByCode(self._info.code) or error("Koda zimanî \"" .. self._info.code .. "\" ne guncav e.")
	end
	
	return self
end

export.new = Category.new


function Category:getInfo()
	return self._info
end

function Category:getBreadcrumbName()
	return self._lang:getCanonicalName()
end


function Category:getDataModule()
	return "Modul:dara kategoriyan/zimankatbike"
end


function Category:canBeEmpty()
	return false
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
			"Kategoriya sereke ya '''" .. self._lang:getCategoryName() .. "''', represented in Wiktionary by the [[Wiktionary:Languages|code]] '''" .. self._lang:getCode() .. "'''. " ..
			"This language contains terms in historical writing, whose meaning has not yet been determined by scholars."
	end
	
	local canonicalName = self._lang:getCanonicalName()
	
	local ret = linkbox(self._lang, self._info.setwiki, self._info.setwikt, self._info.setsister, self._info.entryname)
	
	ret = ret .. "Ev ji bo zimanê '''" .. mw.ustring.lower(self._lang:getCategoryName()) .. "''' kategoriya sereke ye.\n\nDanasîna zimanî:\n\n" .. infobox(self._lang)
	
	if self._lang:getType() == "reconstructed" then
		ret = ret .. "\n\n" ..
			mw.getContentLanguage():ucfirst(canonicalName) .. " zimanekî ji nû ve sazkirî ye. Lewra peyvên di vê rûpelê de yekser nehatine peyitandin." ..
			" Lê belê li gorî rêbaza berawirdkirinê piştraskirî ne û tên bawerkirin ku di wextekî de hebûn.\n\n" ..
			"Peyvên bi zimanê " .. canonicalName ..
			" nabe ku cihê xwe valahiya nav ya sereke de bigrin, van peyvan divê bi [[Wîkîferheng:Jinûvesazî|'''Jinûvesazî:''']] dest pê bikin."
	elseif self._lang:getType() == "appendix-constructed" then
		ret = ret .. "\n\n" ..
			canonicalName .. " is a constructed language that is only in sporadic use. " ..
			"According to our [[Wiktionary:Criteria for inclusion|criteria for inclusion]], terms in " .. canonicalName ..
			" 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:" .. canonicalName .. "]]."
	end
	
	ret = ret .. " __EXPECTUNUSEDCATEGORY__" -- it's OK if this category is empty
	return ret
end


function Category:getParents()
	local canonicalName = self._lang:getCanonicalName()
	
	local ret = {{name = "Kategorî:Hemû ziman", sort = canonicalName}}
	
	local fam = self._lang:getFamily()
	local famCode = fam and fam:getCode()
	
	if not fam then
		table.insert(ret, {name = "Kategorî:Zimanên ku nehatine sinifandin", sort = canonicalName})
	elseif famCode == "qfa-iso" then
		table.insert(ret, {name = "Kategorî:Zimanên îzole", sort = canonicalName})
	elseif famCode == "qfa-mix" then
		table.insert(ret, {name = "Kategorî:Zimanên têkilkirî", sort = canonicalName})
	elseif famCode == "sgn" then
		table.insert(ret, {name = "Kategorî:Zimanên destan", sort = canonicalName})
	elseif famCode == "crp" then
		table.insert(ret, {name = "Kategorî:Zimanên kreyolî yan pîdgînî", sort = canonicalName})
		
		for _, anc in ipairs(self._lang:getAncestors()) do
			table.insert(ret, {name = "Kategorî:Zimanên kreyolî yan pîdgînî li ser bingeha " .. anc:getCanonicalName(), sort = canonicalName})
		end
	elseif famCode == "art" then
		if self._lang:getType() == "appendix-constructed" then
			table.insert(ret, {name = "Kategorî:Zimanên çêkirî di nimînokan de", sort = canonicalName})
		else
			table.insert(ret, {name = "Kategorî:Zimanên çêkirî", sort = canonicalName})
		end
		
		for _, anc in ipairs(self._lang:getAncestors()) do
			table.insert(ret, {name = "Kategorî:Li ser bingeha " .. anc:getCanonicalName() .. " zimanên çêkirî", sort = canonicalName})
		end
	else
		table.insert(ret, {name = "Kategorî:" .. mw.getContentLanguage():ucfirst(fam:getCategoryName()), sort = canonicalName})
		
		if self._lang:getType() == "reconstructed" then
			table.insert(ret, {name = "Kategorî:Zimanên jinûvesazkirî", sort = (mw.ustring.gsub(canonicalName, "^Proto%-", ""))})
		end
	end
	
	if self._lang:hasTranslit() then
		table.insert(ret, {name = "Kategorî:Zimanên bi transliterasyona xweser", sort = canonicalName})
	end
	
	return ret
end


function Category:getUmbrella()
	return nil
end


return export