Module:Infobox road/name/CAN

local p = {}

local format = string.format

local typesModule = require "Module:Infobox road/name/defs" Country = typesModule.Country Type = typesModule.Type Name = typesModule.Name

local names = Country:new do -- Name definitions function names:typeOverride(args) local type = args.type local province = args.province if type == province then return self["Hwy"] else return nil end end do -- Provincial highways local type = Type:new do           local types = {"Fwy", "Hwy", "PTH", "Route", "2ndHwy", "TCH"} for i,v in ipairs(types) do               names[v] = type end end do -- Highway local provinces = {"AB", "BC", "SK", "MB"} local name = Name:new{formatStr = "Highway %s"} for i,v in ipairs(provinces) do               type[v] = name end end -- Highway do -- Route local provinces = {"QC", "NB", "PE", "NL"} local name = Name:new{formatStr = "Route %s"} for i,v in ipairs(provinces) do               type[v] = name end end -- Route do -- Nova Scotia local function processTypeExceptions(exceptions, default, formatArgs) return function (args) local formatArguments = {} for i,v in ipairs(formatArgs) do                       formatArguments[i] = args[v] end local type = args.type local formatStr = exceptions[type] or default args.override = format(formatStr, unpack(formatArguments)) end end local typeExceptions = {["Hwy"] = "Highway %s", ["NS"] = "Highway %s", ["Route"] = "Route %s"} local preprocessor = processTypeExceptions(typeExceptions, '', {"route"}) type["NS"] = Name:new{formatStr = "%s", formatArgs = {"override"}, preprocessors = {preprocessor}} end -- Nova Scotia do -- Ontario local exceptions = {["QEW"] = "Queen Elizabeth Way"} type["ON"] = Name:new{formatStr = "Highway %s", exceptions = exceptions} end -- Ontario end -- Provincial highways do -- Trunk highways (Nova Scotia) local type = Type:new names["Trunk"] = type type["NS"] = Name:new{formatStr = "Trunk %s"} end -- Trunk highways (Nova Scotia) do -- Autoroutes (Quebec) local name = Name:new{formatStr = "Autoroute %s"} names["A"] = name names["Autoroute"] = name end -- Autoroutes (Quebec) names["CR"] = Name:new{formatStr = "%s County Road %s", formatArgs = {"county", "route"}} -- County roads names["RR"] = Name:new{formatStr = "%s Regional Road %s", formatArgs = {"county", "route"}} -- Regional roads names["MR"] = Name:new{formatStr = "%s Municipal Road %s", formatArgs = {"county", "route"}} -- Municipal roads names["PR"] = Name:new{formatStr = "Provincial Road %s"} -- Provincial roads do -- Secondary and Teritary Highways local name = Name:new{formatStr = "Highway %s"} names["Sec"] = name names["Secondary"] = name names["Tert"] = name names["Tertiary"] = name end -- Secondary and Teritary Highways end -- Name definitions

p.names = names return p