模块:Countdown:修订间差异

创建页面,内容为“local p = {} -- Constants local lang = mw.language.getContentLanguage() local getArgs = require('Module:Arguments').getArgs local function formatMessage(secondsLeft, event, color) local timeLeft = lang:formatDuration(secondsLeft, {'years', 'weeks', 'days', 'hours', 'minutes', 'seconds'}) -- Find whether we are plural or not. local isOrAre if string.match(timeLeft, '^%d+') == '1' then isOrAre = 'is' else isOrAre = 'are' end -- Color and bold the num…”
 
无编辑摘要
第6行: 第6行:


local function formatMessage(secondsLeft, event, color)
local function formatMessage(secondsLeft, event, color)
local timeLeft = lang:formatDuration(secondsLeft, {'years', 'weeks', 'days', 'hours', 'minutes', 'seconds'})
local timeLeft = lang:formatDuration(secondsLeft, {'', '', '', '小时', '', ''})
-- Find whether we are plural or not.
 
local isOrAre
if string.match(timeLeft, '^%d+') == '1' then
isOrAre = 'is'
else
isOrAre = 'are'
end
-- Color and bold the numbers, because it makes them look important.
-- Color and bold the numbers, because it makes them look important.
timeLeft = string.gsub(timeLeft, '(%d+)', '<span style="color: ' .. (color or '#F00') .. '; font-weight: bold;">%1</span>')
timeLeft = string.gsub(timeLeft, '(%d+)', '<span style="color: ' .. (color or '#F00') .. '; font-weight: bold;">%1</span>')
return string.format('There %s %s until %s.', isOrAre, timeLeft, event)
return string.format('距离 %s 还有 %s.', event, timeLeft)
end
end


第23行: 第17行:


if not (args.year and args.month and args.day) then
if not (args.year and args.month and args.day) then
return '<strong class="error">Error: year, month, and day must be specified</strong>'
return '<strong class="error">错误:需指定年、月、日。</strong>'
end
end


第37行: 第31行:
if timeToStart > 0 then
if timeToStart > 0 then
-- Event has not begun yet
-- Event has not begun yet
text = formatMessage(timeToStart, args.event or 'the event begins', args.color)
text = formatMessage(timeToStart, args.event or '事件开始', args.color)
elseif args.duration then
elseif args.duration then
local timeToEnd
local timeToEnd
第48行: 第42行:
if timeToEnd > 0 then
if timeToEnd > 0 then
-- Event is in progress
-- Event is in progress
text = args.eventstart or formatMessage(timeToEnd, (args.event or 'the event') .. ' ends', args.color)
text = args.eventstart or formatMessage(timeToEnd, args.color)
else
else
-- Event had a duration and has now ended
-- Event had a duration and has now ended
text = args.eventend or ((lang:ucfirst(args.event or 'The event')) .. ' has ended.')
text = args.eventend or ((lang:ucfirst(args.event or '事件')) .. ' 已结束。')
end
end
else
else
-- Event had no duration and has begun
-- Event had no duration and has begun
text = args.eventstart or ((lang:ucfirst(args.event or 'The event')) .. ' has started.')
text = args.eventstart or ((lang:ucfirst(args.event or '事件')) .. ' 已开始。')
end
end
local refreshLink
local refreshLink
第62行: 第56行:
else
else
refreshLink = mw.title.getCurrentTitle():fullUrl({action = 'purge'})
refreshLink = mw.title.getCurrentTitle():fullUrl({action = 'purge'})
refreshLink = string.format(' <small><span class="plainlinks">([%s refresh])</span></small>', refreshLink)
refreshLink = string.format(' <small><span class="plainlinks">([%s 刷新])</span></small>', refreshLink)
end
end
return text .. refreshLink
return text .. refreshLink