Difference between revisions of "Module:TNT"

Jump to navigation Jump to search
add language param
en>Yurik
en>Yurik
(add language param)
Line 12: Line 12:
--    with a given key (e.g. source-table), plus optional arguments
--    with a given key (e.g. source-table), plus optional arguments
--    to the wiki markup in the current content language.
--    to the wiki markup in the current content language.
--    Use lang=xx to set language.
--
--
--      {{#invoke:TNT | msg | Original/Template:Graphs.tab | source-table | param1 }}
--      {{#invoke:TNT | msg | Original/Template:Graphs.tab | source-table | param1 }}
--            uses https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab
--            uses https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab
--   
--   
--    The "doc" function will generate the <templatedata> parameter documentation for templates.i
--    The "doc" function will generate the <templatedata> parameter documentation for templates.
--    This way all template parameters can be stored and localized in a single Commons dataset.
--    This way all template parameters can be stored and localized in a single Commons dataset.
--    NOTE: "doc" assumes that all documentation is located in Data:Templatedata/* on Commons.
--    NOTE: "doc" assumes that all documentation is located in Data:Templatedata/* on Commons.
Line 31: Line 32:
local dataset, id
local dataset, id
local params = {}
local params = {}
local lang = nil
for k, v in pairs(frame.args) do
for k, v in pairs(frame.args) do
if k == 1 then
if k == 1 then
Line 38: Line 40:
elseif type(k) == 'number' then
elseif type(k) == 'number' then
table.insert(params, v)
table.insert(params, v)
elseif k == 'lang' and v ~= '_' then
lang = v
end
end
end
end
return formatMessage(dataset, id, params)
return formatMessage(dataset, id, params, lang)
end
end


Line 61: Line 65:
function p.doc(frame)
function p.doc(frame)
dataset = 'Templatedata/' .. normalizeDataset(frame.args[1])
dataset = 'Templatedata/' .. normalizeDataset(frame.args[1])
-- TODO: add '_' parameter once lua starts reindexing properly for "all" languages
local data = loadData(dataset)
local data = loadData(dataset)
local names = {}
local names = {}
Line 97: Line 102:
end
end


function formatMessage(dataset, key, params)
function formatMessage(dataset, key, params, lang)
     for _, row in pairs(loadData(dataset).data) do
     for _, row in pairs(loadData(dataset, lang).data) do
     local id, msg = unpack(row)
     local id, msg = unpack(row)
     if id == key then
     if id == key then
Line 127: Line 132:
end
end


function loadData(dataset)
function loadData(dataset, lang)
local data = mw.ext.data.get(dataset)
local data = mw.ext.data.get(dataset, lang)
if data == false then
if data == false then
if dataset == i18nDataset then
if dataset == i18nDataset then
Anonymous user

Navigation menu