Module:Datatype
Jump to navigation
Jump to search
Used by Template:Datatype
Code
local p = {}
local i18n = mw.loadData('Module:i18n/datatype')
function p.resolveDatatype(datatype)
return i18n.keys[string.lower(datatype)]
end
function p.display(datatype, lang)
if not datatype or datatype == '' then
return 'no datatype provided'
end
local fb = require 'Module:Fallback'
datatype = p.resolveDatatype(datatype) or datatype
local data = i18n[datatype]
if not data then
return datatype .. '-' .. fb._langSwitch(i18n.unrecognized, lang)
end
local text = mw.ustring.format('[[Special:MyLanguage/Help:Data_type#%s|%s]]',
datatype, fb._langSwitch(data, lang))
local trailingtext = ''
if data.planned then
local linguistic = require 'Module:Linguistic'
trailingtext = linguistic.inparentheses(fb._langSwitch(i18n.planned, lang), lang)
end
return text .. trailingtext
end
function p.showdatatype(frame)
local datatype = frame.args[1]
if not datatype or datatype == '' then
return nil
end
datatype = string.lower(datatype)
if string.sub(datatype, 1, 9) == 'property:' then
local pid = string.sub(datatype, 11)
datatype = mw.wikibase.getEntity('P' .. pid).datatype
end
local outputtype = frame.args[2]
if outputtype == 'raw' then
return datatype
elseif outputtype == 'abbr' then
if datatype == "wikibase-item" then datatype = "item"
elseif datatype == "wikibase-property" then datatype = "prop"
elseif datatype == "commonsMedia" then datatype = "commons"
elseif datatype == "external-id" then datatype = "ext-id"
end
return datatype
else
local lang = frame.args.lang or frame:callParserFunction('int', 'lang')
return p.display(datatype, lang)
end
end
return p