Modul:labels
Izgled
Dokumentaciju za ovaj modul možete napraviti na stranici Modul:labels/dok
local languages = mw.loadData("Module:languages")
local m_labeldata = mw.loadData("Module:labels/data")
local export = {}
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local args = frame:getParent().args
NAMESPACE = mw.title.getCurrentTitle().nsText
local ret = ""
local compat = (frame.args["compat"] or "") ~= ""
-- Gather parameters
local lang = args[(compat and "lang" or 1)] or (NAMESPACE == "Template" and "und") or ""; if compat and lang == "" then lang = "en" end --(NAMESPACE == "Template" and "und") or error("Language code has not been specified. Please pass parameter \"lang=\" to the template.")
local langinfo = languages[lang] or error("The language code \"" .. lang .. "\" is not valid.")
local script = args["script"]; if script == "" then script = nil end
local script2 = args["script2"]; if script2 == "" then script2 = nil end
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
local sort_key2 = args["sort2"]; if sort_key2 == "" then sort_key2 = nil end
-- Show the labels
ret = ret .. "<span class=\"ib-brac qualifier-brac\">(</span><span class=\"ib-content qualifier-content\">"
local i = (compat and 1 or 2)
local label = args[i] or ""
local next_label = args[i+1] or ""
while label ~= "" do
if label == "," then
ret = ret .. '<span class="ib-comma"><span class="qualifier-comma">,</span></span> '
elseif label == "or" then
ret = ret .. 'or '
elseif label == "and" then
ret = ret .. 'and '
elseif label == "_" then
if next_label ~= "," and next_label ~= "" then
ret = ret .. ' '
end
else
-- Is this label really an alias of another label?
-- If so, then just "rename" the current label to the one it points to.
if m_labeldata.aliases[label] then
label = m_labeldata.aliases[label]
end
-- Is this label a known/recognised label?
if m_labeldata.labels[label] then
ret = ret .. show_label(label, m_labeldata.labels[label], next_label, lang, langinfo, script, sort_key, script2, sort_key2)
else
-- Does a valid context label template exist for this label?
local label_template = mw.title.new("Template:" .. label)
if label_template and label_template.exists and frame:expandTemplate{ title = label, args = { sub = "test" } } == "valid context label" then
ret = ret .. frame:expandTemplate{ title = label, args = {
next = next_label,
lang = lang,
script = script,
script2 = script2,
sort = sort_key,
sort2 = sort_key2 } }
else
ret = ret .. show_label(label, {display = label}, next_label, lang, langinfo, script, sort_key, script2, sort_key2)
end
end
end
i = i + 1
label = next_label
next_label = args[i+1] or ""
end
ret = ret .. "</span><span class=\"ib-brac qualifier-brac\">)</span>"
return ret
end
function show_label(label, data, next_label, lang, langinfo, script, sort_key, script2, sort_key2)
local ret = data.display or label
if next_label == "," or next_label == "or" or next_label == "and" or next_label == "_" then
ret = ret .. " "
elseif next_label ~= "" then
ret = ret .. "<span class=\"ib-comma qualifier-comma\">,</span> "
end
if NAMESPACE == "" or NAMESPACE == "Appendix" then
for i, cat in ipairs(data.topical_categories or {}) do
ret = ret .. "[[Category:" .. lang .. ":" .. cat .. (sort_key and "|" .. sort_key or "") .. "]]"
if script then
ret = ret .. "[[Category:" .. lang .. ":" .. cat .. " in " .. script .. " script" .. (sort_key and "|" .. sort_key or "") .. "]]"
end
if script2 then
ret = ret .. "[[Category:" .. lang .. ":" .. cat .. " in " .. script2 .. " script" .. (sort_key2 and "|" .. sort_key2 or "") .. "]]"
end
end
for i, cat in ipairs(data.pos_categories or {}) do
ret = ret .. "[[Category:" .. langinfo.names[1] .. " " .. cat .. (sort_key and "|" .. sort_key or "") .. "]]"
if script then
ret = ret .. "[[Category:" .. langinfo.names[1] .. " " .. cat .. " in " .. script .. " script" .. (sort_key and "|" .. sort_key or "") .. "]]"
end
if script2 then
ret = ret .. "[[Category:" .. langinfo.names[1] .. " " .. cat .. " in " .. script2 .. " script" .. (sort_key2 and "|" .. sort_key2 or "") .. "]]"
end
end
for i, cat in ipairs(data.regional_categories or {}) do
ret = ret .. "[[Category:" .. cat .. " " .. langinfo.names[1] .. (sort_key and "|" .. sort_key or "") .. "]]"
if script then
ret = ret .. "[[Category:" .. cat .. " " .. langinfo.names[1] .. " in " .. script .. " script" .. (sort_key and "|" .. sort_key or "") .. "]]"
end
if script2 then
ret = ret .. "[[Category:" .. cat .. " " .. langinfo.names[1] .. " in " .. script2 .. " script" .. (sort_key2 and "|" .. sort_key2 or "") .. "]]"
end
end
for i, cat in ipairs(data.plain_categories or {}) do
ret = ret .. "[[Category:" .. cat .. (sort_key and "|" .. sort_key or "") .. "]]"
if script then
ret = ret .. "[[Category:" .. cat .. " in " .. script .. " script" .. (sort_key and "|" .. sort_key or "") .. "]]"
end
if script2 then
ret = ret .. "[[Category:" .. cat .. " in " .. script2 .. " script" .. (sort_key2 and "|" .. sort_key2 or "") .. "]]"
end
end
end
return ret
end
return export