မဝ်ဂျူ:reference template cat
မံက်ပြာကတ်
Documentation for this module may be created at မဝ်ဂျူ:reference template cat/doc
local export = {}
local Array = require("Module:array")
local m_lang = require("Module:languages")
local prefixes = {
['နိဿဲ'] = 'R',
['quotation'] = 'RQ',
}
function export.categorize(title, langs, sortkey, what)
what = what or 'နိဿဲ';
langs = Array(langs):slice()
local name = title.text:gsub("^" .. prefixes[what] .. ":", "")
local lang_in_title, rest = name:match("^(%l[%l-]*%l):(.+)$")
if lang_in_title then
if not m_lang.getByCode(lang_in_title) then
lang_in_title = lang_in_title .. "-pro"
end
if m_lang.getByCode(lang_in_title) and not langs:contains(lang_in_title) then
langs:insert(1, lang_in_title)
end
name = rest
end
sortkey = sortkey or name
return langs
:map(
function (langCode)
local lang = m_lang.getByCode(langCode, true)
return "[[Category:ထာမ်ပလိက်".. what .. lang:getCanonicalName()
.. "ဂမၠိုင်|" .. sortkey .. "]]"
end)
:concat ""
end
function export.main(frame)
local current_title = mw.title.getCurrentTitle()
if current_title.nsText == "" or current_title.nsText == "ဗီုပြင်သိုင်တၟိ" then
error("This template is meant to be used in the Template namespace.")
end
local what = frame.args.what or 'နိဿဲ'; -- can be either 'နိဿဲ' or 'quotation'
local args = frame:getParent().args
local sortkey = args.sort
local args = Array.shallow_copy(args)
local title = current_title
local is_demo = current_title.nsText == "မဝ်ဂျူ"
or (current_title.nsText == "ထာမ်ပလိက်"
and current_title.baseText == what .. " template cat")
if is_demo and args.title then
title = mw.title.new(args.title)
args.title = nil
end
args.sort = nil
local langs = args
if not langs:is_array() then
error("Sequential positional parameters expected")
end
local categories = export.categorize(title, langs, sortkey, what)
if is_demo then
categories = mw.text.nowiki(categories)
end
return categories
end
return export