Module:Solar eclipse
local eclipse = {}
 local args = {}
 
 local data_module_prefix = &quot;Module:Solar eclipse/db/&quot;
 
 local function ifnotempty(s,a,b)
 	if (s and s ~= '') then
 		return a
 	else
 		return b
 	end
 end
 
 local function ifexist(page)
     if not page then return false end
     if mw.title.new(page).exists then return true end
     return false
 end
 
 local function parsedate(y,m,d)
 	local lang = mw.language.getContentLanguage()
 	d = (tonumber(d) &lt; 10) and ('0' .. tonumber(d)) or (d)
 	m = (tonumber(m) &lt; 10) and ('0' .. tonumber(m)) or (m)
 	local success, result = pcall(lang.formatDate, lang, 'F j, Y', y .. '-' .. m .. '-' .. d)
 	return success and result or nil
 end
 
 local function parsecoord(frame, s)
 	local lat = s:match('^%s*([%d][%d.]*)%s*[NS]%s*[%d][%d.]*[EW]%s*$')
 	local  NS = s:match('^%s*[%d][%d.]*%s*([NS])%s*[%d][%d.]*[EW]%s*$')
 	local lon = s:match('^%s*[%d][%d.]*%s*[NS]%s*([%d][%d.]*)[EW]%s*$')
 	local  EW = s:match('^%s*[%d][%d.]*%s*[NS]%s*[%d][%d.]*([EW])%s*$')
 	if( lat and NS and lon and EW ) then
 		return frame:expandTemplate{ title = 'coord', args = {lat, NS, lon, EW, 'type:landmark'} }
 	else
 		return s
 	end
 end
 
 local function parsekm(frame, s)
 	if(s and s:match('^%s*[%d][%d.]*%s*$')) then
 		return frame:expandTemplate{ title = 'convert', args = {s, 'km','mi',abbr = 'on'} }
 	else
 		if(s and s ~= '') then
 			return s .. ' கிமீ'
 		else
 			return nil
 		end
 	end
 end
 
 local function parsetime(s)
 	if(s and s ~= '') then
 		local min = s:match('^%s*([%d][%d]*)m%s*[%d][%d]*s%s*$')
 		local sec = s:match('^%s*[%d][%d]*m%s*([%d][%d]*)s%s*$')
 		if( min and sec ) then
 			return tostring(tonumber(min)*60 + tonumber(sec)) .. '&amp;nbsp;வி' ..
 				' (' .. min .. '&amp;nbsp;நி ' .. sec .. '&amp;nbsp;வி)'
 		end
 	end
 	return s
 end
 
 local function cataloglink(c, y)
 	if(c and tonumber(c)) then
 		local y1 = math.floor( (tonumber(y) - 1) / 10 ) * 10 + 1
 		local y2 = y1 + 99
 		return '[http://eclipse.gsfc.nasa.gov/SEcat5/SE' .. tostring(y1) .. '-' .. tostring(y2) .. '.html ' .. c .. ']'
 	else
 		return c
 	end
 end
 
 local function loadsolardb(frame, s)
 	local yearstr = s:match('^%s*([%d][%d][%d][%d])[A-Z][a-z][a-z][%d][%d]%s*$') or ''
 	local function setarg(k, v)
 		if(v and v ~= '') then args[k] = v end
 	end
 	if( yearstr ~= '' ) then
 		local dbsubpage = math.floor( (tonumber(yearstr) - 1) / 50 ) * 5
 		local dbpage  = data_module_prefix .. tostring( dbsubpage )
 		if (ifexist(dbpage)) then
 			local data = mw.loadData(dbpage)
 			local dargs = data[s]
 			setarg('date', parsedate(dargs['y'], dargs['m'] or dargs['m3'] or dargs['m2'], dargs['d'] or dargs['d2']))
 			setarg('image', (dargs['Ph'] and dargs['Ph'] ~= '') and '[[File:' .. dargs['Ph']  .. '|320px]]' or nil)
 			setarg('caption', dargs['PhCap'])
 			setarg('map', (dargs['Map'] and dargs['Map'] ~= '') and '[[File:' .. dargs['Map']  .. '|320px]]' or nil)
 			setarg('map_caption', 'Map')
 			setarg('type_ref', '')
 			setarg('cat', cataloglink(dargs['Cat'], dargs['y']) )
 			setarg('nature', dargs['Ty'])
 			setarg('gamma', dargs['Gam'])
 			setarg('magnitude', dargs['Mag'])
 			setarg('saros', dargs['Saros'] and '[[Solar Saros ' .. dargs['Saros'] .. '|'  .. dargs['Saros'] .. ']]')
 			setarg('saros_sequence', dargs['Mem'])
 			setarg('saros_total', dargs['Max'])
 			setarg('max_eclipse_ref', '')
 			setarg('duration', parsetime(dargs['Dur']))
 			setarg('location', '')
 			setarg('coords', parsecoord(frame,dargs['Loc']))
 			setarg('max_width', parsekm(frame,dargs['Wid']))
 			setarg('times_ref', '')
 			setarg('start_partial', dargs['TiPB'])
 			setarg('start_total', dargs['TiTB'])
 			setarg('start_central', '')
 			setarg('greatest_eclipse', dargs['TiG'])
 			setarg('end_central', '')
 			setarg('end_total', dargs['TiTE'])
 			setarg('end_partial', dargs['TiPE'])
 		end
 	end
 end
 
 local function infobox(frame)
 	local abovestr = ifnotempty(args['date'], 
 		&quot;''&quot; .. (args['date'] or '') .. &quot;''-இல் நிகழ்ந்த கதிரவ மறைப்பு&quot;,
 		&quot;, see [[Template:Infobox Solar eclipse]]&quot;)
 	local bgcolor = args['background'] or args['bgcolour'] or ''
 	local mapstr = ifnotempty(args['map'],
 		&quot;&lt;div style='padding-bottom:0.5em;'&gt;&quot; .. 
 		(args['map'] or '') .. ifnotempty(args['map_caption'], 
 			&quot;&lt;div style='line-height:1.2em; padding-top:0.1em;'&gt;&lt;small&gt;&quot; ..
 			(args['map_caption'] or '') .. &quot;&lt;/small&gt;&lt;/div&gt;&quot;, '') .. '&lt;/div&gt;')
 
 	return frame:expandTemplate{ title = 'infobox', args = {
 		[&quot;bodyclass&quot;] = &quot;vevent&quot;,
 		[&quot;bodystyle&quot;] = &quot;width:25em; text-align:left; font-size:90%;&quot;,
 		[&quot;above&quot;] = abovestr,
 		[&quot;aboveclass&quot;] = &quot;summary&quot;,
 		[&quot;abovestyle&quot;] = &quot;padding-bottom:0.25em; background:&quot; .. bgcolor .. &quot;; line-height:1.2em; text-align:center; font-size:115%;&quot;,
 ------------------ Images and maps ------------------
 		[&quot;image&quot;] = args['image'] or '',
 		[&quot;imagestyle&quot;] = &quot;padding-bottom:0.5em;&quot;,
 		[&quot;caption&quot;] = args['caption'] or '',
 		[&quot;captionstyle&quot;] = &quot;padding-top:0.1em; line-height:1.2em; font-size:90%;&quot;,
 		[&quot;headerstyle&quot;] = &quot;background:#eee; font-size:105%;&quot;,
 		[&quot;labelstyle&quot;] = &quot;padding:0 0.5em 0 0; line-height:1.1em;&quot;,
 		[&quot;datastyle&quot;] = &quot;padding:0; line-height:1.2em; vertical-align:middle;&quot;,
 		[&quot;data1&quot;] = mapstr,
 ------------- Type of eclipse and saros -------------
 		[&quot;header2&quot;] = &quot;மறைப்பின் வகை&quot; .. (args['type_ref'] or ''),
 		[&quot;label3&quot;]  = &quot;இயல்பு&quot;,
 		[&quot;data3&quot;]   = args['nature'] or '',
 		[&quot;label4&quot;]  = &quot;[[காம்மா (கிரகணம்)|காம்மா]]&quot;,
 		[&quot;data4&quot;]   = args['gamma'] or '',
 		[&quot;label5&quot;]  = &quot;[[மறைப்பின் அளவு|அளவு]]&quot;,
 		[&quot;data5&quot;]   = args['magnitude'] or '',
 ------------------ Maximum eclipse ------------------
 		[&quot;header7&quot;] = &quot;அதியுயர் மறைப்பு&quot; .. (args['max_eclipse_ref'] or ''),
 		[&quot;label8&quot;] = &quot;காலம்&quot;,
 		[&quot;data8&quot;] = args['duration'] or '',
 		[&quot;label9&quot;] = &quot;இடம்&quot;,
 		[&quot;data9&quot;] = args['location'] or '',
 		[&quot;class9&quot;] = &quot;location&quot;,
 		[&quot;label10&quot;] = &quot;ஆள் கூறுகள்&quot;,
 		[&quot;data10&quot;] = args['coords'] or '',
 		[&quot;label11&quot;] = &quot;பட்டையின் அதியுயர் அகலம்&quot;,
 		[&quot;data11&quot;] = args['max_width'] or '',
 ----------------------- Times -----------------------
 		[&quot;header12&quot;] = &quot;நேரங்கள் ([[UTC]])&quot; .. (args['times_ref'] or ''),
 		[&quot;label13&quot;] = &quot;(P1) பகுதி கிரகணம் துவக்கம்&quot;,
 		[&quot;data13&quot;] = args['start_partial'] or '',
 		[&quot;label14&quot;] = &quot;(U1) முழு கிரகணம் துவக்கம்&quot;,
 		[&quot;data14&quot;] = args['start_total'] or '',
 		[&quot;label15&quot;] = &quot;(U2) நடு மறைப்பு துவக்கம்&quot;,
 		[&quot;data15&quot;] = args['start_central'] or '',
 		[&quot;label16&quot;] = &quot;பெரும் மறைப்பு&quot;,
 		[&quot;data16&quot;] = args['greatest_eclipse'] or '',
 		[&quot;label17&quot;] = &quot;(U3) நடு மறைப்பு முடிவு&quot;,
 		[&quot;data17&quot;] = args['end_central'] or '',
 		[&quot;label18&quot;] = &quot;(U4) முழு மறைப்பு முடிவு&quot;,
 		[&quot;data18&quot;] = args['end_total'] or '',
 		[&quot;label19&quot;] = &quot;(P4) பகுதி கிரகணம் முடிவு&quot;,
 		[&quot;data19&quot;] = args['end_partial'] or '',
 ------------------------ Event references -------------------------
 		[&quot;header20&quot;] = &quot;மேற்கோள்கள்&quot;,
 		[&quot;label21&quot;] = &quot;[[சாரோசு (வானியல்)|சாரோசு]]&quot;,
 		[&quot;data21&quot;] = (args['saros'] or '') 	.. &quot; (&quot; .. (args['saros_sequence'] or '') .. &quot; of &quot; .. (args['saros_total'] or '') .. &quot;)&quot;,
 		[&quot;label22&quot;] = &quot;அட்டவணை # (SE5000)&quot;,
 		[&quot;data22&quot;] = args['cat'] or '',
 		} }
 	
 end
 
 function eclipse.box(frame)
 	args = require('Module:Arguments').getArgs(frame, {
 			wrappers = 'Template:Infobox solar eclipse'
 		})
 
 	if( args['2'] and args['2'] ~= '') then
 		loadsolardb(frame,args['2'])
 	elseif( args['1'] and args['1'] ~= '') then
 		loadsolardb(frame,args['1'])
 	end
 	
 	return infobox(frame)
 end