Module:Infobox road
local p = {}
 local getArgs = require('Module:Arguments').getArgs
 local util = require(&quot;Module:Road data/util&quot;)
 local yesno = require('Module:Yesno')
 local langModule = require('Module:Lang')
 local routeModule = require(&quot;Module:Infobox road/route&quot;)
 local parserModule = require(&quot;Module:Road data/parser&quot;)
 local parser = parserModule.parser
 local format = mw.ustring.format
 local frame = mw.getCurrentFrame()
 
 local function country(args)
 	local state = args.state or args.province
 	local country
 	local countryModule = mw.loadData(&quot;Module:Road data/countrymask&quot;)
 	local country = args.country or countryModule[state]
 	
 	return country
 end
 
 -- HEADER COLORS
 
 function p.headerStyle(frame)
 	local args = getArgs(frame)
 	local header 
 		if args.header_type == nil then
 			header = args.header_type
 		else
 			header = string.lower(args.header_type)
 		end
 		
 	local deleted = args.decommissioned or args.deleted or header == &quot;former&quot;
 	local uc = header == &quot;under construction&quot; or header == &quot;const&quot; or header == &quot;uc&quot;
 	local minor = header == &quot;minor&quot;
 	local hist = header == &quot;hist&quot; or header == &quot;historic&quot; or header == &quot;historical&quot; or header == &quot;scenic&quot;
 	local color = parser(args, 'color') or args['header_color']
 	local freeway = header == &quot;freeway&quot;
 	
 	if freeway then
 		return &quot;header-MUTCDblue&quot;
 	elseif uc then
 		return &quot;header-uc&quot;
 	elseif minor then
 		return &quot;header-minor&quot;
 	elseif deleted and header == 'hist' or deleted and color == 'hist' then
 		return &quot;header-deleted-hist&quot;
 	elseif deleted then
 		return &quot;header-deleted&quot;
 	elseif hist then
 		return &quot;header-hist&quot;
 	elseif color then
 		return &quot;header-&quot; .. color
 	elseif args.state or args.province or args.country then
 		local country = country(args)
 		return &quot;header-&quot; .. country or &quot;header-default&quot;
 	else
 		return &quot;header-default&quot;
 	end
 end
 
 -- SECOND IMAGE
 
 local function photo(args)
 	local country = country(args)
 	local photo = args.photo or args.image
 	local width = args.photo_wide or args.image_width or &quot;290px&quot;
 	local alt = args.photo_alt or args.image_alt or photo
 	
 	if photo == nil then
 		return nil
 	elseif country == &quot;USA&quot; then
 		return nil
 		else return string.format('[[File:%s|%s|alt=%s]]', photo, width, alt)
 	end
 end
 
 function p.photo(frame)
 	local args = getArgs(frame)
 	return photo(args)
 end
 
 -- TRANSLATION
 
 local function translate(args, lang)
 	local lang = parser(args, 'lang') or args.lang or 'none'
 	local translation = args.translation or parser(args, 'translation') or ''
 	
 	if country(args) == &quot;PAK&quot; and translation ~= '' then
 		local route = args.route
 		
 		if route ~= nil then
 			local arabicModule = require( &quot;Module:Convert to eastern arabic numerals&quot; )
 			local arabic = arabicModule._convert({route})
 			local translated = string.gsub( translation, route, arabic)
 		
 			return frame:expandTemplate{title = 'Nastaliq', args = {translated}}
 		else
 			return frame:expandTemplate{title = 'Nastaliq', args = {translation}}
 		end
 	elseif translation ~= '' and lang == 'none' then
 		return translation
 	elseif country(args) == &quot;CHN&quot; and args.type == &quot;Expwy&quot; then
 		local trans = require( &quot;Module:Road data/masks/CHN/Expwy translations&quot; )
 		local route = args.route
 		
 		return langModule._lang({lang, trans[route]})
 	elseif country(args) == &quot;HUN&quot; then
 		local nominal = require( &quot;Module:Road data/masks/HUN&quot; )
 		local routeNum
 		local leading
 		
 			if string.len(args.route) &gt; 2 then
 				routeNum = string.match(args.route, &quot;%d%d$&quot;, 0)
 				leading = string.match(args.route, &quot;(%d*)%d%d$&quot;, 0)
 			else
 				routeNum = args.route
 				leading = ''
 			end
 		
 		if args.type == &quot;M&quot; then
 			return langModule._lang({&quot;hu&quot;, &quot;M&quot; .. leading .. nominal[routeNum] .. &quot; autópálya&quot;})
 		elseif args.type == &quot;Mb&quot; then
 			return langModule._lang({&quot;hu&quot;, &quot;M&quot; .. leading .. nominal[routeNum] .. &quot; autóút&quot;})
 		elseif args.type == &quot;MR&quot; then
 			return langModule._lang({&quot;hu&quot;, leading .. nominal[routeNum] .. &quot; főút&quot;})
 		elseif args.type == &quot;Mb&quot; then
 			return langModule._lang({&quot;hu&quot;, leading .. nominal[routeNum] .. &quot; közút&quot;})
 		end
 	elseif lang == &quot;ar&quot; and translation ~= '' then
 		local route = args.route
 		local arabicModule = require( &quot;Module:Convert to eastern arabic numerals&quot; )
 		local arabic = arabicModule._convert({route})
 		local translated = string.gsub( translation, route, arabic)
 		
 		return langModule._lang({lang, translated})
 	elseif translation ~= '' and lang ~= 'none' then
 		return langModule._lang({lang, translation})
 	else
 		return nil
 	end
 end
 
 function p.translate(frame)
 	local pframe = frame:getParent()
     local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
     local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
     
     local lang = config.lang
 	return translate(args, lang)
 end
 
 -- MAINTAINED BY
 
 local function maint(args)
 	local maint = args.maint or parser(args, 'maint') or ''
 	if maint == &quot;none&quot; or maint == '' then
 		return nil
 	else
 		return &quot;Maintained by &quot; .. maint
 	end
 end
 
 function p.maint(frame)
 	local args = getArgs(frame)
 	return maint(args)
 end
 
 -- DEFINED BY LAW
 
 local function law(args)
 	local law = parser(args, 'law') or ''
 	if args.section == '' then
 		return nil
 	else
 		return &quot;Defined by &quot; .. law
 	end
 end
 
 function p.law(frame)
 	local args = getArgs(frame)
 	return law(args)
 end
 
 -- EXISTED
 
 function p._existed(args)
 	local formed = args.established or args.formed or ''
 	local deleted = args.decommissioned or args.deleted or ''
 	
 	if formed == '' then
 		return nil
 	elseif deleted == '' then
 		return formed .. &quot;–present&quot;
 	else
 		return formed .. &quot;–&quot; .. deleted
 	end
 end
 
 function p.existed(frame)
 	local args = getArgs(frame)
 	return p._existed(args)
 end
 
 -- TIME PERIOD
 
 local function period(args)
 	
 	local infobox_args = {}
 	
 	infobox_args['bodystyle'] = 'display:inline-table;'
 	infobox_args['child'] = 'yes'
 	infobox_args['decat'] = 'yes'
 	infobox_args['label1'] = &quot;Time period&quot;
 	infobox_args['data1'] = args.time_period
 	
 	if args.time_period then
 		infobox_args['label2'] = &quot;Cultural significance&quot;
 		infobox_args['data2'] = args.significance
 		infobox_args['label3'] = &quot;Known for&quot;
 		infobox_args['data3'] = args.known_for
 		infobox_args['label4'] = &quot;Related routes&quot;
 		infobox_args['data4'] = args.related
 	else
 		infobox_args['label3'] = &quot;Known for&quot;
 		infobox_args['data3'] = args.known_for
 	end
 
 	return frame:expandTemplate ({title='Infobox', args = infobox_args})
 end
 
 local function period_params(args)
 
 	if args.time_period or args.known_for then
 		return true
 	else
 		return false
 	end
 end
 
 function p.period(frame)
 	local args = getArgs(frame)
 	
 	if period_params(args) == false then
 			return nil
 		else
 			return period(args)
 		end
 	end
 
 -- ALLOCATION
 
 local function allocation(args)
 	local country = country(args)
 	
 	if country == &quot;AUS&quot; then
 		return &quot;[[Route number#Australia|Allocation]]&quot;
 		else return &quot;Component&lt;br&gt;highways&quot;
 	end
 end
 
 function p.allocation(frame)
 	local args = getArgs(frame)
 	return allocation(args)
 end
 
 -- SPUR OF
 
 local function spurOf(args)
 	local state = args.state or args.province
 	local country = args.country
 	local county = args.county
 	local parentType = args.spur_type
 	local parentRoute = args.spur_of
 	local aux = parser(args, 'aux') or &quot;Auxiliary route&quot; or nil
 	local jct = frame:expandTemplate{
 			title = 'jct', args = {
 				state = state,
 				country = country,
 				county1 = county,
 				parentType,
 				parentRoute,
 				noshield1 = &quot;yes&quot;
 			}
 		}
 
 	if not parentType and not parentRoute then
 		return nil
 	elseif type(aux) == &quot;table&quot; then
 		return &quot;Auxiliary route of &quot; .. jct
 		else return tostring(aux) .. &quot; of &quot; .. jct
 	end
 end
 
 function p.spurOf(frame)
 	local args = getArgs(frame)
 	return spurOf(args)
 end
 
 -- PART OF
 
 local function partOf(args)
 	
 	if args[&quot;e-road&quot;] or args.ahn or args.tahn or args.mrn then
 
 		local infobox_args = {}
 		
 		infobox_args['bodystyle'] = 'display:inline-table;'
 		infobox_args['child'] = 'yes'
 		infobox_args['decat'] = 'yes'
 
 		if args[&quot;e-road&quot;] then
 			local eshield = args[&quot;e-road-shield&quot;] or ''
 			infobox_args['data1'] = eshield .. &quot; Part of &quot; .. args[&quot;e-road&quot;]
 		end
 		if args.ahn then
 			local ashield = args[&quot;ahn-shield&quot;] or ''
 			infobox_args['data2'] = ashield .. &quot; Part of &quot; .. args.ahn
 		end
 		if args.tahn then
 			local tshield = args[&quot;tahn-shield&quot;] or ''
 			infobox_args['data3'] = tshield .. &quot; Part of &quot; .. args.tahn
 		end
 		if args.mrn then
 			local mshield = args[&quot;mrn-shield&quot;] or ''
 			infobox_args['data4'] = mshield .. &quot; Part of &quot; .. args.mrn
 		end
 		
 		return frame:expandTemplate ({title='Infobox', args = infobox_args})
 		
 	else return nil
 	end	
 end
 
 function p.partOf(frame)
 	local args = getArgs(frame)
 	return partOf(args)
 end
 
 --BROWSE LINKS
 
 local function browse(args)
 	if args.nobrowse then return nil end
 	
 	local previousRoute = args.previous_route
 	local nextRoute = args.next_route
 	if previousRoute or nextRoute then
 		local box = mw.html.create('table'):cssText(&quot;width:100%; background:none; border-collapse:collapse; display:inline-table;&quot;)
 		local boxModule = require &quot;Module:Road data/browse&quot;
 		local primary = boxModule._browse(args)
 		box:wikitext(primary)
 		return tostring(box)
 	end
 end
 
 function p.browse(frame)
 	local args = getArgs(frame)
 	return browse(args)
 end
 
 local function extended(args)
 	local extended = args.browse
 	if args.nobrowse or extended == nil then
 		return nil 
 	else
 		local box = mw.html.create('table'):cssText(&quot;width:100%; background:none; border-collapse:collapse; display:inline-table;&quot;)
 		box:wikitext(extended)
 		return tostring(box)
 	end
 end
 
 function p.extended(frame)
 	local args = getArgs(frame)
 	return extended(args)
 end
 
 -- HIGHWAY SYSTEM LINKS
 
 local function system(args)
 	if args.system1 then
 		
 	local infobox_args = {
 		['child'] = &quot;yes&quot;,
 		['decat'] = &quot;yes&quot;,
 		['bodystyle'] = &quot;border-collapse:collapse;&quot;
 	}
 		
 		
 	local i = 1
 	while (1) do
 		local systemClassn = &quot;class&quot; .. i
 		local systemDatan = &quot;data&quot; .. i
 		local systemArgn = args['system' .. i]
 		
 		infobox_args[systemClassn] = &quot;hlist&quot;
 		infobox_args[systemDatan] = systemArgn
 		
 			if i == 10 then
 				break
 			else
 				i = i + 1
 			end
 		end
 	
 	return frame:expandTemplate ({title='Infobox', args = infobox_args})
 	end
 end
 
 function p.system(frame)
 	local args = getArgs(frame)
 	return system(args)
 end
 
 -- ROUTE INFORMATION HEADER
 
 local function info(args)
 	local maint = maint(args)
 	local law = law(args)
 	local period = period_params(args)
 	local existed = args.established or args.formed or nil
 	local spur = args.spur_type or args.spur_of or nil
 	local part = partOf(args)
 	
 	if period == true or spur ~= nil or part ~= nil or existed ~= nil or maint ~= nil or args.section or args.length_mi or args.length_km or args.allocation or args.history or args.restrictions or args.tourist or args.status or args.margary then
 		return &quot;வழித்தட தகவல்கள்&quot;
 	else
 		return nil
 	end
 end
 
 function p.info(frame)
 	local args = getArgs(frame)
 	return info(args)
 end
 
 -- HIGHWAY SYSTEM HEADER
 
 local function highwaySystem(args)
 	if args.nobrowse then return nil end
 	local country = country(args) or args.countries
 	
 	if country == nil then
 		return nil
 	elseif country == &quot;GBR&quot; or country == &quot;ENG&quot; or country == &quot;NIR&quot; or country == &quot;SCT&quot; or country == &quot;WLS&quot; or
 		country == &quot;GGY&quot; or country == &quot;IMN&quot; or country == &quot;JEY&quot; or country == &quot;AIA&quot; or country == &quot;BMU&quot; or
 		country == &quot;IOT&quot; or country == &quot;VGB&quot; or country == &quot;CYM&quot; or country == &quot;FLK&quot; or country == &quot;GIB&quot; or
 		country == &quot;MSR&quot; or country == &quot;PCN&quot; or country == &quot;SHN&quot; or country == &quot;SGS&quot; or country == &quot;TCA&quot; then
 		return &quot;Road network&quot;
 		else return &quot;Highway system&quot;
 	end
 end
 
 function p.highwaySystem(frame)
 	local args = getArgs(frame)
 	return highwaySystem(args)
 end