Module:Age/sandbox: Difference between revisions

Content deleted Content added
more localization; bda + dda use $1/$2/$3 substitutes so wanted wikitext can be specified
more localization for bnwiki + bswiki
Line 31:
['txt-comma-and'] = ', and ',
['txt-error'] = 'Error: ',
['txt-format-default'] = 'mf', -- 'df' (day first = dmy) or 'mf' (month first = mdy)
['txt-module-convertnumeric'] = 'Module:ConvertNumeric',
['txt-module-date'] = 'Module:Date',
Line 37:
['txt-bda'] = '<span style="display:none"> (<span class="bday">$1</span>) </span>$2<span class="noprint ForceAgeToShow"> (age&nbsp;$3)</span>',
['txt-dda'] = '$2<span style="display:none">($1)</span> (aged&nbsp;$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 repisWarning = {}
['mt-bad-param1'] = true,
}
 
Line 112 ⟶ 120:
local function dateFormat(args)
-- Return string for wanted date format.
local default = mtext['txt-format-default'] -- 'df' (day first = dmy) or 'mf' (month first = mdy)
local other = default == 'df' and 'mf' or 'df'
local wanted = stripToNil(args[other]) and other or default
return wanted == 'df' and mtext['%txt-d %B %-Ydmy'] or mtext['%B %-d, %txt-Ymdy']
end
 
Line 122 ⟶ 130:
return mw.message.newRawMessage(text, ...):plain()
end
 
local function yes(parameter)
-- Return true if parameter should be interpreted as "yes".
Line 129 ⟶ 138:
end
 
local function message(msg, id...)
-- 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 text
if type(msg) == 'table' then
text = getText(msg[1])
local rep = {}
for i, v in ipairs(msg) do
if i > 1 then
rep['$' .. (i - 1)] = v
end
end
text = text:gsub('$%d+', rep)
else
text = getText(msg)
end
local categories = {
Line 151 ⟶ 147:
warning = mtext['txt-category'],
}
local a, b, k, category
local text = substituteParameters(getText(msg), ...)
if id == 'warning' then
if isWarning[msg] then
a = '<sup>[<i>'
b = '</i>]</sup>'
if id k == 'warning' then
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[id or 'error'k] .. ']]'
end
return
Line 248 ⟶ 247:
result = '<span data-sort-value="_SORTKEY_♠"></span>'
end
return (result:gsub('_SORTKEY_', sortKey))
end
end
Line 351 ⟶ 350:
date = date + item
if not date then
return message({ 'mt-cannot-add', item })
end
end
Line 408 ⟶ 407:
local name = names[components[i]]
if name then
text:addif type(vstrname) ..== sep'table' ..then
name = mw.getContentLanguage():plural(islist and v[2] or v, name))
end
text:add(vstr .. sep .. name)
else
text:add(vstr)
Line 456 ⟶ 458:
-- which have been validated.
local names = {
-- Each name is a table of strings, one of which is used following the rules at:
-- * a string if no plural form of the name is used; or
-- https://translatewiki.net/wiki/Plural/Mediawiki_plural_rules
-- * a table of strings, one of which is selected using the rules at
-- https://translatewiki.net/wiki/Plural/Mediawiki_plural_rules
abbr_off = {
sep = '&nbsp;',
Line 469 ⟶ 473:
},
abbr_on = {
y = {'y'},
m = {'m'},
w = {'w'},
d = {'d'},
H = {'h'},
M = {'m'},
S = {'s'},
},
abbr_infant = { -- for {{age for infant}}
Line 566 ⟶ 570:
(textOptions.suffix or '')
end
return message({ 'mt-bad-show', show.id })
end
 
Line 877 ⟶ 881:
return message('mt-invalid-bd-age')
end
local disp, show = mtext['disp_raw', 'ytxt-bda-disp']
local textshow = 'y'
if diff.years < 2 then
disp = 'disp_age'
Line 926 ⟶ 931:
end
if invalid then
result = result .. message({ 'mt-bad-param1', invalid }, 'warning')
end
end
Line 983 ⟶ 988:
show = 'y',
abbr = 'abbr_off',
disp = mtext['disp_rawtxt-dda-disp'],
range = 'dash',
sep = 'sep_space',
Line 1,010 ⟶ 1,015:
end
if invalid then
result = result .. message({ 'mt-bad-param1', invalid }, 'warning')
end
end
Line 1,082 ⟶ 1,087:
parm = translate[parm]
if parm == nil then -- test for nil because false is a valid setting
return message({ 'mt-bad-param2', argname, args[argname] })
end
parms[argname] = parm
Line 1,093 ⟶ 1,098:
if show then
if show.id ~= round then
return message({ 'mt-conflicting-show', args.show, args.round })
end
else