مۆدیوول:Age/خۆڵەپەتانێ: جیاوازیی نێوان پێداچوونەوەکان
ناوەڕۆکی سڕاو ناوەڕۆکی زیادکراو
No edit summary |
تاقیکردنەوەى وەشانى ویکی ئینگلیزی |
||
ھێڵی ١:
-- Implement various "age of" and other date-related templates.
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 ٢٧ ⟶ ٢٦:
['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-
['txt-
['txt-
['txt-comma-and'] = '
['txt-error'] = '
['txt-
['txt-module-convertnumeric'] = 'Module:ConvertNumeric',
['txt-module-date'] = 'Module:Date',
['txt-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
['mt-bad-param1'] = true,
}
local translate, from_en, to_en, isZero
if translate then
-- Functions to translate from en to local language and reverse go here.
-- See example at [[:bn:Module:বয়স]].
else
from_en = function (text)
Line ١٤٦ ⟶ ٦٤:
-- Return objects exported from the date module or its sandbox.
if not _Date then
local sandbox = frame:getTitle():find(mtext['
local datemod = require(mtext['
local realDate = datemod._Date
_currentDate = datemod._current
Line ١٩٨ ⟶ ١١٦:
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 ٢٠٧ ⟶ ١٣٨:
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 ٢٧٤ ⟶ ١٩٥:
-- 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 ٢٩٦ ⟶ ٢١٧:
end
if flagCurrent then
end
return extra
Line ٣٢٧ ⟶ ٢٤٧:
result = '<span data-sort-value="_SORTKEY_♠"></span>'
end
return (result:gsub('_SORTKEY_', sortKey))
end
end
Line ٣٥٤ ⟶ ٢٧٤:
sep = {
comma = 'sep_comma',
[','] = 'sep_comma',
serialcomma = 'sep_serialcomma',
Line ٣٧٤ ⟶ ٢٩٣:
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 ٤٢٩ ⟶ ٣٥٠:
date = date + item
if not date then
return message(
end
end
Line ٤٨٥ ⟶ ٤٠٦:
end
local name = names[components[i]]
if name then
if type(name) == 'table' then
end
text:add(vstr .. sep .. name)
else
text:add(vstr)
Line ٥٠٦ ⟶ ٤٢١:
last = ' '
elseif options.join == 'sep_comma' then
first = '
last = '
elseif options.join == 'sep_serialcomma' and text.n > 2 then
first = '
last = mtext['txt-comma-and']
else
first = '
last = mtext['txt-and']
end
Line ٥٣١ ⟶ ٤٤٦:
end
end
return
(options.sortKey or '') ..
(options.extra or '') ..
sign ..
text:join() ..
(options.suffix or '')
end
Line ٥٤٣ ⟶ ٤٥٨:
-- 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 = {
},
abbr_on = {
Line ٥٦٤ ⟶ ٤٨٢:
},
abbr_infant = { -- for {{age for infant}}
},
abbr_raw = {},
Line ٥٨١ ⟶ ٤٩٨:
local defaultJoin
if abbr ~= 'abbr_off' then
defaultJoin = 'sep_space'
end
if not show then
Line ٥٨٧ ⟶ ٥٠٤:
if parms.disp == 'disp_age' then
if diff.years < 3 then
defaultJoin = 'sep_space'
if diff.years >= 1 then
show = 'ym'
Line ٦٠٢ ⟶ ٥١٩:
end
if parms.disp == 'disp_raw' then
defaultJoin = 'sep_space'
abbr = 'abbr_raw'
elseif parms.wantSc then
Line ٦٥٠ ⟶ ٥٦٧:
makeText({ diff.partial.mindiff:age(show.id, diffOptions) }, show, names[abbr], opt) ..
rangeJoin(textOptions.range) ..
makeText({ diff.partial.maxdiff:age(show.id, diffOptions) }, show, names[abbr], opt, true) ..
(textOptions.suffix or '')
end
return message(
end
Line ٧٢٦ ⟶ ٦٤٤:
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 ٩٥٢ ⟶ ٨٨١:
return message('mt-invalid-bd-age')
end
local disp
local show = 'y'
if diff.years < 2 then
disp = 'disp_age'
Line ٩٦١ ⟶ ٨٩١:
end
end
local result = substituteParameters(
mtext['txt-bda'],
from_en(date:text(dateFormat(args))),
from_en(dateDifference({
diff = diff,
show = show,
Line ٩٧٤ ⟶ ٩٠١:
disp = disp,
sep = 'sep_space',
})
)
local warnings = tonumber(frame.args.warnings)
if warnings and warnings > 0 then
Line ١٬٠٠٤ ⟶ ٩٣١:
end
if invalid then
result = result .. message(
end
end
Line ١٬٠٤٢ ⟶ ٩٦٩:
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 ١٬٠٩١ ⟶ ١٬٠١٥:
end
if invalid then
result = result .. message(
end
end
Line ١٬١٦٣ ⟶ ١٬٠٨٧:
parm = translate[parm]
if parm == nil then -- test for nil because false is a valid setting
return message(
end
parms[argname] = parm
Line ١٬١٧٤ ⟶ ١٬٠٩٨:
if show then
if show.id ~= round then
return message(
end
else
|