Module:TNT: Difference between revisions
Jump to navigation
Jump to search
metawikimedia>DiBabelYurikBot m Copying 4 changes by Yurik: "no auto I18n/ prefix, breaks some graphs, fixed doc link, Trim parameter whitespaces, docs link" from mw:Module:TNT. See docs. |
metawikimedia>DiBabelYurikBot m Copying 5 changes by Yurik: "fix doc translation link, Trim parameter whitespaces, docs link, fix templatedata doc having just the positional parameters, make i18n/ prefix optional, support for usage from modules" from mw:Module:TNT. (docs, translate) |
||
Line 39: | Line 39: | ||
-- Forward declaration of the local functions | -- Forward declaration of the local functions | ||
local | local sanitizeDataset, loadData, link, formatMessage | ||
function p.msg(frame) | function p.msg(frame) | ||
Line 75: | Line 75: | ||
function p.doc(frame) | function p.doc(frame) | ||
return frame:extensionTag( | local dataset = 'Templatedata/' .. sanitizeDataset(frame.args[1]) | ||
return frame:extensionTag('templatedata', p.getTemplateData(dataset)) .. | |||
formatMessage(i18nDataset, 'edit_doc', {link(dataset)}) | |||
end | end | ||
function p.getTemplateData( | function p.getTemplateData(dataset) | ||
-- TODO: add '_' parameter once lua starts reindexing properly for "all" languages | -- TODO: add '_' parameter once lua starts reindexing properly for "all" languages | ||
local data = loadData(dataset) | local data = loadData(dataset) | ||
Line 124: | Line 122: | ||
-- Local functions | -- Local functions | ||
sanitizeDataset = function(dataset) | |||
if not dataset then | |||
return nil | |||
end | |||
dataset = mw.text.trim(dataset) | |||
if dataset == '' then | |||
return nil | |||
elseif string.sub(dataset,-4) ~= '.tab' then | |||
return dataset .. '.tab' | |||
else | |||
return dataset | |||
end | |||
end | |||
loadData = function(dataset, lang) | loadData = function(dataset, lang) | ||
if not dataset | dataset = sanitizeDataset(dataset) | ||
if not dataset then | |||
error(formatMessage(i18nDataset, 'error_no_dataset', {})) | error(formatMessage(i18nDataset, 'error_no_dataset', {})) | ||
end | end | ||