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 formatMessage, loadData, link
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])
'templatedata',
return frame:extensionTag('templatedata', p.getTemplateData(dataset)) ..
p.getTemplateData(mw.text.trim(frame.args[1]))
  formatMessage(i18nDataset, 'edit_doc', {link(dataset)})
) .. formatMessage(i18nDataset, 'edit_doc', {link(dataset)})
end
end


function p.getTemplateData(page)
function p.getTemplateData(dataset)
dataset = 'Templatedata/' .. mw.text.trim(page)
-- 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 or dataset == '' then
dataset = sanitizeDataset(dataset)
if not dataset then
error(formatMessage(i18nDataset, 'error_no_dataset', {}))
error(formatMessage(i18nDataset, 'error_no_dataset', {}))
end
if string.sub(dataset,-4) ~= '.tab' then
dataset = dataset .. '.tab'
end
end