2,788
edits
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
function export.make_labels(language, labels, nocat) | function export.make_labels(language, labels, nocat) | ||
local function make_label(label_id, label) | local function make_label(label_id, label, language_name) | ||
local categories = label["categories"] | |||
local cat_out = "" | |||
if categories ~= nil then | |||
for _, cat in ipairs(categories) do | |||
cat_out = cat_out .. "[[Category:" .. language_name .. " " .. cat .. "]]" | |||
end | |||
end | |||
local display = label["display"] | local display = label["display"] | ||
local glossary = label["glossary"] | local glossary = label["glossary"] | ||
local wikipedia = label["Wikipedia"] | local wikipedia = label["Wikipedia"] | ||
if display ~= nil then return display end | if display ~= nil then return display, cat_out end | ||
if glossary ~= nil then | if glossary ~= nil then | ||
local g_url = "Appendix:Glossary#" .. (type(glossary) == "string" and glossary or label_id) | local g_url = "Appendix:Glossary#" .. (type(glossary) == "string" and glossary or label_id) | ||
return "[[" .. g_url .. "|" .. label_id .. "]]" | return "[[" .. g_url .. "|" .. label_id .. "]]", cat_out | ||
end | end | ||
if wikipedia ~= nil then | if wikipedia ~= nil then | ||
return "[[w:" .. (type(wikipedia) == "string" and wikipedia or label_id) .. "]]" | return "[[w:" .. (type(wikipedia) == "string" and wikipedia or label_id) .. "]]", cat_out | ||
end | end | ||
return label_id | return label_id, cat_out | ||
end | end | ||
local l_data = mw.loadData("Module:labels/data") | local l_data = mw.loadData("Module:labels/data") | ||
local | local out = "(''" | ||
local cats = | local cats = "" | ||
local skip_comma = false | local skip_comma = false | ||
for i, l_id in ipairs(labels) do | for i, l_id in ipairs(labels) do | ||
Line 24: | Line 31: | ||
local label = l_data.labels[l_id] | local label = l_data.labels[l_id] | ||
if i > 1 then | if i > 1 then | ||
out = out .. (skip_comma and " " or ", ") | |||
end | end | ||
if label == null then | if label == null then | ||
out = out .. l_id | |||
skip_comma = false | skip_comma = false | ||
else | else | ||
l_out, l_cats = make_label(l_id, label) | |||
out = out .. l_out | |||
cats = cats .. l_cats | |||
skip_comma = label["omit_comma"] or false | skip_comma = label["omit_comma"] or false | ||
end | end | ||
end | end | ||
out = out .. ")" | |||
return | return out .. (nocat and "" or cats) | ||
end | end | ||