Module:TNT: Difference between revisions

Jump to navigation Jump to search
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)
metawikimedia>DiBabelYurikBot
m Copying 4 changes by Yurik: "optimize libraryUtil loading only when needed, fix templatedata doc having just the positional parameters, make i18n/ prefix optional, support for usage from modules, no auto I18n/ prefix, breaks some graphs" from mw:Module:TNT. (docs, translate)
Line 36: Line 36:
local p = {}
local p = {}
local i18nDataset = 'I18n/Module:TNT.tab'
local i18nDataset = 'I18n/Module:TNT.tab'
local checkType = require('libraryUtil').checkType


-- Forward declaration of the local functions
-- Forward declaration of the local functions
Line 61: Line 60:
-- Identical to p.msg() above, but used from other lua modules
-- Identical to p.msg() above, but used from other lua modules
function p.format(dataset, key, params, lang)
function p.format(dataset, key, params, lang)
local checkType = require('libraryUtil').checkType
checkType('format', 1, dataset, 'string')
checkType('format', 1, dataset, 'string')
checkType('format', 2, key, 'string')
checkType('format', 2, key, 'string')
Line 68: Line 68:
end
end


-- Converts first parameter to a interwiki-ready link. For example, it converts
-- Obsolete function that adds a 'c:' prefix to the first param.
-- "Sandbox/Sample.tab" -> 'commons:Data:Sandbox/Sample.tab'
-- "Sandbox/Sample.tab" -> 'c:Data:Sandbox/Sample.tab'
function p.link(frame)
function p.link(frame)
return link(frame.args[1])
return link(frame.args[1])
Line 158: Line 158:
-- Given a dataset name, convert it to a title with the 'commons:data:' prefix
-- Given a dataset name, convert it to a title with the 'commons:data:' prefix
link = function(dataset)
link = function(dataset)
dataset = 'Data:' .. mw.text.trim(dataset or '')
return 'c:Data:' .. mw.text.trim(dataset or '')
if mw.site.siteName == 'Wikimedia Commons' then
return dataset
else
return 'commons:' .. dataset
end
end
end