Difference between revisions of "Module:TNT"
fix doc translation link
>Yurik (no auto I18n/ prefix, breaks some graphs) |
>Yurik (fix doc translation link) |
||
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 | ||