Module:labels: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 1: Line 1:
local m_labeldata = mw.loadData("Module:labels/data")
local m_labeldata = mw.loadData("Module:labels/data")
local m_utilities = require("Module:utilities")
--local m_links = require("Module:links") unused
local m_links = require("Module:links")
 
local m_utilities_format_categories = require("Module:utilities/format_categories")


local export = {}
local export = {}
Line 54: Line 55:
end
end
return m_utilities.format_categories(categories, lang, sort_key, nil, force_cat) ..
return m_utilities_format_categories(categories, lang, sort_key, nil, force_cat) ..
m_utilities.format_categories(categories2, lang, sort_key2, nil, force_cat)
m_utilities_format_categories(categories2, lang, sort_key2, nil, force_cat)
end
end


Line 63: Line 64:
local categories = ""
local categories = ""
local alias
local alias
if m_labeldata.deprecated[label] then
local data = m_labeldata[label]
 
-- get language-specific labels from data module
local langcode = lang:getCode()
local langlabels_ok, langlabels = pcall(function() return mw.loadData("Module:labels/data/lang/" .. langcode) end)
if langlabels_ok then
-- prefer per-language label in order to pick subvariety labels over regional ones
data = langlabels[label] or data
end
data = data or {}
 
if data.deprecated then
deprecated = true
deprecated = true
end
end
if m_labeldata.aliases[label] then
if type(data) == "string" or data.alias_of then
alias = label
alias = label
label = m_labeldata.aliases[label]
label = data.alias_of or data
if langlabels_ok then
data = langlabels[label] or m_labeldata[label]
else
data = m_labeldata[label]
end
data = data or {}
end
end
if m_labeldata.deprecated[label] then
if data.deprecated then
deprecated = true
deprecated = true
end
local data = m_labeldata.labels[label] or {}
--[=[
Do not use the data in the table if the current language
is not in the "languages" list.
If the original label was an alias, and was redirected to a label
with a data file, go back to the original label.
For example, suppose the label "Rome" is used with the language code "en" (English).
"Rome" redirects to "Romanesco" in [[Module:labels/data/regional]].
The only language in the "languages" list is "it" (Italian).
Because the language code provided to the template was not "it",
the label's data file will not be used,
and the label will display as "Rome".
tracking: [[Special:WhatLinksHere/Template:tracking/labels/incorrect-language]]
[[Special:WhatLinksHere/Template:tracking/labels/redirect-undone]]
]=]
if data.languages then
local lang_code = lang:getCode()
if not data.languages[lang_code] then
mw.log("incorrect language in label template " .. lang_code .. ":" .. label)
if alias and label ~= alias then
mw.log("redirect undone in label template " .. lang_code .. ":" .. label .. " > " .. alias)
label = alias
end
data = {}
end
end
end
Line 133: Line 119:
if data.glossary then
if data.glossary then
local glossary_entry = type(data.glossary) == "string" and data.glossary or label
local glossary_entry = type(data.glossary) == "string" and data.glossary or label
label = "[[wikt:Appendix:Glossary#" .. glossary_entry .. "|" .. ( data.display or label ) .. "]]"
label = "[[Appendix:Glossary#" .. glossary_entry .. "|" .. ( data.display or label ) .. "]]"
elseif data.Wikipedia then
elseif data.Wikipedia then
Wikipedia_entry = type(data.Wikipedia) == "string" and data.Wikipedia or label
Wikipedia_entry = type(data.Wikipedia) == "string" and data.Wikipedia or label
Line 145: Line 131:
label = '<span class="deprecated-label">' .. label .. '</span>'
label = '<span class="deprecated-label">' .. label .. '</span>'
if not nocat then
if not nocat then
categories = categories .. m_utilities.format_categories({ "Entries with deprecated labels" }, lang, sort_key, nil, force_cat)
categories = categories .. m_utilities_format_categories({ "Entries with deprecated labels" }, lang, sort_key, nil, force_cat)
end
end
end
end
Line 213: Line 199:
label = ""
label = ""
else
else
label = (omit_comma and "" or '<span class="ib-comma" style="font-style: normal;">,</span>') ..
label = (omit_comma and "" or '<span class="ib-comma">,</span>') ..
(omit_space and "" or "&#32;") ..
(omit_space and "" or "&#32;") ..
ret.label
ret.label
Line 221: Line 207:
return
return
"<span class=\"ib-brac\">(</span><span class=\"ib-content\" style=\"font-style: italic;\">" ..
"<span class=\"ib-brac\">(</span><span class=\"ib-content\">" ..
table.concat(labels, "") ..
table.concat(labels, "") ..
"</span><span class=\"ib-brac\">)</span>"
"</span><span class=\"ib-brac\">)</span>"

Navigation menu