Jump to content

Module:Jct/city

From Simple English Wikipedia, the free encyclopedia
Revision as of 02:15, 5 June 2014 by Happy5214 (talk | changes) (Sync with sandbox: Allow unlimited locations and calling from Module:Jct)

Documentation for this module may be created at Module:Jct/city/doc

local p = {}

local state

local function stateName(args)
	local dualabbrs = {NT = "Northern Territory", WA = "Western Australia"}
	
	local data = mw.loadData("Module:Jct/statename/data")
	local abbr = args.state or args.province
	local country = args.country
	if country == 'AUS' then
		return dualabbrs[abbr] or data.statenames[abbr]
	else
		return data.statenames[abbr]
	end
end

local function location(args, num)
	local city = args["city" .. num]
	local location = args["location" .. num]
	local areadab = args["areadab" .. num]
	local countydab = args["countydab" .. num]
	
	if not(city or location) then
		return ''
	end
	
	local parts
	if num == 1 then
		parts = {" – "}
	else
		parts = {", "}
	end
	
	if location then
		table.insert(parts, location)
		return table.concat(parts)
	end
	
	table.insert(parts, "[[" .. city)
	if areadab then
		table.insert(parts, " (" .. areadab .. ")")
	end
	if countydab then
		table.insert(parts, ", " .. countydab .. " County")
	end
	if state then
		table.insert(parts, ", " .. state)
	end
	
	table.insert(parts, "|" .. city .. "]]")
	return table.concat(parts)
end

function p.city(args)
	state = stateName(args)
	local cities = {}
	local locationCount = 1
	repeat
		local location = location(args, locationCount)
		table.insert(cities, location)
		local empty = (location == '')
		locationCount = locationCount + 1
	until empty
	return table.concat(cities)
end

return p