Module:Infobox/Widget/Location: Difference between revisions

From TwogPedia
No edit summary
mNo edit summary
Tag: Manual revert
 
(13 intermediate revisions by the same user not shown)
Line 5: Line 5:
local Location = {}
local Location = {}


function Location.make(args)
function Location.make(countries, cities, category, state)
local index = 1
local current = args['country']
local currentLocation = args['city'] or args['location']
local container = mw.html.create('div')
local container = mw.html.create('div')
local countryList = mw.text.split(countries, ',')
while not String.isEmpty(current) do
for i, v in ipairs(countryList) do
local country = CountryData[string.upper(current)]
v = mw.text.trim(v)
mw.log('current: ' .. current)
local country = CountryData[string.upper(v)]
mw.log('country')
mw.log(country)
local currentTitle = mw.title.getCurrentTitle().text
local currentTitle = mw.title.getCurrentTitle().text
local gameCategory = mw.text.split(currentTitle, '/')[1]
local gameCategory = mw.text.split(currentTitle, '/')[1]
local flag = Flags.icon(country, gameCategory)
local flag = Flags.icon(country, category or gameCategory)
mw.log('flag: ' .. flag)
local div = mw.html.create('div')
local countryNode = mw.html.create('div')
:addClass('flag')
:node(flag)
:wikitext(flag)
:wikitext(country)
if cities then
container:node(country)
div:wikitext(mw.text.trim(mw.text.split(cities, ',')[i]))
else
index = index + 1
div:wikitext(country)
current = args['country' .. index]
end
currentLocation = args['city' .. index] or args['location' .. index]
if state then div:wikitext(', ' .. state) end
container:node(div)
end
end

Latest revision as of 17:47, 2 October 2023

Documentation for this module may be created at Module:Infobox/Widget/Location/doc

local CountryData = mw.loadData('Module:Localisation/Data')
local Flags = require('Module:Flags')
local String = require('Module:StringUtils')

local Location = {}

function Location.make(countries, cities, category, state)
	local container = mw.html.create('div')
	local countryList = mw.text.split(countries, ',')
	
	for i, v in ipairs(countryList) do
		v = mw.text.trim(v)
		local country = CountryData[string.upper(v)]
		local currentTitle = mw.title.getCurrentTitle().text
		local gameCategory = mw.text.split(currentTitle, '/')[1]
		local flag = Flags.icon(country, category or gameCategory)
		local div = mw.html.create('div')
			:addClass('flag')
			:wikitext(flag)
		if cities then
			div:wikitext(mw.text.trim(mw.text.split(cities, ',')[i]))
		else
			div:wikitext(country)
		end
		if state then div:wikitext(', ' .. state) end
			
		container:node(div)
	end
	
	return container
end

return Location