return navr..'|}'
end
end  
--======================================================  
local function nav_nordinal( , firstpart, ord, lastpart, minimumord, maximumord )
local nord = tonumber(ord)
local minord = tonumber(string.match(minimumord or '', '(-?%d+)')) or -9999 --allow full ord & +/- qualifier
local maxord = tonumber(string.match(maximumord or '', '(-?%d+)')) or 9999 --allow full ord & +/- qualifier
if string.match(minimumord or '', 'கிமு') then minord = -math.abs(minord) end --allow BC qualifier (AD otherwise assumed)
if string.match(maximumord or '', 'கிமு') then maxord = -math.abs(maxord) end --allow BC qualifier (AD otherwise assumed)
local th = '-ஆம்' --adding for tawiki  
local temporal = string.match(lastpart, 'நூற்றாண்டு') or
string.match(lastpart, 'ஆயிரமாண்டு')  
local tspace = ' ' --assume a trailing space after ordinal
if string.match(lastpart, '^(- )') then tspace = '' end --DNE for "19th-century"-type cats  
--AD/BC switches & vars  
local ordBCElastparts = { --needed for parent = AD 1-5, when the BC/E format is unknown
--lists the lastpart of valid BCE cats
--"BCE" removed to match both AD & BCE cats; easier & faster than multiple string.matchs
['-century Hebrew people'] = 'BCE', --WP:CFD/Log/2016 June 21#Category:11th-century BC Hebrew people
['-century Jews'] = 'BCE', --co-nominated
['-century Judaism'] = 'BCE', --co-nominated
['-century rabbis'] = 'BCE', --co-nominated
['-century High Priests of Israel'] = 'BCE',
}
local parentBC = mw.ustring.match(lastpart, '%s(BCE?)') --"1st-century BC" format
local lastpartNoBC = mw.ustring.gsub(lastpart, '%sBCE?', '') --easier than splitting lastpart up in 2; AD never used
local BCe = parentBC or ordBCElastparts[lastpartNoBC] or 'கிமு' --"BC" default  
local switchADBC = 1 -- 1=AD parent
if parentBC then switchADBC = -1 end -- -1=BC parent; possibly adjusted later
local O = 0 --secondary iterator for AD-on-a-BC-parent  
if not temporal and minord < 1 then minord = 1 end --nothing before "1st parliament", etc.
if minord > nord*switchADBC then minord = nord*switchADBC end --input error; minord should be <= parent
if maxord < nord*switchADBC then maxord = nord*switchADBC end --input error; maxord should be >= parent  
--begin navnordinal
local bnb = '' --/no
if navborder == false then --for Navseasoncats decade and century
bnb = ' -style: ; background-color: transparent;'
end
local navo = '{|\n'..'|\n'  
local i = -5 --nav position
while i <= 5 do
local o = nord + i*switchADBC
local BC = ''
local BCdisp = ''
if parentBC then
if switchADBC == -1 then --parentBC looking at the BC side
if o >= 1 then --the common case
BC = BCe..' '
elseif o == 0 then --switch to the AD side
BC = ''
switchADBC = 1
end
end
if switchADBC == 1 then --displayed o is now in the AD regime
O = O + 1 --skip o = 0 (DNE)
o = O --easiest solution: start another iterator for these AD o's displayed on a BC year parent
end
elseif o <= 0 then --parentAD looking at BC side
BC = BCe..' '
o = math.abs(o - 1) --skip o = 0 (DNE)
end
if BC ~= '' and nord <= 5 then --only show 'BC' for parent ords <= 5: saves room, easier to read,
BCdisp = BCe..' ' --and 6 is the first/last nav ord that doesn't need a disambiguator;
end --the /parent ord will always show BC, so no need to show it another 10x  
--populate / navo
local oth = p.addord(o)
local osign = o --use o for display & osign for logic
if BC ~= '' then osign = -osign end
local hidden = '<span>'..oth..'</span>'
if temporal then --e.g. "3rd-century BC"
local lastpart = lastpartNoBC --lest we recursively add multiple "BC"s
if BC ~= '' then
lastpart = string.gsub(lastpart, temporal, temporal..BC) --replace BC if needed
end
lastpart = string.gsub(lastpart, th..' '..temporal, temporal) --replace '-ஆம் ' in century or millenium categories
local catlink = catlinkfollowr( , firstpart..' '..oth..tspace..lastpart, BCdisp..oth)
if (minord <= osign) and (osign <= maxord) then
if catlink.rtarget then --a was followed
trackcat(23, 'Navseasoncats nordinal redirected')
end
navo = navo..navcenter(i, catlink)
else
navo = navo..'*'..hidden..'\n'
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
end
end
elseif BC == '' and minord <= osign and osign <= maxord then --e.g. >= "1st parliament"
local catlink = catlinkfollowr( , firstpart..' '..oth..tspace..lastpart, oth )
if catlink.rtarget then --a was followed
trackcat(23, 'Navseasoncats nordinal redirected')
end
navo = navo..navcenter(i, catlink)
else --either out-of-range (hide), or non-temporal + BC = something might be wrong (2nd X parliament BC?); handle exceptions if/as they arise
navo = navo..'*'..hidden..'\n'
end  
i = i + 1
end  
isolatedcat
if listall then
return listalllinks
else
return navo..'|}'
end
end  
--======================================================  
local function nav_wordinal( , firstpart, word, lastpart, minimumword, maximumword, ordinal, )
--Module:ConvertNumeric.numeral_to_english flags:
-- ordinal == 'on': 'second' is output instead of 'two'
-- ordinal ~= 'on': 'two' is output instead of 'second'
local ord2eng = require('Module:ConvertNumeric').numeral_to_english
local eng2ord = require('Module:ConvertNumeric').english_to_ordinal
local th = 'ஆம்'
if ordinal ~= 'on' then
th = ''
eng2ord = require('Module:ConvertNumeric').english_to_numeral
end
local sc = string.match(word, '^%u') --sentence-case check
local lc = string.lower(word) --operate on/with lc, and restore any sc later
local nord = eng2ord(lc)
local case = nil
if sc then case = 'U' end  
local lspace = ' ' --assume a leading space (most common)
local tspace = ' ' --assume a trailing space (most common)
if string.match(firstpart, '[%-%(]$') then lspace = '' end --DNE for "Straight-eight engines"-type cats
if string.match(lastpart, '^[%-%)]' ) then tspace = '' end --DNE for "Nine-cylinder engines"-type cats  
--sterilize min/max
local minword = 1
local maxword = 99
if minimumword then
local num = tonumber(minimumword)
if num and 0 < num and num < maxword then
minword = num
else
local ord = eng2ord(minimumword)
if 0 < ord and ord < maxword then
minword = ord
end
end
end
if maximumword then
local num = tonumber(maximumword)
if num and 0 < num and num < maxword then
maxword = num
else
local ord = eng2ord(maximumword)
if 0 < ord and ord < maxword then
maxword = ord
end
end
end
if minword > nord then minword = nord end
if maxword < nord then maxword = nord end  
--begin navwordinal
local navw = '{|\n'..'|\n'  
local i = -5 --nav position
while i <= 5 do
local n = nord + i  
if n >= 1 then
local nth = p.addord(n)
if ordinal ~= 'on' then nth = n end
if i ~= 0 then --/ navw
local frame_args = :newChild{ args = { n, ord = ordinal, case = case } } --easier to do this than modify Module:ConvertNumeric
local w = ord2eng( frame_args )
local catlink = catlinkfollowr( , firstpart..lspace..w..tspace..lastpart, nth )
if minword <= n and n <= maxword then
if catlink.rtarget then --a was followed
trackcat(24, 'Navseasoncats wordinal redirected')
end
navw = navw..'*'..catlink.navelement..'\n'
else
local hidden = '<span>'..nth..'</span>'
navw = navw..'*'..hidden..'\n'
if listall then
tlistall[#tlistall] = tlistall[#tlistall]..' ('..hidden..')'
end
end
else -- navw
navw = navw..'*<b>'..nth..'</b>\n'
end
else
navw = navw..'*<span>'..'0'..th..'</span>\n'
end  
i = i + 1
end  
isolatedcat
if listall then
return listalllinks
else
return navw..'|}'
end
end  
--==========================================================  
local function find_var( pn )
--Extracts the variable text (e.g. 2015, 2015–16, 2000s, 3rd, III, etc.) from a string,
--and returns { ['vtype'] = <'year'|'season'|etc.>, <v> = <2015|2015–16|etc.> }
local pagename = currtitle.text
if pn and pn ~= '' then
pagename = pn
end  
local cpagename = '  
local d_season = mw.ustring.match(cpagename, ':(%d+s).+%(%d+[–-]%d+%)') --i.e. "1760s in the Province of Quebec (1763–1791)"