مۆدیوول:Age/خۆڵەپەتانێ: جیاوازیی نێوان پێداچوونەوەکان

ناوەڕۆکی سڕاو ناوەڕۆکی زیادکراو
No edit summary
تاقیکردنەوەى وەشانى ویکی ئینگلیزی
ھێڵی ١:
-- Implement various "age of" and other date-related templates.
 
local numConv = require('Module:Numeral_converter').convert
 
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-ageand'] = '(age and ',
['txt-agedor'] = ' or (aged',
['txt-andcategory'] = '، وCategory:Age error',
['txt-comma-and'] = '،, وand ',
['txt-error'] = 'ھەڵەError: ',
['txt-orformat-default'] = 'mf', -- 'df' (day first = dmy) or 'mf' (month first ' یان= ',mdy)
['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&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 abbr_pluralisWarning = {
['mt-bad-param1'] = true,
y = 'ساڵ',
m = 'مانگ',
w = 'ھەفتە',
d = 'ڕۆژ',
H = 'سەعات',
M = 'دەقە',
S = 'چرکە',
}
local translate, from_en, to_en, isZero
 
translate = {
digits = {
from_en = {
['0'] = '٠',
['1'] = '١',
['2'] = '٢',
['3'] = '٣',
['4'] = '٤',
['5'] = '٥',
['6'] = '٦',
['7'] = '٧',
['8'] = '٨',
['9'] = '٩',
},
to_en = {
['٠'] = '0',
['١'] = '1',
['٢'] = '2',
['٣'] = '3',
['٤'] = '4',
['٥'] = '5',
['٦'] = '6',
['٧'] = '7',
['٨'] = '8',
['٩'] = '9',
},
},
words = {
from_en = {
January = 'کانوونی دووەم',
February = 'شوبات',
March = 'ئادار',
April = 'نیسان',
May = 'ئایار',
June = 'حوزەیران',
July = 'تەممووز',
August = 'ئاب',
September = 'ئەیلوول',
October = 'تشرینی یەکەم',
November = 'تشرینی دووەم',
December = 'کانوونی یەکەم',
Jan = 'کانوونی دووەم',
Feb = 'شوبات',
Sep = 'ئەیلوول',
Oct = 'تشرینی یەکەم',
Nov = 'تشرینی دووەم',
Dec = 'کانوونی یەکەم',
},
to_en = {
['کانوونی دووەم'] = 'January',
['شوبات'] = 'February',
['ئادار'] = 'March',
['ئازار'] = 'March',
['نیسان'] = 'April',
['ئایار'] = 'May',
['حوزەیران'] = 'June',
['تەممووز'] = 'July',
['ئاب'] = 'August',
['ئەیلوول'] = 'September',
['تشرینی یەکەم'] = 'October',
['تشرینی دووەم'] = 'November',
['کانوونی یەکەم'] = 'December',
['ئەیلول'] = 'Sep',
},
},
}
 
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:বয়স]].
from_en = function (text)
-- Translate en output to local language.
return (text
:gsub('%d', translate.digits.from_en)
:gsub('%a+', translate.words.from_en))
end
to_en = function (text)
text = mw.ustring.gsub(text, '%d', translate.digits.to_en)
-- Translate input in local language to en.
-- Following trick works for languages where all letters are non-ASCII.
-- It is needed because mw.ustring pattern '%a+' only finds parts of a word.
return (string.gsub(text, '[\128-\255]+', translate.words.to_en))
end
isZero = function (text)
return tonumber((mw.ustring.gsub(text or '', '%d', translate.digits.to_en))) == 0
end
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['خۆڵەپەتانێtxt-sandbox'], 1, true) and ('/خۆڵەپەتانێ' .. mtext['txt-sandbox']) or ''
local datemod = require(mtext['Module:Date2txt-module-date'])
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, 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 = {
error = mtext['txt-category'[[Category:Age error]]',
warning = mtext['txt-category'],
warning = '[[Category:Age error]]', -- same as error until determine whether 'Age warning' would be worthwhile
}
local a, b, k, category
local text = substituteParameters(getText(msg), ...)
if id == 'warning' then
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[idk] or.. 'error']]'
end
return
Line ٢٧٤ ⟶ ١٩٥:
-- i == 1 for the first number which can optionally start with an uppercase letter.
number = tostring(number)
return require(mtext['Module:ConvertNumerictxt-module-convertnumeric']).spell_number(
number,
nil, -- fraction numerator
Line ٢٩٦ ⟶ ٢١٧:
end
if flagCurrent then
extra = '<span class="currentage"></span>' .. extra
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',
[','] = '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({ 'mt-cannot-add', item })
end
end
Line ٤٨٥ ⟶ ٤٠٦:
end
local name = names[components[i]]
--if islist then
--name = abbr_plural[components[i]] -- إضافة اسم الجمع باللغة العربية
--end
--mw.log( 'vstr: ' .. vstr )
if name then
if type(name) == 'table' then
local plural = abbr_plural[components[i]] -- names.plural
if name not= mw.getContentLanguage():plural or (islist and v[2] or v, name) == 1 then
plural = ''
end
text:add(vstr .. sep .. name)
if plural ~= "s" and plural ~= "" then name = "" end
text:add(vstr .. name .. plural)
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 numConv(
'ckb',
(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 = {
pluralsep = 's&nbsp;',
sepy = {'year', 'years'},
ym = {'ساڵmonth', 'months'},
mw = {'مانگweek', 'weeks'},
wd = {'ھەفتەday', 'days'},
dH = {'ڕۆژhour', 'hours'},
HM = {'سەعاتminute', 'minutes'},
MS = {'دەقەsecond', 'seconds'},
S = 'چرکە',
},
abbr_on = {
Line ٥٦٤ ⟶ ٤٨٢:
},
abbr_infant = { -- for {{age for infant}}
pluralsep = 's&nbsp;',
sepy = {'yr', 'yrs'},
ym = {'yrmo', 'mos'},
mw = {'mowk', 'wks'},
wd = {'wkday', 'days'},
dH = {'dayhr', 'hrs'},
HM = {'hrmin', 'mins'},
MS = {'minsec', 'secs'},
S = 'sec',
},
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({ 'mt-bad-show', show.id })
end
 
Line ٧٢٦ ⟶ ٦٤٤:
for i = 1, nrDates do
local index = i == 1 and 1 or 4
dates[i]local y, m, d = Date(fields[index], fields[index+1], fields[index+2])
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, show = mtext['disp_raw', 'ytxt-bda-disp']
local show = 'y'
if diff.years < 2 then
disp = 'disp_age'
Line ٩٦١ ⟶ ٨٩١:
end
end
local result = substituteParameters(
local df = stripToNil(args.df) -- day first (dmy); default is month first (mdy)
mtext['txt-bda'],
local result = '<span class="bday">(%-Y-%m-%d)</span></span>' ..
date:text(df and '%-d %B Y-%m-Y' or '%B %-d, %-Y'),
from_en(date:text(dateFormat(args))),
result = from_en('<span style="display:none">' ..
from_en(dateDifference({
date:text(result) ..
'<span class="noprint ForceAgeToShow">' ..
mtext['txt-age'] ..
dateDifference({
diff = diff,
show = show,
Line ٩٧٤ ⟶ ٩٠١:
disp = disp,
sep = 'sep_space',
}) ..)
)
')</span>')
local warnings = tonumber(frame.args.warnings)
if warnings and warnings > 0 then
Line ١٬٠٠٤ ⟶ ٩٣١:
end
if invalid then
result = result .. message({ 'mt-bad-param1', invalid }, 'warning')
end
end
Line ١٬٠٤٢ ⟶ ٩٦٩:
return message('mt-invalid-dates-age')
end
local fmt_date, fmt_ymd
local df = stripToNil(args.df) -- day first (dmy); default is month first (mdy)
local result
if date1.day then -- y, m, d known
fmt_date = dateFormat(args)
result = (df and
'%-dfmt_ymd %B= '%-Y-%m-%d' or
'%B %-d, %-Y') ..
'<span style="display:none">(%-Y-%m-%d)</span>'
elseif date1.month then -- y, m known; d unknown
fmt_date = '%B %-Y'
result =
fmt_ymd = '%B %-Y-%m-00' ..
'<span style="display:none">(%-Y-%m-00)</span>'
else -- y known; m, d unknown
resultfmt_date = '%-Y'
fmt_ymd = '%-Y-00-00' ..
'<span style="display:none">(%-Y-00-00)</span>'
end
local result = substituteParameters(
result = from_en(date1:text(result) ..
mtext['txt-ageddda'] ..,
date1:text(fmt_ymd),
dateDifference({
from_en(date1:text(fmt_date)),
from_en(dateDifference({
diff = diff,
show = 'y',
abbr = 'abbr_off',
disp = mtext['disp_rawtxt-dda-disp'],
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({ 'mt-bad-param1', invalid }, 'warning')
end
end
Line ١٬١٦٣ ⟶ ١٬٠٨٧:
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 ١٬١٧٤ ⟶ ١٬٠٩٨:
if show then
if show.id ~= round then
return message({ 'mt-conflicting-show', args.show, args.round })
end
else