মডিউল:module categorization
এই মডিউলের জন্য মডিউল:module categorization/নথি-এ নথিপত্র তৈরি করা হয়ে থাকতে পারে
local export = {}
local categoryKeywords = {
common = "Utility",
utilities = "Utility",
headword = "Headword-line",
translit = "প্রতিবর্ণী",
decl = "Inflection",
conj = "Inflection",
pronun = "Pronunciation",
pronunc = "Pronunciation",
pronunciation = "Pronunciation",
IPA = "Pronunciation",
sortkey = "Sortkey-generating",
}
-- returnTable set to true makes function return table of categories with
-- "[[Category:" and "]]" stripped away. It is used by [[Module:documentation]].
function export.categorize(frame, returnTable)
local title = mw.title.getCurrentTitle()
local subpage = title.subpageText
-- To ensure no categories are added on documentation pages.
if subpage == "documentation" then
return ""
end
local output, categories = {}, {}
local namespace = title.nsText
local pagename, mode
if frame.args[1] then
pagename = frame.args[1]
pagename = pagename:gsub("^Module:", "")
mode = "testing"
mw.log("arg", pagename)
else
if namespace ~= "Module" then
error("This template should only be used in the Module namespace.")
end
pagename = title.text
if subpage ~= pagename then
pagename = title.rootText
end
end
local args
if frame.args.is_template then
local params = {
[1] = {},
[2] = {}, -- FIXME: used in several modules saying e.g. "per the Paiboon scheme"; ignored
["cat"] = {},
}
local parent_args = frame:getParent().args
args = require("Module:parameters").process(parent_args, params)
else
args = {}
end
--[[
If this is a transliteration module, parameter 1 is used as the code,
rather than the code in the page title.
]]
local code, categoryKeyword = pagename:match("([-%a]+)[- ]([^/]+)$")
if not code then
error("Category name was not recognized.")
end
local lang, sc
if subpage == "sandbox" then
table.insert(categories, "Sandbox modules")
else
local category = args.cat or categoryKeywords[categoryKeyword]
if category == "প্রতিবর্ণী" then
code = args[1] or code
end
local origcode = code
if code then
if category then
local getByCode = require("Module:languages").getByCode
for stage=1,2 do
lang = getByCode(code) or getByCode(code .. "-pro")
if category == "প্রতিবর্ণী" then
if not lang then
sc = require("Module:scripts").getByCode(code)
if sc then
table.insert(categories, "Transliteration modules by script|" .. sc:getCanonicalName())
end
end
end
if lang or sc then
break
end
-- Some modules have names like [[Module:bho-Kthi-translit]] or
-- [[Module:Deva-Kthi-translit]]. If we didn't recognize the code the
-- first time, try chopping off the attached script and try again.
code = code:gsub("%-[A-Z].*", "")
end
if not (sc or lang) then
if category == "প্রতিবর্ণী" then
error('The language or script code "' .. origcode ..
'" in the page title is not recognized by [[Module:languages]] or [[Module:scripts]].')
else
error('The language code "' .. origcode ..
'" in the page title is not recognized by [[Module:languages]].')
end
end
local function languageCategory(lang, sortkey)
return lang:getCanonicalName() .. " modules|" .. sortkey
end
local function generalCategory(category, sortkey)
return category .. " modules|" .. sortkey
end
if category == "প্রতিবর্ণী" then
local langs = require("Module:languages/byTranslitModule")(pagename)
local sortkey = category
if sc then
sortkey = sortkey .. ", " .. sc:getCanonicalName()
end
if langs[1] then
for i, lang in ipairs(langs) do
table.insert(categories, languageCategory(lang, sortkey))
end
elseif lang then
table.insert(categories, languageCategory(lang, sortkey))
end
if sc then
table.insert(categories, generalCategory(category, sc:getCanonicalName()))
else
table.insert(categories, generalCategory(category, lang:getCanonicalName()))
end
else
table.insert(categories, languageCategory(lang, category))
table.insert(categories, generalCategory(category, lang:getCanonicalName()))
end
else
error('The category keyword "' .. categoryKeyword .. '" was not recognized.')
end
end
end
if returnTable then
return categories
else
categories = table.concat(
require "Module:fun".map(
function (category)
return "[[Category:" .. category .. "]]"
end,
categories))
end
if testing then
table.insert(output, pagename)
if categories == "" then
categories = '<span class="error">failed to generate categories for ' .. pagename .. '</span>'
else
categories = mw.ustring.gsub(categories, "%]%]%[%[", "]]\n[[")
categories = frame:extensionTag{ name = "syntaxhighlight", content = categories }
end
end
return table.concat(output) .. categories
end
return export