Module:labels: Difference between revisions

Undo revision 276931 by Sware (talk)
No edit summary
(Undo revision 276931 by Sware (talk))
Tag: Undo
 
Line 1: Line 1:
local m_labeldata = mw.loadData("Module:labels/data")
local m_labeldata = mw.loadData("Module:labels/data")
--local m_links = require("Module:links") unused
local m_utilities = require("Module:utilities")
 
local m_links = require("Module:links")
local m_utilities_format_categories = require("Module:utilities/format_categories")


local export = {}
local export = {}
Line 55: Line 54:
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 64: Line 63:
local categories = ""
local categories = ""
local alias
local alias
local data = m_labeldata[label]
if m_labeldata.deprecated[label] then
 
-- 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 type(data) == "string" or data.alias_of then
if m_labeldata.aliases[label] then
alias = label
alias = label
label = data.alias_of or data
label = m_labeldata.aliases[label]
if langlabels_ok then
data = langlabels[label] or m_labeldata[label]
else
data = m_labeldata[label]
end
data = data or {}
end
end
if data.deprecated then
if m_labeldata.deprecated[label] 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 119: Line 133:
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 = "[[Appendix:Glossary#" .. glossary_entry .. "|" .. ( data.display or label ) .. "]]"
label = "[[wikt: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 131: Line 145:
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 199: Line 213:
label = ""
label = ""
else
else
label = (omit_comma and "" or '<span class="ib-comma">,</span>') ..
label = (omit_comma and "" or '<span class="ib-comma" style="font-style: normal;">,</span>') ..
(omit_space and "" or "&#32;") ..
(omit_space and "" or "&#32;") ..
ret.label
ret.label
Line 207: Line 221:
return
return
"<span class=\"ib-brac\">(</span><span class=\"ib-content\">" ..
"<span class=\"ib-brac\">(</span><span class=\"ib-content\" style=\"font-style: italic;\">" ..
table.concat(labels, "") ..
table.concat(labels, "") ..
"</span><span class=\"ib-brac\">)</span>"
"</span><span class=\"ib-brac\">)</span>"