440
edits
(fix message per Template talk:Death date and age#confusing error message and update from i18n for bn:Module:বয়স) |
m (29 revisions imported from wikipedia:Module:Age) |
||
(5 intermediate revisions by one other user not shown) | |||
Line 3:
local mtext = {
-- Message and other text that should be localized.
-- Also need to localize text in table names in function dateDifference.
['mt-bad-param1'] = 'Invalid parameter $1',
['mt-bad-param2'] = 'Parameter $1=$2 is invalid',
Line 9 ⟶ 10:
['mt-conflicting-show'] = 'Parameter show=$1 conflicts with round=$2',
['mt-date-wrong-order'] = 'The second date must be later in time than the first date',
['mt-dd-future'] = 'Death date (first date) must not be in the future',
['mt-dd-wrong-order'] = 'Death date (first date) must be later in time than the birth date (second date)',
['mt-invalid-bd-age'] = 'Invalid birth date for calculating age',
Line 24 ⟶ 26:
['mt-template-bad-name'] = 'The specified template name is not valid',
['mt-template-x'] = 'The template invoking this must have "|template=x" where x is the wanted operation',
['txt-and'] = ' and ',
['txt-or'] = ' or ',
['txt-category'] = 'Category:Age error',
['txt-comma-and'] = ', and ',
['txt-error'] = 'Error: ',
['txt-
['txt-module-convertnumeric'] = 'Module:ConvertNumeric',
['txt-module-date'] = 'Module:Date',
['txt-sandbox'] = 'sandbox',
['txt-bda'] = '<span style="display:none"> (<span class="bday">$1</span>) </span>$2<span class="noprint ForceAgeToShow"> (age $3)</span>',
['txt-dda'] = '$2<span style="display:none">($1)</span> (aged $3)',
['txt-bda-disp'] = 'disp_raw', -- disp_raw → age is a number only; disp_age → age is a number and unit (normally years but months or days if very young)
['txt-dda-disp'] = 'disp_raw',
['txt-dmy'] = '%-d %B %-Y',
['txt-mdy'] = '%B %-d, %-Y',
}
local isWarning = {
['mt-bad-param1'] = true,
}
Line 49 ⟶ 64:
-- Return objects exported from the date module or its sandbox.
if not _Date then
local sandbox = frame:getTitle():find(mtext['txt-sandbox'], 1, true) and ('/' .. mtext['txt-sandbox']) or ''
local datemod = require(mtext['
local realDate = datemod._Date
_currentDate = datemod._current
Line 101 ⟶ 116:
end
return text
end
local function dateFormat(args)
-- Return string for wanted date format.
local default = mtext['txt-format-default']
local other = default == 'df' and 'mf' or 'df'
local wanted = stripToNil(args[other]) and other or default
return wanted == 'df' and mtext['txt-dmy'] or mtext['txt-mdy']
end
local function substituteParameters(text, ...)
-- Return text after substituting any given parameters for $1, $2, etc.
return mw.message.newRawMessage(text, ...):plain()
end
Line 110 ⟶ 138:
end
local function message(msg,
-- Return formatted message text for an error or warning.
local function getText(msg)
return mtext[msg] or error('Bug: message "' .. tostring(msg) .. '" not defined')
end
local categories = {
error = mtext['txt-category'
warning = mtext['txt-category'],
}
local a, b, k, category
local text = substituteParameters(getText(msg), ...)
if isWarning[msg] then
a = '<sup>[<i>'
b = '</i>]</sup>'
k = 'warning'
else
a = '<strong class="error">' .. getText('txt-error')
b = '</strong>'
k = 'error'
end
if mw.title.getCurrentTitle():inNamespaces(0) then
-- Category only in namespaces: 0=article.
category = '[[' .. categories[
end
return
Line 177 ⟶ 195:
-- i == 1 for the first number which can optionally start with an uppercase letter.
number = tostring(number)
return require(mtext['
number,
nil, -- fraction numerator
Line 194 ⟶ 212:
if mw.ustring.len(extra) > 1 then
-- Parameter "~" gives "~3" whereas "over" gives "over 3".
if extra:sub(-6, -1) ~=
extra = extra .. ' '
end
end
if flagCurrent then
Line 219 ⟶ 239:
sortKey = string.format('%d', sortKey) .. string.format('%015.0f', math.floor(value * 10^(14-mag)))
end
local
if sortable == 'sortable_table' then
elseif sortable == 'sortable_debug' then
result = '<span data-sort-value="_SORTKEY_♠"><span style="border:1px solid">_SORTKEY_♠</span></span>'
else
result = '<span data-sort-value="_SORTKEY_♠"></span>'
end
return
end
end
Line 275 ⟶ 293:
hm = { 'H', 'M', id = 'hm' },
hms = { 'H', 'M', 'S', id = 'hms' },
M = { 'M', id = 'M' },
s = { 'S', id = 's' },
d = { 'd', id = 'd' },
dh = { 'd', 'H', id = 'dh' },
Line 330 ⟶ 350:
date = date + item
if not date then
return message(
end
end
Line 350 ⟶ 370:
end
end
return (sortKey or '') .. makeExtra(args) .. (result or '')
end
Line 387 ⟶ 407:
local name = names[components[i]]
if name then
if type(name) == 'table' then
end
text:add(vstr .. sep .. name
else
text:add(vstr)
Line 439 ⟶ 458:
-- which have been validated.
local names = {
-- Each name is:
-- * a string if no plural form of the name is used; or
-- * a table of strings, one of which is selected using the rules at
-- https://translatewiki.net/wiki/Plural/Mediawiki_plural_rules
abbr_off = {
sep = ' ',
y = {'year', 'years'},
m = {'month', 'months'},
w = {'week', 'weeks'},
d = {'day', 'days'},
H = {'hour', 'hours'},
M = {'minute', 'minutes'},
S = {'second', 'seconds'},
},
abbr_on = {
Line 460 ⟶ 482:
},
abbr_infant = { -- for {{age for infant}}
sep = ' ',
y = {'yr', 'yrs'},
m = {'mo', 'mos'},
w = {'wk', 'wks'},
d = {'day', 'days'},
H = {'hr', 'hrs'},
M = {'min', 'mins'},
S = {'sec', 'secs'},
},
abbr_raw = {},
Line 549 ⟶ 570:
(textOptions.suffix or '')
end
return message(
end
Line 623 ⟶ 644:
for i = 1, nrDates do
local index = i == 1 and 1 or 4
if (m == 2 or m == '2') and (d == 29 or d == '29') then
-- Workaround error with following which attempt to use invalid date 2001-02-29.
-- {{age_ymwd|year1=2001|year2=2004|month2=2|day2=29}}
-- {{age_ymwd|year1=2001|month1=2|year2=2004|month2=1|day2=29}}
-- TODO Get rid of wantMixture because even this ugly code does not handle
-- 'Feb' or 'February' or 'feb' or 'february'.
if not ((y % 4 == 0 and y % 100 ~= 0) or y % 400 == 0) then
d = 28
end
end
dates[i] = Date(y, m, d)
end
else
Line 849 ⟶ 881:
return message('mt-invalid-bd-age')
end
local disp
local show = 'y'
if diff.years < 2 then
disp = 'disp_age'
Line 858 ⟶ 891:
end
end
local result = substituteParameters(
mtext['txt-bda'],
from_en(date:text(dateFormat(args))),
from_en(dateDifference({
diff = diff,
show = show,
Line 871 ⟶ 901:
disp = disp,
sep = 'sep_space',
})
)
local warnings = tonumber(frame.args.warnings)
if warnings and warnings > 0 then
Line 901 ⟶ 931:
end
if invalid then
result = result .. message(
end
end
Line 923 ⟶ 953:
if diff.isnegative then
return message('mt-dd-wrong-order')
end
local Date = getExports(frame)
local today = Date('currentdate') + 1 -- one day in future allows for timezones
if date1 > today then
return message('mt-dd-future')
end
local years
Line 934 ⟶ 969:
return message('mt-invalid-dates-age')
end
local fmt_date, fmt_ymd
if date1.day then -- y, m, d known
fmt_date = dateFormat(args)
elseif date1.month then -- y, m known; d unknown
fmt_date = '%B %-Y'
else -- y known; m, d unknown
end
local result = substituteParameters(
mtext['txt-
date1:text(fmt_ymd),
from_en(date1:text(fmt_date)),
from_en(dateDifference({
diff = diff,
show = 'y',
abbr = 'abbr_off',
disp = mtext['
range = 'dash',
sep = 'sep_space',
})
)
local warnings = tonumber(frame.args.warnings)
if warnings and warnings > 0 then
Line 983 ⟶ 1,015:
end
if invalid then
result = result .. message(
end
end
Line 1,055 ⟶ 1,087:
parm = translate[parm]
if parm == nil then -- test for nil because false is a valid setting
return message(
end
parms[argname] = parm
Line 1,066 ⟶ 1,098:
if show then
if show.id ~= round then
return message(
end
else
|