Module:Period/sandbox
Jump to navigation
Jump to search
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
Lua
Documentation for this module may be created at Module:Period/sandbox/doc
Code
local p = {}
function p._periodSpan(item, lang)
-- get the time span of the period given by "item"from the Wikidata values
-- for P580/P582 or P571/P576
local getDate = require('Module:Wikidata date')._date
local start = getDate(item, 'P580' , lang).str or getDate(item, 'P571' , lang).str
local stop = getDate(item, 'P582' , lang).str or getDate(item, 'P576' , lang).str
-- TODO: [[Module:Wikidata label]] has issues with RTL text when falling back
-- to some LTR text, see the example at [[Template:Period/testcases]],
-- has to get fixed there probably
local spantext = nil
if start or stop then
spantext = string.format('(%s–%s)', start or '', stop or '')
end
return spantext
end
function p._period(period, dates, lang)
local wikitext = ''
local LookupTable = mw.loadData('Module:Period/data')
local item = LookupTable[string.lower(period)]
-- try to find an item in the dictionary
if item then
-- if an item was found use it
local wikidata_label = require('Module:Wikidata label')._getLabel
wikitext = wikidata_label(item, lang)
-- now get the time span if requested and append it to the wikitext string
if dates == 'date' or dates == 'yes' then
local spantext = p._periodSpan(item, lang)
if spantext then
wikitext = wikitext .. ' ' .. spantext
end
elseif dates and dates ~= '' then
wikitext = string.format('%s (%s)', wikitext, dates)
end
-- create and append non-visible language independent marking
-- in QuickStatements-like format
-- using property "time period" (P2348)
local qsText = '<div style="display: none;">era QS:P2348,' .. item .. '</div>'
wikitext = wikitext .. qsText
elseif period and period ~= '' then
wikitext = '[[Category:Unsupported period|' .. period .. ']]' .. period
if dates and dates ~= '' then
wikitext = string.format('%s (%s)', wikitext, dates)
end
end
return wikitext
end
function p.period(frame)
local args = frame.args
return p._period(args.period, args.dates, args.lang)
end
return p