মডিউল:বয়স: সংশোধিত সংস্করণের মধ্যে পার্থক্য

বিষয়বস্তু বিয়োগ হয়েছে বিষয়বস্তু যোগ হয়েছে
https://en.wikipedia.org/w/index.php?title=Module:Age&oldid=877316077 থেকে কোড
Johnuniq (আলোচনা | অবদান)
allow localization per request on talk and en:User talk:Johnuniq#Module:Age for bnwiki
১ নং লাইন:
-- Implement various "age of" and other date-related templates.
 
local mtext = {
-- Message and other text that should be localized.
['mt-bad-param1'] = 'Invalid parameter $1',
['mt-bad-param2'] = 'Parameter $1=$2 is invalid',
['mt-bad-show'] = 'Parameter show=$1 is not supported here',
['mt-cannot-add'] = 'Cannot add "$1"',
['mt-conflicting-show'] = 'Parameter show=$1 conflicts with round=$2',
['mt-date-wrong-order'] = 'The second date should not be before the first date',
['mt-dd-wrong-order'] = 'Death date (first date) must occur after birth date (second date)',
['mt-invalid-bd-age'] = 'Invalid birth date for calculating age',
['mt-invalid-dates-age'] = 'Invalid dates for calculating age',
['mt-invalid-end'] = 'Invalid end date in second parameter',
['mt-invalid-start'] = 'Invalid start date in first parameter',
['mt-need-jdn'] = 'Need valid Julian date number',
['mt-need-valid-bd'] = 'Need valid birth date: year, month, day',
['mt-need-valid-bd2'] = 'Need valid birth date (second date): year, month, day',
['mt-need-valid-date'] = 'Need valid date',
['mt-need-valid-dd'] = 'Need valid death date (first date): year, month, day',
['mt-need-valid-ymd'] = 'Need valid year, month, day',
['mt-need-valid-ymd-current'] = 'Need valid year/month/day or "currentdate"',
['mt-need-valid-ymd2'] = 'Second date should be year, month, day',
['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-age'] = '(age ',
['txt-aged'] = ' (aged ',
['txt-and'] = ' and ',
['txt-comma-and'] = ', and ',
['txt-or'] = ' or ',
}
 
local 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',
['এপ্রিল'] = 'April',
['মে'] = 'May',
['জুন'] = 'June',
['জুলাই'] = 'July',
['আগস্ট'] = 'August',
['সেপ্টেম্বর'] = 'September',
['অক্টোবর'] = 'October',
['নভেম্বর'] = 'November',
['ডিসেম্বর'] = 'December',
['জানু'] = 'Jan',
['ফেব্রু'] = 'Feb',
['সেপ্টে'] = 'Sep',
['অক্টো'] = 'Oct',
['নভে'] = 'Nov',
['ডিসে'] = 'Dec',
},
},
}
 
local from_en, to_en
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.
-- Do not translate any metadata or sortkey.
-- That is achieved by skipping the first "<span.../span>".
local spanMarker = '\127_SPAN_\127'
local spanText = text:match('<span.-/span>') or ''
text = text
:gsub('<span.-/span>', spanMarker, 1)
:gsub('%d', translate.digits.from_en)
:gsub('%a+', translate.words.from_en)
:gsub(spanMarker, spanText, 1)
return text
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.
text = string.gsub(text, '[\128-\255]+', translate.words.to_en)
return text
end
else
from_en = function (text)
return text
end
end
 
local _Date, _currentDate
৭ ⟶ ১৩৯ নং লাইন:
local sandbox = frame:getTitle():find('sandbox', 1, true) and '/sandbox' or ''
local datemod = require('Module:Date' .. sandbox)
_Datelocal realDate = datemod._Date
_currentDate = datemod._current
if to_en then
_Date = function (...)
local args = {}
for i, v in ipairs({...}) do
args[i] = to_en(v)
end
return realDate(unpack(args))
end
else
_Date = realDate
end
end
return _Date, _currentDate
৫৭ ⟶ ২০০ নং লাইন:
local function message(msg, id)
-- Return formatted message text for an error or warning.
local text
if type(msg) == 'table' then
text = mtext[msg[1]] or error('bug: message not defined')
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 = mtext[msg] or error('bug: message not defined')
end
local categories = {
error = '[[Category:Age error]]',
৭৫ ⟶ ২৩১ নং লাইন:
return
a ..
mw.text.nowiki(msgtext) ..
b ..
(category or '')
২৫২ ⟶ ৪০৮ নং লাইন:
return 'error'
end
return message('Need mt-need-valid -date')
end
local add = stripToNil(args.add)
২৫৯ ⟶ ৪১৫ নং লাইন:
date = date + item
if not date then
return message({ 'Cannot mt-cannot-add "' .., item .. '"'})
end
end
২৭২ ⟶ ৪২৮ নং লাইন:
result = date[show]
if result == nil then
result = from_en(date:text(show))
elseif type(result) == 'boolean' then
result = result and '1' or '0'
else
result = from_en(tostring(result))
end
end
২৮৪ ⟶ ৪৪০ নং লাইন:
local function rangeJoin(range)
-- Return text to be used between a range of ages.
return range == 'dash' and '–' or mtext['&nbsp;txt-or ']
end
 
৩৩৫ ⟶ ৪৯১ নং লাইন:
elseif options.join == 'sep_serialcomma' and text.n > 2 then
first = ', '
last = mtext[', txt-comma-and ']
else
first = ', '
last = mtext[' txt-and ']
end
for i, v in ipairs(text) do
৩৬৯ ⟶ ৫২৫ নং লাইন:
local names = {
abbr_off = {
plural = 's',
sep = '&nbsp;',
y = 'year',
৩৮৯ ⟶ ৫৪৪ নং লাইন:
},
abbr_infant = { -- for {{age for infant}}
plural = 's',
sep = '&nbsp;',
y = 'yr',
৪৭৮ ⟶ ৬৩২ নং লাইন:
(textOptions.suffix or '')
end
return message({ 'Parameter mt-bad-show=' .., show.id .. ' is not supported here'})
end
 
৫৭৮ ⟶ ৭৩২ নং লাইন:
end
if not dates[1] then
return message(getopt.missing1 or 'Need mt-need-valid year, month, day-ymd')
end
if getopt.single then
৫৮৪ ⟶ ৭৩৮ নং লাইন:
end
if not dates[2] then
return message(getopt.missing2 or 'Second date should be year, month, daymt-need-valid-ymd2')
end
return dates[1], dates[2]
৫৯৫ ⟶ ৭৪৯ নং লাইন:
local name = frame.args.template
if not name then
return message('The mt-template invoking this must have "|template=x" where -x is the wanted operation')
end
local args = frame:getParent().args
৬৯২ ⟶ ৮৪৬ নং লাইন:
local spec = specs[name]
if not spec then
return message('The specified mt-template -bad-name is not valid')
end
if name == 'age_days' then
৭৫৬ ⟶ ৯১০ নং লাইন:
}
if (spec.negative or frame.args.negative) == 'error' and parms.diff.isnegative then
return message('The second date should not be before the first mt-date-wrong-order')
end
return from_en(dateDifference(parms))
end
 
৭৬৫ ⟶ ৯১৯ নং লাইন:
local args = frame:getParent().args
local options = {
missing1 = 'Need mt-need-valid birth date: year, month, day-bd',
noMissing = true,
single = true,
৭৭৬ ⟶ ৯৩০ নং লাইন:
local diff = Date('currentdate') - date
if diff.isnegative or diff.years > 150 then
return message('Invalid birth date for calculating mt-invalid-bd-age')
end
local disp, show = 'disp_raw', 'y'
৭৮৮ ⟶ ৯৪২ নং লাইন:
end
local df = stripToNil(args.df) -- day first (dmy); default is month first (mdy)
local result = df'(<span andclass="bday">%-Y-%m-%d</span>) </span>' ..
(df and '%-d %B %-Y' or '%B %-d, %-Y')
result = from_en('<span style="display:none"> ' ..
'%B %-d, %-Y'
result = '(<span class="bday">%-Y-%m-%d</span>) </span>' .. result
result = '<span style="display:none"> ' ..
date:text(result) ..
'<span class="noprint ForceAgeToShow"> ' ..
mtext['(txt-age&nbsp;'] ..
dateDifference({
diff = diff,
৮০৩ ⟶ ৯৫৫ নং লাইন:
sep = 'sep_space',
}) ..
')</span>')
local warnings = tonumber(frame.args.warnings)
if warnings and warnings > 0 then
৮৩২ ⟶ ৯৮৪ নং লাইন:
end
if invalid then
result = result .. message('invalid parameter{ 'mt-bad-param1', ..invalid invalid}, 'warning')
end
end
৮৪২ ⟶ ৯৯৪ নং লাইন:
local args = frame:getParent().args
local options = {
missing1 = 'Need mt-need-valid death date (first date): year, month, day-dd',
missing2 = 'Need mt-need-valid birth date (second date): year, month, day-bd2',
noMissing = true,
partial = true,
৮৫৩ ⟶ ১,০০৫ নং লাইন:
local diff = date1 - date2
if diff.isnegative then
return message('Death date (first date) must occur after birth date (second date)mt-dd-wrong-order')
end
local years
৮৬৩ ⟶ ১,০১৫ নং লাইন:
end
if years > 150 then
return message('Invalid mt-invalid-dates for calculating -age')
end
local df = stripToNil(args.df) -- day first (dmy); default is month first (mdy)
৮৮১ ⟶ ১,০৩৩ নং লাইন:
'<span style="display:none">(%-Y-00-00)</span>'
end
result = from_en(date1:text(result) ..
mtext[' (txt-aged&nbsp;'] ..
dateDifference({
diff = diff,
৮৯১ ⟶ ১,০৪৩ নং লাইন:
sep = 'sep_space',
}) ..
')')
local warnings = tonumber(frame.args.warnings)
if warnings and warnings > 0 then
৯১৪ ⟶ ১,০৬৬ নং লাইন:
end
if invalid then
result = result .. message('invalid parameter{ 'mt-bad-param1', ..invalid invalid}, 'warning')
end
end
৯৪০ ⟶ ১,০৯২ নং লাইন:
local date = Date('juliandate', args[1], args[2])
if date then
return from_en(date:text())
end
return message('Need valid Julian date numbermt-need-jdn')
end
 
৯৫৫ ⟶ ১,১০৭ নং লাইন:
return tostring(date.jd)
end
return message('Need mt-need-valid year/month/day or "currentdate"-ymd-current')
end
 
৯৭৪ ⟶ ১,১২৬ নং লাইন:
local date1 = Date(fix, 'partial', stripToNil(args[1]) or 'currentdatetime')
if not date1 then
return message('Invalid mt-invalid-start date in first parameter')
end
local date2 = Date(fix, 'partial', stripToNil(args[2]) or 'currentdatetime')
if not date2 then
return message('Invalid mt-invalid-end date in second parameter')
end
parms.diff = date2 - date1
৯৮৬ ⟶ ১,১৩৮ নং লাইন:
parm = translate[parm]
if parm == nil then -- test for nil because false is a valid setting
return message('Parameter{ ' ..mt-bad-param2', argname .. '=' .., args[argname] .. ' is invalid'})
end
parms[argname] = parm
৯৯৭ ⟶ ১,১৪৯ নং লাইন:
if show then
if show.id ~= round then
return message({ 'Parameter mt-conflicting-show=' .., args.show, args.. ' conflicts with round=' .. args.round})
end
else
১,০০৫ ⟶ ১,১৫৭ নং লাইন:
parms.round = true
end
return from_en(dateDifference(parms))
end