وحدة:category tree/langcatboiler
المظهر
يمكن إنشاء صفحة توثيق الوحدة في وحدة: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() .. ":|" .. wikimedialang:getCode() .. ".wiktionary.org]]'''")
end
wiktionarylinks = table.concat(wiktionarylinks, "<br/>")
end
return [=[<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">''']=] .. lang:getCategoryName() .. [=['''</div>
{| style="font-size: 90%; background: #f9f9f9"
|-
| style="vertical-align: Middle; height: 35px" width="35px" | [[ملف:Wiktionary-logo-en.svg|35px|none|Wiktionary]]
|| '']=] .. lang:getCategoryName() .. [=[ edition]=] .. (#lang:getWikimediaLanguages() > 1 and "s" or "") .. [=[ of Wiktionary''
|-
| colspan="2" style="padding-left:10px" | ]=] ..
wiktionarylinks .. [=[
|-
| style="vertical-align: Middle; height: 35px" | [[ملف:Wikipedia-logo.svg|35px|none|Wikipedia]]
|| ''Wikipedia article about ]=] .. lang:getCategoryName() .. [=[''
|-
| colspan="2" style="padding-left:10px" | ]=] .. (setwiki == "-" and "''None.''" or "'''[[w:" .. (setwiki or lang:getCategoryName()) .. "|" .. (setwiki or lang:getCategoryName()) .. "]]'''") .. [=[
|-
| style="vertical-align: Middle; height: 35px" | [[ملف:Wikimedia-logo.svg|35px|none|Wikimedia Commons]]
|| ''Links related to ]=] .. lang:getCategoryName() .. [=[ in sister projects at Wikimedia Commons''
|-
| colspan="2" style="padding-left:10px" | ]=] .. (setsister == "-" and "''None.''" or "'''[[commons:Category:" .. (setsister or lang:getCategoryName()) .. "|" .. (setsister or lang:getCategoryName()) .. "]]'''") .. [=[
|-
| style="vertical-align: Middle; height: 35px" | [[ملف:Crystal kfind.png|35px|none|Considerations]]
|| ]=] .. lang:getCategoryName() .. [=[ considerations
|-
| colspan="2" style="padding-left:10px" | '''[[Wiktionary:About ]=] .. lang:getCanonicalName() .. [=[]]'''
|-
| style="vertical-align: Middle; height: 35px" | [[ملف:Incomplete list.svg|35px|none|Index]]
|| ]=] .. lang:getCategoryName() .. [=[ index
|-
| colspan="2" style="padding-left:10px" | '''[[Index:]=] .. lang:getCanonicalName() .. [=[]]'''
|-
| style="vertical-align: Middle; height: 35px" | [[ملف:Open book nae 02.svg|35px|none|Entry]]
|| ]=] .. lang:getCategoryName() .. [=[ entry
|-
| colspan="2" style="padding-left:10px" | ''']=] .. require("Module:links").full_link(entryname or lang:getCanonicalName(), nil, require("Module:languages").getByCode("en"), nil, nil, nil, {}, false) .. [=['''
|}
</div>]=]
end
function export.country_categories(frame)
local categories = {}
for i, country in ipairs(frame:getParent().args) do
if i > 1 then
table.insert(categories, "[[تصنيف:لغات ال" .. country .. "]]")
end
end
if #categories > 0 then
return table.concat(categories)
else
return "[[تصنيف:Languages not sorted into a country category]]"
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: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 [[Wiktionary:Languages|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 .. "<table class=\"wikitable\">\n"
ret = ret .. "<tr>\n<th>Canonical name</th><td>" .. self._lang:getCanonicalName() .. "</td>\n</tr>\n"
if #self._lang:getOtherNames() > 0 then
local names = {}
for _, name in ipairs(self._lang:getOtherNames()) do
table.insert(names, "<li>" .. name .. "</li>")
end
ret = ret .. "<tr>\n<th>Other names</th><td>" .. table.concat(names, "\n") .. "</td>\n</tr>\n"
end
ret = ret .. "<tr>\n<th>[[Wiktionary:Languages|Language code]]</th><td><code>" .. self._lang:getCode() .. "</code></td>\n</tr>\n"
ret = ret .. "<tr>\n<th>[[Wiktionary:Families|Language family]]</th>\n"
local fam = self._lang:getFamily()
if fam:getCode() == "qfa-iso" then
ret = ret .. "<td>[[:Category:لغات معزولة|لغة معزولة]]</td>"
elseif fam:getCode() == "qfa-mix" then
ret = ret .. "<td>[[:Category:اللغات المختلطة|اللغة المختلطة]]</td>"
elseif fam:getCode() == "qfa-und" then
ret = ret .. "<td>unclassified</td>"
elseif fam:getCode() == "sgn" then
ret = ret .. "<td>[[:Category:لغات إشارة|لغة إشارة]]</td>"
elseif fam:getCode() == "crp" then
ret = ret .. "<td>[[:Category:لغات بدجنية أو كريل|لغة بدجنية أو كريل]]</td>"
elseif fam:getCode() == "art" then
ret = ret .. "<td>[[:Category:لغات مصطنعة|لغة مصطنعة]]</td>"
else
ret = ret .. "<td>[[:Category:" .. fam:getCategoryName() .. "|" .. fam:getCanonicalName() .. "]]</td>"
end
if #self._lang:getAncestors() > 0 then
for _, anc in ipairs(self._lang:getAncestors()) do
ret = ret .. "[[تصنيف:" .. anc:getCategoryName() .. "]]"
end
end
if #self._lang:getAncestors() > 0 then
for _, anc in ipairs(self._lang:getAncestors()) do
ret = ret .. "[[تصنيف:" .. anc:getCategoryName() .. "]]"
end
end
ret = ret .. "\n</tr>\n<tr>\n<th>Ancestors</th>\n"
if #self._lang:getAncestors() > 1 then
local ancestors = {}
for _, anc in ipairs(self._lang:getAncestors()) do
table.insert(ancestors, "<li>[[:Category:" .. anc:getCategoryName() .. "|" .. anc:getCanonicalName() .. "]]</li>")
end
ret = ret .. "<td><ul>\n" .. table.concat(ancestors, "\n") .. "</ul></td>\n"
elseif #self._lang:getAncestorChain() > 0 then
ret = ret .. "<td><ul>\n"
local chain = {}
for _, anc in ipairs(self._lang:getAncestorChain()) do
table.insert(chain, "<li>[[:Category:" .. anc:getCategoryName() .. "|" .. anc:getCanonicalName() .. "]]</li>")
end
ret = ret .. table.concat(chain, "\n<ul>\n")
for _, _ in ipairs(chain) do
ret = ret .. "</ul>"
end
ret = ret .. "</td>\n"
else
ret = ret .. "<td>unknown</td>\n"
end
ret = ret .. "</tr>\n"
if #self._lang:getScripts() > 0 then
local scripts = {}
for _, sc in ipairs(self._lang:getScripts()) do
local text = "<li>[[:Category:" .. sc:getCategoryName() .. "|" .. 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<ul>\n" ..
"<li>[[:Category:" .. Hani:getCategoryName() .. "|" .. Hani:getCanonicalName() .. "]]</li>\n" ..
"<li>[[:Category:" .. Hira:getCategoryName() .. "|" .. Hira:getCanonicalName() .. "]]</li>\n" ..
"<li>[[:Category:" .. Kana:getCategoryName() .. "|" .. 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<ul>\n" ..
"<li>[[:Category:" .. Hang:getCategoryName() .. "|" .. Hang:getCanonicalName() .. "]]</li>\n" ..
"<li>[[:Category:" .. Hani:getCategoryName() .. "|" .. Hani:getCanonicalName() .. "]]</li>\n" ..
"</ul>\n"
end
text = text .. "</li>"
table.insert(scripts, text)
end
ret = ret .. "<tr>\n<th>[[Wiktionary:Scripts|Scripts]]</th>\n<td><ul>\n" .. table.concat(scripts, "\n") .. "</ul></td>\n</tr>\n"
else
ret = ret .. "<tr>\n<th>[[Wiktionary:Scripts|Scripts]]</th>\n<td>not specified</td>\n</tr>\n"
end
ret = ret .. "</table>"
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 [[Wiktionary:Criteria for inclusion|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."
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 [[Wiktionary:Criteria for inclusion|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 = {{name = "Category:All languages", sort = self._lang:getCanonicalName()}}
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:Pidgins and creole languages", sort = self._lang:getCanonicalName()})
for _, anc in ipairs(self._lang:getAncestors()) do
table.insert(ret, {name = "Category:" .. anc:getCanonicalName() .. "-based pidgin or creole 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 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})
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