Module:Jctint/AUS

From blackwiki
Revision as of 05:49, 27 September 2020 by Blackwikiadmin (talk | contribs) (3 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
local p = {}

local format = mw.ustring.format
local concat = table.concat
local insert = table.insert

local roadDataModule = require("Module:Road data")

function p._jctint(args)
	-- Tracked parameters
	local msgs = {}
	local trackedParams = {}
	for key,param  in pairs(trackedParams) do
		if args[param] then
			insert(msgs, format("[[Category:Jctint template tracking category|%s %%page%%]]", key))
		end
	end
	local msg
	if #msgs > 0 then
		local page = mw.title.getCurrentTitle().prefixedText -- Get transcluding page's title
		msg = mw.ustring.gsub(concat(msgs), "%%page%%", page)
	end

	-- Extra parameters
	args.country = "AUS"
	if args.lcspan == "3" then
		args.unitary = args.location_special
		args.unitary_align = args.lcalign
		args.location_special = nil
	elseif args.lcspan == "2" then
		args.indep_city_special = args.location_special
		args.indep_city_align = args.lcalign
		args.location_special = nil
	end

	-- Parameters to be renamed
	local paramSubst = {
		region_special = "state_special",
		regionspan = "sspan",
		sub1_special = "LGA",
		sub1_note = "LGA_note",
		sub1span = "LGAspan",
		sub2span = "lspan",
		unit = "km",
		unit2 = "km2",
		place = {"tunnel", "bridge"},
		pspan = {"tspan", "bspan"}
	}
	-- Rename parameters.
	for tgt,src in pairs(paramSubst) do
		if type(src) == "table" then
			for _,param in ipairs(src) do
				args[tgt] = args[tgt] or args[param]
				args[param] = nil
			end
		else
			args[tgt] = args[tgt] or args[src]
			args[src] = nil
		end
	end

	-- Parameters to be removed
	local nilParams = {"lcalign"}
	-- Remove parameters.
	for _,param  in ipairs(nilParams) do
		args[param] = nil
	end

	local coreModule = require("Module:Jctint/core/sandbox")
	return coreModule._jctint(args) .. (msg or "")
end

function p.jctint(frame)
	-- Import module function to work with passed arguments
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)
	return p._jctint(args)
end

return p