Modul:InfoboxSettlement

De la Wikipedia, enciclopedia liberă
Sari la navigare Sari la căutare

Documentația acestui modul poate fi creată la Modul:InfoboxSettlement/doc

local p = {}

local args = {}
local root
local wikidata = require('Modul:Wikidata')
local editWD = require('Modul:EditAtWikidata')
local collapsibleList = require('Modul:Collapsible_list')
local getArgs = require('Modul:Arguments').getArgs
local NameAndImage = require('Modul:NameAndImage')
local StringUtils = require('Modul:StringUtils')
local infoboxImage = require('Modul:InfoboxImage').InfoboxImage
local DateUtils = require('Modul:DateUtils')
local TableTools = require('Modul:TableTools')
local round = require('Modul:Matematică')._round
local join = require('Modul:Separated entries')._main
local formatnum = require('Modul:Formatnum')._formatNum
local wrapInLangSpan = function(langCode, text) 
	if text then return require('Modul:Lang').fromArgs(langCode, nil, text, true) end
	return nil
end
local existCache = {}
local lang = mw.getContentLanguage()

local _br_ = tostring(mw.html.create('br'))

local function ifexist(pageName)
	if existCache[pageName] == nil then
		local page = mw.title.new(pageName)
		if page then
			existCache[pageName] = page.exists
		else
			existCache[pageName] = false
		end
	end
	return existCache[pageName]
end

local function returnIfPageExists(pageName)
	if pageName == nil then return nil end
	if ifexist(pageName) then
		return pageName
	end
	return nil
end

local function isNilOrEmpty(argument)
	return argument == nil or argument == {} or mw.text.trim(argument) == ''
end

local function convertSqMiToKm2(argument)
	local sqmi = argument
	if type(argument) == 'string' then sqmi = tonumber(argument) end
	return 2.58998811 * sqmi
end

local function convertFtToM(argument)
	local ft = argument
	if type(argument) == 'string' then ft = tonumber(argument) end
	return .3048 * ft
end

local function removeDiacritics(argument)
	local ret = tostring(argument)
	ret = mw.ustring.gsub(ret, 'ă', 'a')
	ret = mw.ustring.gsub(ret, 'â', 'a')
	ret = mw.ustring.gsub(ret, 'î', 'i')
	ret = mw.ustring.gsub(ret, 'ș', 's')
	ret = mw.ustring.gsub(ret, 'ț', 't')
	ret = mw.ustring.gsub(ret, 'ș', 's')
	ret = mw.ustring.gsub(ret, 'ț', 't')
	return ret
end

local function keepFirstNumber(argument)
	--TODO make it work for negative numbers with all possible prefixes and move to Modul:Matematică
    if isNilOrEmpty(argument) then return argument end
	local ret = string.match(argument, '^%d[%d.,]*')
	if ret then return ret end
	return argument
end

local function extractPopulationFromWikidata(args, entityId)
	local wikidataPopClaims = wikidata.findBestClaimsForProperty(entityId, 'P1082')
	local preferredWikidataPopClaim = nil
	if wikidataPopClaims and #wikidataPopClaims > 0 then
		for _,eachPopClaim in ipairs(wikidataPopClaims) do
			if eachPopClaim.qualifiers and eachPopClaim.qualifiers['P459'] then
				for __,eachDeterminationMethodQualifier in ipairs(eachPopClaim.qualifiers['P459']) do
					if wikidata.isValueSnak(eachDeterminationMethodQualifier) and eachDeterminationMethodQualifier.datavalue.value['numeric-id'] == 39825 then
						preferredWikidataPopClaim = eachPopClaim
					end
				end
			end
		end
		if not preferredWikidataPopClaim then preferredWikidataPopClaim = wikidataPopClaims[#wikidataPopClaims] end
	end
	if preferredWikidataPopClaim then
		if preferredWikidataPopClaim.qualifiers and preferredWikidataPopClaim.qualifiers['P585'] then
			for _,eachTimeQual in ipairs(preferredWikidataPopClaim.qualifiers['P585']) do
				if wikidata.isValueSnak(eachTimeQual) then
					args['recensamant'] = tostring(wikidata.extractDateFromClaim(eachTimeQual).year)
					break
				end
			end
		end
		args['populatie'] = tonumber(preferredWikidataPopClaim.mainsnak.datavalue.value.amount)
	end
end

local function _generate()
	root = mw.html.create('table')
	root:addClass('infocaseta')
		:css('border-spacing', '0')
		:css('font-size', '88%')
		:css('padding', '0')
		:css('line-height', '1.5em')
	local categories = {}
	local headerTd = root:tag('tr'):tag('td')
			:attr('colspan', '2')
			:css('height', '41px')
			:addClass('antet harta')
			:wikitext(args['nume'])
	local alteNume = {}
	if not isNilOrEmpty(args['nume_nativ']) then table.insert(alteNume, mw.text.trim(args['nume_nativ'])) end
	if not isNilOrEmpty(args['alt_nume']) then table.insert(alteNume, mw.text.trim(args['alt_nume'])) end
	if #alteNume > 0 then
		root:tag('tr')
			:addClass('mergedrow')
			:tag('td')
				:attr('align', 'center')
				:attr('colspan', '2')
				:css('font-size', '150%')
				:css('margin-bottom', '2')
				:css('line-height', '1.2em')
				:css('background', 'linear-gradient( to right, rgba(45, 41, 46, 0), rgba(45, 41, 46, 0), rgba(45, 41, 46, 0), rgba(16, 23, 33, 0.25)) repeat-y right')
				:css('padding-top', '0')
				:addClass('porecla')
				:wikitext(table.concat(alteNume, _br_))
	end
	if args['nume'] and args['tip_asezare'] then
		root:tag('tr')
			:addClass('mergedtoprow')
			:tag('td')
				:attr('colspan', '2')
				:css('text-align', 'center')
				:css('background', '#dddddd')
				:wikitext(StringUtils._encloseString({StringUtils._emptyToNil({mw.text.listToText(args['tip_asezare'], ', ')}), "—  '''", "'''  —"}))
	end
	
	if args['nume'] and args['nume_oficial'] and args['nume'] ~= args['nume_oficial'] then
		root:tag('tr')
			:addClass('mergedtoprow')
			:tag('td')
				:attr('colspan', '2')
				:css('text-align', 'center')
				:wikitext("'''" .. args['nume_oficial'] .. "'''")
	end
	
	local nume_limba = args['nume_limba']
	for langIndex = 1,table.maxn(nume_limba) do
		if nume_limba[langIndex] and nume_limba[langIndex]['nume_limba'] and nume_limba[langIndex]['nume_limba'] ~= "" then
			root:tag('tr')
				:addClass('mergedtoprow')
				:tag('td')
					:attr('colspan', '2')
					:css('text-align', 'center')
					:wikitext("'''" .. nume_limba[langIndex]['nume_limba'] .. " '''")
			local nume_limba_tip = nume_limba[langIndex]['tip']
			local nume_limba_info = nume_limba[langIndex]['info']
			if nume_limba_tip and nume_limba_info then
				for tipIndex = 1,table.maxn(nume_limba_tip) do
					if nume_limba_tip[tipIndex] then
						local langTr = root:tag('tr')
						if tipIndex == table.maxn(nume_limba_tip) then langTr:addClass('mergedbottomrow') else langTr:addClass('mergedrow') end
						langTr:tag('th')
							:wikitext(" - " .. nume_limba_tip[tipIndex])
						langTr:tag('td')
							:wikitext(nume_limba_info[tipIndex] or "")
					end
				end
			end
		end
	end

	if args['imagine'] and args['imagine'] ~= "" then
		local imageText = infoboxImage{image=args['imagine'], size=args['imagine_dimensiune'], sizedefault='frameless', upright='1', suppressplaceholder='yes', alt=args['imagine_descriere'] or ''}
		local imageCaption = args['imagine_descriere']
		local fullImageText = join({imageText, imageCaption, ['separator'] = tostring(mw.html.create('br'))})
		root:tag('tr')
			:tag('td')
				:attr('colspan', '2')
				:css('text-align', 'center')
				:css('padding', '0.7em 0.8em 0.7em 0.8em')
				:wikitext(fullImageText)
	end

	if args['image_seal'] or args['drapel'] or args['stemă'] or args['emblemă_imagine'] then
		local symbolsTable = root:tag('tr')
			:addClass('mergedtoprow')
			:tag('td')
				:addClass('maptable')
				:attr('colspan', '2')
				:attr('align', 'center')
				:css('padding', '0.4em 0 0.4em 0')
				:tag('table')
					:css('width', '100%')
					:css('background', 'none')
                                        :css('display', 'table')
					:attr('align', 'center')
		local numberOfSymbols = 0
		
		local sealText, drapelText, stemaText, emblemaText = "","","",""
		if not isNilOrEmpty(args['image_seal']) then
			sealText = sealText .. "[[Fișier:" .. args['image_seal'] .. '|' .. args['seal_size'] .. '|'
			sealText = sealText .. "Sigiliul autorităților din " .. args['nume'] .. ']]'
			sealText = sealText .. "<br/><small>"
			if args['seal_link'] and args['seal_link'] ~= "" then sealText = sealText .. '[[' .. args['seal_link'] .. '|Sigiliu]]' else sealText = sealText .. "'''Sigiliu'''" end
			sealText = sealText .. "</small>"
		end
		if not isNilOrEmpty(args['emblemă_imagine']) then
			emblemaText = emblemaText .. "[[Fișier:" .. args['emblemă_imagine'] .. '|' .. args['emblemă_dimensiune'] .. '|Logo oficial]]'
			emblemaText = emblemaText .. "<br/><small>"
			if not isNilOrEmpty(args['emblemă_link']) then emblemaText = emblemaText .. '[[' .. args['emblemă_link'] .. '|' .. args['emblemă_tip'] ..']]' else emblemaText = emblemaText .. args['emblemă_tip'] end
			emblemaText = emblemaText .. "</small>"
		end
		if not isNilOrEmpty(args['stemă']) then
			stemaText = stemaText .. "[[Fișier:" .. args['stemă'] .. '|' .. args['stemă_dimensiune'] .. '|Stemă]]'
			stemaText = stemaText .. "<br/><small>"
			if not isNilOrEmpty(args['link_stemă']) then stemaText = stemaText .. '[[' .. args['link_stemă'] .. '|Stemă]]' else stemaText = stemaText .. "'''Stemă'''" end
			stemaText = stemaText .. "</small>"
		end
		if not isNilOrEmpty(args['drapel']) then
			drapelText = drapelText .. "[[Fișier:" .. args['drapel'] .. '|' .. args['drapel_dimensiune'] .. '|border|Drapel]]'
			drapelText = drapelText .. "<br/><small>"
			if not isNilOrEmpty(args['link_drapel']) then drapelText = drapelText .. '[[' .. args['link_drapel'] .. '|Drapel]]' else drapelText = drapelText .. "'''Drapel'''" end
			drapelText = drapelText .. "</small>"
		end
		
		for symbolIndex, symbolKey in pairs({ 'image_seal', 'drapel', 'stemă', 'emblemă_imagine' }) do
			if not isNilOrEmpty(args[symbolKey]) then numberOfSymbols = numberOfSymbols + 1 end
		end
		if numberOfSymbols == 2 then
			local twoSymbolsTr = symbolsTable:tag('tr')
			local firstSymbolsTd = twoSymbolsTr:tag('td')
					:css('vertical-align', 'middle')
					:attr('align', 'center')
			if not isNilOrEmpty(args['drapel']) then
				firstSymbolsTd:wikitext(drapelText)
			elseif not isNilOrEmpty(args['image_seal']) then
				firstSymbolsTd:wikitext(sealText)
			elseif not isNilOrEmpty(args['stemă']) then
				firstSymbolsTd:wikitext(stemaText)
			elseif not isNilOrEmpty(args['emblemă_imagine']) then
				firstSymbolsTd:wikitext(emblemaText)
			end
			local secondSymbolsTd = twoSymbolsTr:tag('td')
					:css('vertical-align', 'middle')
					:attr('align', 'center')
			if not isNilOrEmpty(args['emblemă_imagine']) then
				secondSymbolsTd:wikitext(emblemaText)
			elseif not isNilOrEmpty(args['stemă']) then
				secondSymbolsTd:wikitext(stemaText)
			elseif not isNilOrEmpty(args['image_seal']) then
				secondSymbolsTd:wikitext(sealText)
			elseif not isNilOrEmpty(args['drapel']) then
				secondSymbolsTd:wikitext(drapelText)
			end
		else
			if not isNilOrEmpty(args['drapel']) or not isNilOrEmpty(args['image_seal']) then
				local flagAndSealRow = symbolsTable:tag('tr')
				if not isNilOrEmpty(args['drapel']) then
					local drapelTd = flagAndSealRow:tag('td'):css('vertical-align', 'middle'):attr('align', 'center')
					if isNilOrEmpty(args['image_seal']) then drapelTd:attr('colspan', '2') else drapelTd:attr('width', '50%') end
					drapelTd:wikitext(drapelText)
				end
				if not isNilOrEmpty(args['image_seal']) then
					local sealTd = flagAndSealRow:tag('td'):css('vertical-align', 'middle'):attr('align', 'center')
					if isNilOrEmpty(args['drapel']) then sealTd:attr('colspan', '2') else sealTd:attr('width', '50%') end
					sealTd:wikitext(sealText)
				end
			end
			if not isNilOrEmpty(args['stemă']) or not isNilOrEmpty(args['emblemă_imagine']) then
				local armsAndLogoRow = symbolsTable:tag('tr')
				if not isNilOrEmpty(args['stemă']) then
					local armsTd = armsAndLogoRow:tag('td'):css('vertical-align', 'middle'):attr('align', 'center')
					if isNilOrEmpty(args['emblemă_imagine']) then armsTd:attr('colspan', '2') else armsTd:attr('width', '50%') end
					armsTd:wikitext(stemaText)
				end
				if not isNilOrEmpty(args['emblemă_imagine']) then
					local logoTd = armsAndLogoRow:tag('td'):css('vertical-align', 'middle'):attr('align', 'center')
					if isNilOrEmpty(args['stemă']) then logoTd:attr('colspan', '2') else logoTd:attr('width', '50%') end
					logoTd:wikitext(emblemaText)
				end
			end
		end
	end
	
	if args['poreclă'] ~= "" then
		root:tag('tr'):addClass('mergedrow')
			:tag('td'):attr('colspan', '2')
				:attr('align', 'center')
				:wikitext('[[Poreclă]]: ' .. tostring(mw.html.create('span'):addClass('porecla'):wikitext(args['poreclă'])))
	end
	if args['motto'] ~= "" then
		root:tag('tr'):addClass('mergedrow')
			:tag('td'):attr('colspan', '2')
				:attr('align', 'center')
				:wikitext('[[Motto]]: ' .. args['motto'])
	end
	local hartaPunct = args['hartă_punct']
	if hartaPunct then
		local hartaPunctText = mw.getCurrentFrame():expandTemplate{ 
			title = 'superimpose', 
			args = { 
				base = hartaPunct.imagine,
				base_width = hartaPunct.dimensiune,
				base_caption = args['nume'],
				float = 'Red pog.svg',
				float_width = '9px',
				float_caption = hartaPunct.descriere,
				x = hartaPunct.x,
				y = hartaPunct.y
			}
		} .. (hartaPunct.descriere ~= nil and tostring(mw.html.create('small').wikitext(hartaPunct.descriere)) or '')
		root:tag('tr'):addClass('mergedrow'):attr('align', 'center')
			:tag('td'):attr('colspan', '2')
				:css('text-align', 'center')
				:css('padding', '0.7em 0.8em 0.7em 0.8em')
				:wikitext(hartaPunctText)
	end
	local pushpins = args['pushpin']
	for mapIndex = 1,table.maxn(args['pushpin']) do
		if pushpins[mapIndex] 
			and not isNilOrEmpty(pushpins[mapIndex]['map']) 
			and not isNilOrEmpty(args['longd'])
			and not isNilOrEmpty(args['latd'])
			and ifexist('Format:Harta de localizare ' .. pushpins[mapIndex]['map']) then
				local mapArgs = { pushpins[mapIndex]['map'], float = 'none', 
					background = args['background'], border = 'none', 
					position = pushpins[mapIndex]['label_position'], 
					width = pushpins[mapIndex]['size'],
					mapframe = pushpins[mapIndex]['mapframe'] or false
				}
				if pushpins[mapIndex]['label_position'] ~= none then mapArgs.label = args['nume'] end
				if isNilOrEmpty(args['longm']) and isNilOrEmpty(args['longEV']) then 
					mapArgs.long = args['longd']
				else
					mapArgs.lon_deg = args['longd']
					mapArgs.lon_min = args['longm']
					mapArgs.lon_sec = args['longs']
					mapArgs.lon_dir = args['longEV']
				end
				if isNilOrEmpty(args['latm']) and isNilOrEmpty(args['latNS']) then
					mapArgs.lat = args['latd']
				else
					mapArgs.lat_deg = args['latd']
					mapArgs.lat_min = args['latm']
					mapArgs.lat_sec = args['lats']
					mapArgs.lat_dir = args['latNS']
				end
				local altMap = mw.getCurrentFrame():expandTemplate{title = 'Harta de localizare ' .. pushpins[mapIndex]['map'], args = { 'alt_image' } }
				if not isNilOrEmpty(altMap) then mapArgs.AlternativeMap = altMap end
				local mapText = mw.getCurrentFrame():expandTemplate{title = 'Location map ', args = mapArgs }
				root:tag('tr'):addClass('mergedrow')
					:tag('td'):attr('colspan', '2'):attr('align', 'center')
					:wikitext(mapText .. pushpins[mapIndex]['caption'])
		end
	end
	if not isNilOrEmpty(args['latd']) or not isNilOrEmpty(args['coordonate']) then
		local coordsTh = root:tag('tr'):addClass('mergedbottomrow')
								:tag('th'):attr('colspan', '2')
									:css('text-align', 'center')
									:css('font-size', 'small')
									:css('padding-bottom', '0.7em')
		if not isNilOrEmpty(args['latd']) then
			local coordsText = 'Coordonate'
			if not isNilOrEmpty(args['tip_coordonate']) then
				coordsText = coordsText .. '&nbsp;(' .. args['tip_coordonate'] .. ')'
			end
			coordsText = coordsText .. ': ' .. mw.getCurrentFrame():expandTemplate{ title = 'Geobox coor', args = { args['latd'], args['latm'], args['lats'], args['latNS'], args['longd'], args['longm'], args['longs'], args['longEV'], args['coordinates_type'], title=args['coords_in_title'], format='dms' } }
			coordsTh:wikitext(coordsText)
		elseif not isNilOrEmpty(args['coordonate']) then
			coordsTh:wikitext(args['coordonate'])
		end
	end
	if #(args['subdiviziuni']) > 0 then
		root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
		for subdivIndex = 1, table.maxn(args['subdiviziuni']) do
			if args['subdiviziuni'][subdivIndex] ~= nil and not isNilOrEmpty(args['subdiviziuni'][subdivIndex]['tip']) then
				local subdivTh = root:tag('tr'):addClass('merged' .. (subdivIndex == 1 and 'top' or '') .. 'row'):tag('th'):wikitext(args['subdiviziuni'][subdivIndex]['tip']):done()
					:tag('th'):addClass('adr')
				if subdivIndex == 1 then subdivTh:tag('span'):addClass('country-name'):wikitext(args['subdiviziuni'][subdivIndex]['nume'])
				elseif subdivIndex == 2 then subdivTh:tag('span'):addClass('region'):wikitext(args['subdiviziuni'][subdivIndex]['nume'])
				else subdivTh:wikitext(args['subdiviziuni'][subdivIndex]['nume']) end
			end
		end
	end
	if #(args['clasificari']) > 0 then
		root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
		for clasifIndex = 1, table.maxn(args['clasificari']) do
			if args['clasificari'][clasifIndex] ~= nil and not isNilOrEmpty(args['clasificari'][clasifIndex]['tip']) then
				root:tag('tr'):addClass('merged' .. (clasifIndex == 1 and 'top' or '') .. 'row'):tag('th'):wikitext(args['clasificari'][clasifIndex]['tip']):done()
					:tag('td'):wikitext(args['clasificari'][clasifIndex]['cod'])
			end
		end
	end
	for atestIndex = 1, table.maxn(args['atestari']) do
		if args['atestari'][atestIndex] ~= nil and not isNilOrEmpty(args['atestari'][atestIndex]['an']) and not isNilOrEmpty(args['atestari'][atestIndex]['titlu']) then
			root:tag('tr'):addClass('mergedrow')
				:tag('th'):wikitext(args['atestari'][atestIndex]['titlu']):done()
				:tag('td'):wikitext(args['atestari'][atestIndex]['an'])
		end
	end
	if not isNilOrEmpty(args['fondator']) then
		root:tag('tr'):addClass('mergedrow')
			:tag('th'):wikitext('Fondator'):done()
			:tag('td'):wikitext(args['fondator'])
	end
	if not isNilOrEmpty(args['numit_dupa']) then
		root:tag('tr'):addClass('mergedrow')
			:tag('th'):wikitext('Numit după'):done()
			:tag('td'):wikitext(args['numit_dupa'])
	end
	local ip = args['p']
	if table.maxn(ip) == 0 and isNilOrEmpty(args['componenta']) then
		ip = wikidata.getValueList(nil, 'P1383') or {}
	end
	if table.maxn(ip) < 3 and args['stil_componenta'] == '' then
		args['stil_componenta'] = 'para'
	end
	if not isNilOrEmpty(args['resedinta']) or table.maxn(ip) > 0 or not isNilOrEmpty(args['componenta']) then
		root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
		local nextRowClass = 'mergedtoprow'
		if not isNilOrEmpty(args['resedinta']) then
			root:tag('tr'):addClass(nextRowClass)
				:tag('th'):wikitext(args['tip_resedinta']):done()
				:tag('td'):wikitext(args['resedinta'])
			nextRowClass = 'mergedrow'
		end
		if table.maxn(ip) > 0 or not isNilOrEmpty(args['componenta']) then
			local tipComp = isNilOrEmpty(args['tip_componenta']) and 'Componență' or args['tip_componenta']
			local pTableRow = root:tag('tr'):addClass(nextRowClass)
				:tag('th'):wikitext(tipComp):done():tag('td')
			if args['stil_componenta'] == 'para' then
				pTableRow:wikitext(args['componenta'])
				if table.maxn(ip) > 0 and not isNilOrEmpty(args['componenta']) then pTableRow:wikitext('&#58;&nbsp;') end
				pTableRow:wikitext(table.concat(ip, ', '))
			elseif table.maxn(ip) > 0 then
				local displayStyle = ''
				if args['stil_componenta'] == 'coll' or (args['stil_componenta'] ~= 'list' and table.maxn(ip) > 6) then displayStyle = 'none' else displayStyle = 'on' end
				pTableRow:wikitext(collapsibleList.display(nil, 'border:none;padding:0;', nil, args['componenta'], 'text-align:left;display:' .. displayStyle, ip))
			else
				pTableRow:wikitext(args['componenta'])
			end
		end
	end
	local lideri = args['lideri']
	if not isNilOrEmpty(args['tip_guvernare']) or table.maxn(lideri) > 0 then
		root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
		local governmentHeadTd = root:tag('tr'):addClass('mergedtoprow'):tag('td'):attr('colspan', '2'):wikitext("'''Guvernare''' ")
		if not isNilOrEmpty(args['guvernare_note_subsol']) then
			governmentHeadTd:wikitext(args['guvernare_note_subsol'])
		end
		if not isNilOrEmpty(args['tip_guvernare']) then
			root:tag('tr'):addClass('mergedrow')
				:tag('th'):wikitext('&nbsp;-&nbsp;Tip'):done()
				:tag('td'):wikitext(args['tip_guvernare'])
		end
		for liderIndex = 1,table.maxn(lideri) do
			if lideri[liderIndex] ~= nil then
				local leaderTd = root:tag('tr'):addClass('mergedrow')
					:tag('th'):wikitext('&nbsp;-&nbsp;', mw.text.trim(lideri[liderIndex]['titlu'] or '')):done()
					:tag('td')
				if not isNilOrEmpty(lideri[liderIndex]['nume']) then
					if not isNilOrEmpty(lideri[liderIndex]['link']) then
						leaderTd:wikitext('[[', lideri[liderIndex]['link'], '|', lideri[liderIndex]['nume'], ']]')
					else 
						leaderTd:wikitext(lideri[liderIndex]['nume'])
					end
				end
				local leaderDataInBrackets = {}
				if not isNilOrEmpty(lideri[liderIndex]['partid']) then
					local tara = args['subdiviziuni'][1] and args['subdiviziuni'][1]['nume'] or ''
					table.insert(leaderDataInBrackets, mw.getCurrentFrame():expandTemplate{title='Polparty', args={tara, lideri[liderIndex]['partid'] } })
				end
				if not isNilOrEmpty(lideri[liderIndex]['ales']) then
					table.insert(leaderDataInBrackets, lideri[liderIndex]['ales'])
				end
				if #leaderDataInBrackets > 0 then leaderTd:wikitext(' (', table.concat(leaderDataInBrackets, ', '), ')') end
			end
		end
	end
	
	local suprIndex, suprV = next(args['suprafata'], nil)
	if suprIndex or not isNilOrEmpty(args['altitudine']) then
		root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
		if suprIndex then
			root:tag('tr'):addClass('mergedtoprow')
				:tag('td'):attr('colspan', '2'):wikitext("'''[[Suprafață]]'''", args['note_subsol_suprafata'])
			if args['suprafata']['totala'] then
				local suprafTotalTh = root:tag('tr'):addClass('mergedrow'):tag('th'):wikitext(' &nbsp;-&nbsp;')
				if not isNilOrEmpty(args['tip_total']) then suprafTotalTh:wikitext(args['tip_total'])
				elseif args['suprafata']['metropolitana'] or args['suprafata']['urbana'] then
					if args['tip_asezare'] and table.maxn(args['tip_asezare']) > 0 then suprafTotalTh:wikitext(args['tip_asezare'][1]) else suprafTotalTh:wikitext('Oraș') end
				else suprafTotalTh:wikitext('Total') end
				suprafTotalTh:done():tag('td'):wikitext(args['suprafata']['totala']['km2'], '&nbsp;[[km²]]')
			end
			if args['suprafata']['pamant'] then
				root:tag('tr'):addClass('mergedrow')
					:tag('th'):wikitext('&nbsp;-&nbsp;Pământ'):done()
					:tag('td'):wikitext(args['suprafata']['pamant']['km2'], '&nbsp;[[km²]]')
			end
			if args['suprafata']['apa'] then
				local waterAreaTd = root:tag('tr'):addClass('mergedrow')
					:tag('th'):wikitext('&nbsp;-&nbsp;Apă'):done()
					:tag('td'):wikitext(args['suprafata']['apa']['km2'], '&nbsp;[[km²]]')
				if args['suprafata']['apa']['procent'] then
					waterAreaTd:wikitext(' &nbsp;', args['suprafata']['apa']['procent'], '%')
				end
			end
			if args['suprafata']['urbana'] then
				root:tag('tr'):addClass('mergedrow')
					:tag('th'):wikitext('&nbsp;-&nbsp;[[Arie urbană|Urbană]]'):done()
					:tag('td'):wikitext(args['suprafata']['urbana']['km2'], '&nbsp;[[km²]]')
			end
			if args['suprafata']['metropolitana'] then
				root:tag('tr'):addClass('mergedrow')
					:tag('th'):wikitext('&nbsp;-&nbsp;[[Zonă metropolitană|Metropolitană]]'):done()
					:tag('td'):wikitext(args['suprafata']['metropolitana']['km2'], '&nbsp;[[km²]]')
			end
			for blankIndex = 1, table.maxn(args['suprafata']['blank'] or {}) do
				local crtBlank = args['suprafata']['blank'][blankIndex]
				if crtBlank and crtBlank['title'] and crtBlank['km2'] then
					root:tag('tr'):addClass('mergedrow')
						:tag('th'):wikitext('&nbsp;-&nbsp;', crtBlank['title']):done()
						:tag('td'):wikitext(crtBlank['km2'], '&nbsp;[[km²]]')
				end
			end
		end
		if not isNilOrEmpty(args['altitudine']) then
			root:tag('tr'):addClass('mergedtoprow')
				:tag('td'):wikitext("'''[[Altitudine]]'''", args['note_subsol_altitudine']):done()
				:tag('td'):wikitext(args['altitudine'], '&nbsp;[[Nivelul mării|m.d.m.]]')
		end
		if not isNilOrEmpty(args['altitudine_max_m']) then
			root:tag('tr'):addClass('mergedtoprow')
				:tag('td'):wikitext("[[Altitudine]]&nbsp;maximă"):done()
				:tag('td'):wikitext(args['altitudine_max_m'], '&nbsp;[[Nivelul mării|m.d.m.]]')
		end
		if not isNilOrEmpty(args['altitudine_min_m']) then
			root:tag('tr'):addClass('mergedbottomrow')
				:tag('td'):wikitext("Altitudine&nbsp;minimă"):done()
				:tag('td'):wikitext(args['altitudine_min_m'], '&nbsp;[[Nivelul mării|m.d.m.]]')
		end
	end
	if not isNilOrEmpty(args['populatie']) or not isNilOrEmpty(args['populatie_urbana']) or not isNilOrEmpty(args['populatie_metropolitana']) or next(args['population_blank'], nil) then
		root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
		local popTitleTd = root:tag('tr'):addClass('mergedtoprow'):tag('td')
		if args['tip_total'] ~= '&nbsp;' then popTitleTd:attr('colspan', '2') end
		popTitleTd:wikitext("'''Populație''' ")
		if args['recensamant'] then popTitleTd:wikitext('(', args['recensamant'], ')') end
		popTitleTd:wikitext(args['note_subsol_populatie'])
		local popTextTd
		if args['tip_total'] ~= '&nbsp;' then
			local totalheader = root:tag('tr'):addClass('mergedrow')
				:tag('th'):wikitext('&nbsp;-&nbsp;')
			if not isNilOrEmpty(args['tip_total']) then totalheader:wikitext(args['tip_total'])
			elseif not isNilOrEmpty(args['populatie_metropolitana']) or not isNilOrEmpty(args['populatie_urbana']) then
				if args['tip_asezare'] and table.maxn(args['tip_asezare']) > 0 then totalheader:wikitext(args['tip_asezare'][1])
					else totalheader:wikitext('Oraș')
				end
			else totalheader:wikitext('Total')
			end
			popTextTd = totalheader:done():tag('td')
		else 
			popTextTd = popTitleTd:done():tag('td')
		end
		args['populatie'] = keepFirstNumber(args['populatie'])
		popTextTd:wikitext(formatnum(args['populatie']), ' locuitori')
		if not isNilOrEmpty(args['densitate']) then
			args['densitate'] = keepFirstNumber(args['densitate'])
			root:tag('tr'):addClass('mergedrow')
				:tag('th'):wikitext('&nbsp;-&nbsp;[[Densitatea populației|Densitate]]'):done()
				:tag('td'):wikitext(formatnum(args['densitate']), ' loc./km²')
		end
		if args['populatie_urbana'] then 
			args['populatie_urbana'] = keepFirstNumber(args['populatie_urbana'])
			root:tag('tr'):addClass('mergedrow')
				:tag('th'):wikitext('&nbsp;- [[Zonă urbană|Urbană]]'):done()
				:tag('td'):wikitext(formatnum(args['populatie_urbana']), ' locuitori')
		end
		if args['densitate_pop_urbana'] then 
			args['densitate_pop_urbana'] = keepFirstNumber(args['densitate_pop_urbana'])
			root:tag('tr'):addClass('mergedrow')
				:tag('th'):wikitext('&nbsp;- Densitate urbană'):done()
				:tag('td'):wikitext(formatnum(args['densitate_pop_urbana']), ' loc./km²')
		end
		if args['populatie_metropolitana'] then 
			args['populatie_metropolitana'] = keepFirstNumber(args['populatie_metropolitana'])
			root:tag('tr'):addClass('mergedrow')
				:tag('th'):wikitext('&nbsp;- [[Zonă metropolitană|Metropolitană]]'):done()
				:tag('td'):wikitext(formatnum(args['populatie_metropolitana']), ' locuitori')
		end
		if args['densitate_pop_metro'] then 
			args['densitate_pop_metro'] = keepFirstNumber(args['densitate_pop_metro'])
			root:tag('tr'):addClass('mergedrow')
				:tag('th'):wikitext('&nbsp;- Densitate metropolitană'):done()
				:tag('td'):wikitext(formatnum(args['densitate_pop_metro']), ' loc./km²')
		end
		for popIdx=1,table.maxn(args['population_blank']) do
			if args['population_blank'][popIdx] then
				if args['population_blank'][popIdx]['value'] then
					args['population_blank'][popIdx]['value'] = keepFirstNumber(args['population_blank'][popIdx]['value'])
					root:tag('tr'):addClass('mergedrow')
						:tag('th'):wikitext('&nbsp;- ', args['population_blank'][popIdx]['title']):done()
						:tag('td'):wikitext(formatnum(args['population_blank'][popIdx]['value']), ' locuitori')
				end
				if args['population_blank'][popIdx]['densitate'] then
					args['population_blank'][popIdx]['densitate'] = keepFirstNumber(args['population_blank'][popIdx]['densitate'])
					root:tag('tr'):addClass('mergedrow')
						:tag('th'):wikitext('&nbsp;- ', 'Densitate ', args['population_blank'][popIdx]['title']):done()
						:tag('td'):wikitext(formatnum(args['population_blank'][popIdx]['densitate']), ' loc./km²') 
				end
			end
		end
		if args['populatie_note'] then
			root:tag('tr'):addClass('mergedbottomrow')
				:tag('td'):wikitext('&nbsp;'):done()
				:tag('td'):tag('small'):wikitext(args['populatie_note'])
		end
	end
	
	if not isNilOrEmpty(args['fus_orar']) or not isNilOrEmpty(args['cod_postal']) or not isNilOrEmpty(args['prefix_tel']) or not isNilOrEmpty(args['cod']) then
		root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
		if not isNilOrEmpty(args['fus_orar']) then
			root:tag('tr'):addClass('mergedtoprow')
				:tag('th'):wikitext('[[Fus orar]]'):done()
				:tag('td'):wikitext(args['fus_orar'], (not isNilOrEmpty(args['utc_offset']) and ('&nbsp;(' .. args['utc_offset'] .. ')') or ''))
			if not isNilOrEmpty(args['fus_orar_DST']) then
				root:tag('tr'):addClass('mergedtoprow')
					:tag('th'):css('white-space', 'nowrap'):wikitext('&nbsp;-&nbsp;Ora de vară&nbsp;([[Ora de vară|DST]])'):done()
					:tag('td'):wikitext(args['fus_orar_DST'], (not isNilOrEmpty(args['utc_offset_DST']) and ('&nbsp;(' .. args['utc_offset_DST'] .. ')') or ''))
			end
		end
		if not isNilOrEmpty(args['cod_postal']) then
			root:tag('tr'):addClass('mergedtoprow')
				:tag('th'):wikitext(args['tip_cod_postal']):done()
				:tag('td'):addClass('adr'):tag('span'):addClass('postal-code'):wikitext(args['cod_postal'])
		end
		local postCodeTrClass = 'mergedrow'
		for postCodeIdx=1,table.maxn(args['postal_codes']) do
			if args['postal_codes'][postCodeIdx] and args['postal_codes'][postCodeIdx]['code_type'] and args['postal_codes'][postCodeIdx]['code'] then
				if postCodeIdx == table.maxn(args['postal_codes']) then postCodeTrClass = 'mergedbottomrow' end
				root:tag('tr'):addClass(postCodeTrClass)
					:tag('th'):wikitext(args['postal_codes'][postCodeIdx]['code_type']):done()
					:tag('td'):addClass('adr'):tag('span'):addClass('postal-code'):wikitext(args['postal_codes'][postCodeIdx]['code_type'])
			end
		end
		if not isNilOrEmpty(args['prefix_tel']) then
			root:tag('tr'):addClass('mergedbottomrow')
				:tag('th'):wikitext('Prefix telefonic'):done()
				:tag('td'):wikitext(args['prefix_tel'])
		end
		if not isNilOrEmpty(args['cod']) then
			root:tag('tr'):addClass('mergedtoprow')
				:tag('th'):wikitext(args['tip_cod']):done()
				:tag('td'):addClass('adr'):tag('span'):addClass('postal-code'):wikitext(args['cod'])
		end
	end
	if next(args['infratiri'], nil) then
		root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
		local first = true
		for infrIdx = 1, table.maxn(args['infratiri']) do
			if args['infratiri'][infrIdx] then
				if first then 
					root:tag('tr'):addClass('mergedtoprow')
						:tag('td'):attr('colspan', '2'):wikitext("'''Localități înfrățite'''")
					first = false
				end
				root:tag('tr'):addClass('mergedrow')
					:tag('td'):wikitext('&nbsp;-&nbsp;', args['infratiri'][infrIdx]['oras']):done()
					:tag('td'):wikitext(args['infratiri'][infrIdx]['tara'] or '')
			end
		end
	end
	local trClass = 'mergedtoprow'
	for campGolIdx = 1, table.maxn(args['campuri_goale']) do
		if args['campuri_goale'][campGolIdx] and args['campuri_goale'][campGolIdx]['gol_nume'] then
			root:tag('tr'):addClass(trClass)
				:tag('th'):wikitext(args['campuri_goale'][campGolIdx]['gol_nume']):done()
				:tag('td'):wikitext(args['campuri_goale'][campGolIdx]['gol_info'])
			trClass = 'mergedrow'
		end
	end
	if args['note'] then
		root:tag('tr'):addClass('mergedtoprow')
			:tag('td'):attr('colspan', '2'):attr('align', 'left')
				:tag('small'):wikitext(args['note'])
	end
	
	local externalAddresses = {}
	local externalAddressesWdIds = {'P1566', 'P402', 'P1997'}
	if not isNilOrEmpty(args['website']) then
		table.insert(externalAddresses, args['website'])
	else
		table.insert(externalAddressesWdIds, 1, 'P856')
	end
	for _,eachAddressId in ipairs(externalAddressesWdIds) do
		local eachAddressLink = wikidata.findOnlineLinks({eachAddressId})
		if eachAddressLink and eachAddressLink[1] then
			table.insert(externalAddresses, eachAddressLink[1] .. ' ' .. editWD.displayMessage(eachAddressId))
		end
	end
	local sites = table.concat(externalAddresses, tostring(mw.html.create('br')))
	root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
	root:tag('tr'):tag('td'):attr('colspan', '2'):addClass('mergedtoprow'):css('text-align', 'center'):wikitext("'''Prezență online''' ")
	root:tag('tr'):tag('td'):attr('colspan', '2'):css('text-align', 'center'):wikitext(sites)

	if args['harti'][1] then
		root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
		for mapIdx = 1, table.maxn(args['harti']) do
			if args['harti'][mapIdx] then
				root:tag('tr'):addClass('mergedrow')
					:tag('td'):attr('colspan', '2'):css('text-align', 'center'):css('padding', '0.7em 0.8em 0.7em 0.8em'):css('align', 'center'):css('margin', '0 auto')
						:wikitext('[[Fișier:' .. args['harti'][mapIdx]['harta'] .. '|' .. args['harti'][mapIdx]['size'] .. '|none|' .. (args['harti'][mapIdx]['descriere'] or ('Hartă de poziționare pentru ' .. args['nume'])) .. ']]', args['harti'][mapIdx]['descriere'])
			end
		end
	else
		if table.maxn(args['pushpin']) == 0 then table.insert(categories, 'Articole fără hărți') end
	end

	if #(args['embedded']) > 0 then
		for embeddedIdx,eachEmbedded in ipairs(args['embedded']) do
			root:tag('tr'):tag('td'):attr('colspan', '2'):tag('hr')
			root:tag('tr'):tag('td'):attr('colspan', '2'):wikitext(eachEmbedded)
		end
	end
	root:wikitext(mw.getCurrentFrame():expandTemplate{title='infodoc', args = {colspan='2', culoare='dddddd', link = args['infodoc'], wikidata = 'da'}})

	local catlinks = {}
	for _,eachCat in ipairs(categories) do
		table.insert(catlinks, '[[Categorie:' .. eachCat .. ']]')
	end
	return tostring(root) .. table.concat(catlinks)
end

p.infobox = function(frame)
	origArgs = getArgs(frame, { wrappers = { 'Format:Infocaseta Așezare' } })
	
	args['nume'] = origArgs['nume'] or origArgs['nume_oficial'] or wikidata.findLabel(nil, nil) or mw.title.getCurrentTitle().text
	args['nume_oficial'] = origArgs['nume_oficial']

	args['nume_nativ'] = origArgs['nume_nativ']
	args['alt_nume'] = origArgs['alt_nume']
	args['tip_asezare'] = {}
	if origArgs['tip_asezare'] or origArgs['tip_așezare'] then table.insert(args['tip_asezare'], origArgs['tip_asezare'] or origArgs['tip_așezare']) end
	if table.maxn(args['tip_asezare']) == 0 then
		local settlementTypes = wikidata.findBestValues('P31')
		if settlementTypes and #settlementTypes > 0 then
			args['tip_asezare'] = settlementTypes
		end
	end
	args['tip_asezare_genitiv'] = origArgs['tip_asezare_genitiv'] or origArgs['tip_așezare_genitiv'] or 'localității'

	args['nume_limba'] = {}
	args['pushpin'] = {}
	args['subdiviziuni'] = {}
	args['clasificari'] = {}
	args['atestari'] = {}
	args['p'] = {}
	args['lideri'] = {}
	args['suprafata'] = {}
	args['population_blank'] = {}
	args['postal_codes'] = {}
	args['infratiri'] = {}
	args['campuri_goale'] = {}
	args['harti'] = {}
	args['embedded'] = {}

	local nlStart, nlEnd
	for argN, argV in pairs(origArgs) do
		if argV ~= nil and mw.text.trim(argV) == '' then origArgs[argN] = nil end
		argV = mw.text.trim(argV)
		origArgs[argN] = mw.text.trim(argV)
		nlStart, nlEnd = mw.ustring.find(argN, 'nume_limba')
		if nlStart == 1 then
			local nlIndex = tonumber(mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN)))
			if nlIndex ~= nil then
				if args['nume_limba'][nlIndex] == nil then
					args['nume_limba'][nlIndex] = {}
				end
				args['nume_limba'][nlIndex]['nume_limba'] = mw.text.trim(argV)
			end
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'pushpin_map')
		if nlStart == 1 then
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local indexLocation = mw.ustring.find(varNameWithIndex, "%d+") or (1 + #varNameWithIndex)
			local variableName = mw.ustring.sub(varNameWithIndex, 1, indexLocation - 1)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, indexLocation, #varNameWithIndex) or ""
			local variableIndex
			if variableIndexStr == "" then variableIndex = 1 else variableIndex = 1 + tonumber(variableIndexStr) end
			if args['pushpin'][variableIndex] == nil then args['pushpin'][variableIndex] = {} end
			args['pushpin'][variableIndex]['map'] = mw.text.trim(argV)
			if origArgs['pushpin_osm' .. variableIndexStr] then args['pushpin'][variableIndex]['mapframe'] = "1" end
			args['pushpin'][variableIndex]['size'] = mw.text.trim(origArgs['pushpin_dimensiune_harta' .. variableIndexStr] or origArgs['pushpin_dimensiune_hartă' .. variableIndexStr] or '290')
			args['pushpin'][variableIndex]['caption'] = mw.text.trim(origArgs['pushpin_descriere_harta' .. variableIndexStr] or origArgs['pushpin_descriere_hartă' .. variableIndexStr] or 'Poziția geografică')
			args['pushpin'][variableIndex]['label_position'] = mw.text.trim(origArgs['pushpin_label_position' .. variableIndexStr] or 'right')
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'tip_subdiviziune')
		if nlStart == 1 then
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local indexLocation = mw.ustring.find(varNameWithIndex, "%d+") or (1 + #varNameWithIndex)
			local variableName = mw.ustring.sub(varNameWithIndex, 1, indexLocation - 1)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, indexLocation, #varNameWithIndex) or ""
			local variableIndex
			if variableIndexStr == "" then variableIndex = 1 else variableIndex = 1 + tonumber(variableIndexStr) end
			if args['subdiviziuni'][variableIndex] == nil then args['subdiviziuni'][variableIndex] = {} end
			args['subdiviziuni'][variableIndex]['tip'] = mw.text.trim(argV)
			args['subdiviziuni'][variableIndex]['nume'] = mw.text.trim(origArgs['nume_subdiviziune' .. variableIndexStr] or '')
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'tip_cod_clasificare')
		if nlStart == 1 then
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local indexLocation = mw.ustring.find(varNameWithIndex, "%d+") or (1 + #varNameWithIndex)
			local variableName = mw.ustring.sub(varNameWithIndex, 1, indexLocation - 1)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, indexLocation, #varNameWithIndex) or ""
			local variableIndex
			if varNameWithIndex == "" then variableIndex = 1
			elseif varNameWithIndex == "_superioară" then variableIndex = 2 else variableIndex = 2 + tonumber(variableIndexStr) end
			if args['clasificari'][variableIndex] == nil then args['clasificari'][variableIndex] = {} end
			args['clasificari'][variableIndex]['tip'] = mw.text.trim(argV)
			args['clasificari'][variableIndex]['cod'] = mw.text.trim(origArgs['cod_clasificare' .. variableIndexStr] or '')
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'atestare')
		if nlStart == 1 then
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local indexLocation = mw.ustring.find(varNameWithIndex, "%d+") or (1 + #varNameWithIndex)
			local variableName = mw.ustring.sub(varNameWithIndex, 1, indexLocation - 1)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, indexLocation, #varNameWithIndex) or ""
			local variableIndex
			if variableIndexStr == "" then variableIndex = 1 else variableIndex = 1 + tonumber(variableIndexStr) end
			if args['atestari'][variableIndex] == nil then args['atestari'][variableIndex] = {} end
			args['atestari'][variableIndex]['an'] = mw.text.trim(argV)
			args['atestari'][variableIndex]['titlu'] = mw.text.trim(origArgs['titlu_atestare' .. variableIndexStr] or 'Atestare')
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'p')
		if nlStart == 1 then
			local pIndex = mw.ustring.find(argN, "%d+$")
			if pIndex == 2 then
				local variableIndexStr = mw.ustring.sub(argN, 2, #argN)
				local variableIndex = tonumber(variableIndexStr)
				if mw.text.trim(argV) ~= '' then
					args['p'][variableIndex] = mw.text.trim(argV)
				end
			end
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'lider_')
		if nlStart == 1 then
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local indexLocation = mw.ustring.find(varNameWithIndex, "%d+") or (1 + #varNameWithIndex)
			local variableName = mw.ustring.sub(varNameWithIndex, 1, indexLocation - 1)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, indexLocation, #varNameWithIndex) or ""
			local variableIndex
			if variableIndexStr == "" then variableIndex = 1 else variableIndex = 1 + tonumber(variableIndexStr) end
			if args['lideri'][variableIndex] == nil then args['lideri'][variableIndex] = {} end
			args['lideri'][variableIndex][variableName] = mw.text.trim(argV)
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'area_blank')
		if nlStart == 1 then
			if args['suprafata']['blank'] == nil then args['suprafata']['blank'] = {} end
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local varNameLocation = mw.ustring.find(varNameWithIndex, "[^%d]") or (1 + #varNameWithIndex)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, 1, varNameLocation - 1)
			local variableName = mw.ustring.sub(varNameWithIndex, mw.ustring.find(varNameWithIndex, '%a[%w_]+') or (1 + #varNameWithIndex), #varNameWithIndex)
			local variableIndex = tonumber(variableIndexStr)
			if args['suprafata']['blank'][variableIndex] == nil then args['suprafata']['blank'][variableIndex] = {} end
			args['suprafata']['blank'][variableIndex][variableName] = mw.text.trim(argV)
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'population_blank')
		if nlStart == 1 then
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local varNameLocation = mw.ustring.find(varNameWithIndex, "[^%d]") or (1 + #varNameWithIndex)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, 1, varNameLocation - 1)
			local variableName = mw.ustring.sub(varNameWithIndex, mw.ustring.find(varNameWithIndex, "%a[%w_]+") or (1 + #varNameWithIndex), #varNameWithIndex)
			local variableIndex = tonumber(variableIndexStr)
			if args['population_blank'][variableIndex] == nil then args['population_blank'][variableIndex] = {} end
			if isNilOrEmpty(variableName) then
				args['population_blank'][variableIndex]['value'] = mw.text.trim(argV)
			else
				args['population_blank'][variableIndex][variableName] = mw.text.trim(argV)
			end
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'densitate_populație_blank')
		if nlStart == 1 then
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local varNameLocation = mw.ustring.find(varNameWithIndex, "[^%d]") or (1 + #varNameWithIndex)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, 1, varNameLocation - 1)
			local variablePostIndexStr = mw.ustring.find(varNameWithIndex, "%a[%w_]+") or (1 + #varNameWithIndex)
			local variableName = mw.ustring.sub(varNameWithIndex, variablePostIndexStr, #varNameWithIndex)
			local variableIndex = tonumber(variableIndexStr)
			if args['population_blank'][variableIndex] == nil then args['population_blank'][variableIndex] = {} end
			if isNilOrEmpty(variableName) or variableName == 'km2' then
				args['population_blank'][variableIndex]['densitate'] = mw.text.trim(argV)
			else
				if variableName == 'sqmi' or variableName == 'sq_mi' then args['population_blank'][variableIndex]['densitate'] = tostring(round(tonumber(argV) / 2.58998811)) end
			end
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'postal')
		if nlStart == 1 then
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local varNameLocation = mw.ustring.find(varNameWithIndex, "[^%d]") or (1 + #varNameWithIndex)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, 1, varNameLocation - 1)
			local variableName = mw.ustring.sub(varNameWithIndex, mw.ustring.find(varNameWithIndex, "%a[%w_]+") or (1 + #varNameWithIndex), #varNameWithIndex)
			if not isNilOrEmpty(variableIndexStr) then
				local variableIndex = tonumber(variableIndexStr)
				if args['postal_codes'][variableIndex] == nil then args['postal_codes'][variableIndex] = {} end
				args['postal_codes'][variableName] = mw.text.trim(argV)
			end
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'infratit')
		if nlStart == 1 then
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local varNameLocation = mw.ustring.find(varNameWithIndex, "[^%d]") or (1 + #varNameWithIndex)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, 1, varNameLocation - 1)
			local varNamePostIndex = mw.ustring.find(varNameWithIndex, "%a[%w_]+") or (1 + #varNameWithIndex)
			local variableName = mw.ustring.sub(varNameWithIndex, varNamePostIndex, #varNameWithIndex)
			local variableIndex = tonumber(variableIndexStr)

			if args['infratiri'][variableIndex] == nil then args['infratiri'][variableIndex] = {} end
			if isNilOrEmpty(variableName) then
				args['infratiri'][variableIndex]['oras'] = mw.text.trim(argV)
			else
				args['infratiri'][variableIndex][variableName] = mw.text.trim(argV)
			end
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'camp')
		if nlStart == 1 then
			local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
			local varNameLocation = mw.ustring.find(varNameWithIndex, "[^%d]") or (1 + #varNameWithIndex)
			local variableIndexStr = mw.ustring.sub(varNameWithIndex, 1, varNameLocation - 1)
			if isNilOrEmpty(variableIndexStr) then variableIndexStr = 1 end
			local variableName = mw.ustring.sub(varNameWithIndex, mw.ustring.find(varNameWithIndex, '%a[%w_]+') or (1 + #varNameWithIndex), #varNameWithIndex)
			local variableIndex = 1 + tonumber(variableIndexStr)
			if args['campuri_goale'][variableIndex] == nil then args['campuri_goale'][variableIndex] = {} end
			args['campuri_goale'][variableIndex][variableName] = mw.text.trim(argV)
		end
		nlStart, nlEnd = mw.ustring.find(argN, 'hartă%d*')
		if nlStart == 1 then
			local variableIndex, variableIndexStr
			if argN == 'hartă' then
				variableIndex = 1
				variableIndexStr = ''
			else
				local indexLocation = mw.ustring.find(argN, "%d+")
				variableIndexStr = mw.ustring.sub(argN, indexLocation, mw.ustring.len(argN))
				if tonumber(variableIndexStr) ~= nil then
					variableIndex = 1 + tonumber(variableIndexStr)
				else
					variableIndex = -1
				end	
			end
			if variableIndex > 0 then
				--append unit if implicit
				if (tonumber(origArgs['dimensiune_hartă' .. variableIndexStr]) or 0) > 0 then 
					origArgs['dimensiune_hartă' .. variableIndexStr] = StringUtils._appendToString({origArgs['dimensiune_hartă' .. variableIndexStr], 'px'})
				end
				if args['harti'][variableIndex] == nil then args['harti'][variableIndex] = {} end
				args['harti'][variableIndex]['harta'] = argV
				args['harti'][variableIndex]['descriere'] = origArgs['descriere_hartă' .. variableIndexStr]
				args['harti'][variableIndex]['size'] = origArgs['dimensiune_hartă' .. variableIndexStr] or '290x290px'
			end
		end
	
		local embedMatcher, embedIdxStr = mw.ustring.match(argN, '(embedded(%d+))')
		if embedMatcher == argN then
			embedIdx = tonumber(embedIdxStr)
			args['embedded'][embedIdx] = argV
		end
	end
	args['harti'] = TableTools.compressSparseArray(args['harti'])
	args['embedded'] = TableTools.compressSparseArray(args['embedded'])
	
	--- populate from Wikidata
	if isNilOrEmpty(args['nume_nativ']) then
		local nativeNamesClaims = wikidata.findBestClaimsForProperty(nil, 'P1705')
		if nativeNamesClaims then
			local nativeNamesList = {}
			for _,eachNativeNamesClaims in ipairs(nativeNamesClaims) do
				if eachNativeNamesClaims.type == 'statement' and eachNativeNamesClaims.mainsnak.snaktype == 'value' 
					and args['nume'] ~= eachNativeNamesClaims.mainsnak.datavalue.value.text
					then
						local nativeNameText = eachNativeNamesClaims.mainsnak.datavalue.value.language == 'ro' and eachNativeNamesClaims.mainsnak.datavalue.value.text or wrapInLangSpan(eachNativeNamesClaims.mainsnak.datavalue.value.language, eachNativeNamesClaims.mainsnak.datavalue.value.text)
						table.insert(nativeNamesList, nativeNameText)
					end
			end
			args['nume_nativ'] = table.concat(nativeNamesList, _br_)
		end
	end
	
	if not isNilOrEmpty(origArgs['an']) then
		if args['atestari'][1] == nil then args['atestari'][1] = {} end
		args['atestari'][1]['an'] = origArgs['an']
		args['atestari'][1]['titlu'] = origArgs['titlu_atestare'] or 'Atestare'
	end
	if table.maxn(args['atestari']) == 0  then 
		local inception = {}
		inception['titlu'] = origArgs['titlu_atestare'] or 'Atestare'
		local inceptionDate = wikidata.findDateValues('P571')
		if inceptionDate and #inceptionDate > 0 then
			inception['an'] = StringUtils._appendToString({DateUtils.formatDate(inceptionDate[1]), editWD.displayMessage('P571')})
			table.insert(args['atestari'], inception)
		end
		
		local disestablishment = {}
		disestablishment['titlu'] = 'Dispariție'
		local disestablishmentDate = wikidata.findDateValues('P576')
		if disestablishmentDate and 0 < #disestablishmentDate then
			disestablishment['an'] = StringUtils._appendToString({DateUtils.formatDate(disestablishmentDate[1]), editWD.displayMessage('P576')})
			table.insert(args['atestari'], disestablishment)
		end
		
	end
	
	--lideri
	local wikidataMayorClaims = wikidata.findBestClaimsForProperty(nil, 'P6')
	if wikidataMayorClaims and wikidataMayorClaims[1] then
		local firstWikidataMayorClaimIndex = 1
		while firstWikidataMayorClaimIndex <= #wikidataMayorClaims and wikidataMayorClaims[firstWikidataMayorClaimIndex].mainsnak.snaktype ~= 'value' do
			firstWikidataMayorClaimIndex = firstWikidataMayorClaimIndex + 1
		end
		if firstWikidataMayorClaimIndex <= #wikidataMayorClaims and wikidataMayorClaims[firstWikidataMayorClaimIndex].mainsnak.snaktype == 'value' and wikidataMayorClaims[firstWikidataMayorClaimIndex].mainsnak.datavalue.type == 'wikibase-entityid' then
			local wikidataMayorId = wikidataMayorClaims[firstWikidataMayorClaimIndex].mainsnak.datavalue.value['numeric-id']
			local wikidataMayorName = wikidata.findLinkToItem(StringUtils._prependIfMissing({tostring(wikidataMayorId), 'Q'}))
			if not isNilOrEmpty(wikidataMayorName) then
				if args['lideri'][1] == nil then args['lideri'][1] = {} end
				args['lideri'][1]['nume'] = wikidataMayorName .. wikidata.outputReferences(wikidataMayorClaims[1])
				args['lideri'][1]['ales'] = wikidata.findLatestQualifierDateValueForOneProperty('P6', 'P580')
				local mayorParty = wikidata.getBestEntityIdsList(StringUtils._prependIfMissing({tostring(wikidataMayorId), 'Q'}), 'P102')
				if mayorParty and mayorParty[1] then
					local mayorPartyIdStr = StringUtils._prependIfMissing({tostring(mayorParty[1]), 'Q'})
					args['lideri'][1]['partid'] = wikidata.findLinkToItemWithCallback(mayorPartyIdStr, true, function(object)
						local partyNameClaim = wikidata.findClaimForTimestamp(mayorPartyIdStr, 'P1813', nil)
						if not partyNameClaim then
							partyNameClaim = wikidata.findClaimForTimestamp(mayorPartyIdStr, 'P1448', nil)
						end
						if partyNameClaim then return partyNameClaim.mainsnak.datavalue.value.text end
						return nil
					end)
				end
			end
		end
	end

	if args['lideri'][1] ~= nil and isNilOrEmpty(args['lideri'][1]['titlu']) then 
		local wikidataMayorTitle = wikidata.findOneValue('P1313')
		if not isNilOrEmpty(wikidataMayorTitle) then
			args['lideri'][1]['titlu'] = wikidataMayorTitle
		else
			args['lideri'][1]['titlu'] = 'Primar' 
		end
	end
	for i = 1,table.maxn(args['nume_limba']) do
		if args['nume_limba'][i] then
			for argN, argV in pairs(origArgs) do
				nlStart, nlEnd = mw.ustring.find(argN, 'nume_limba' .. tostring(i) .. "_")
				if nlStart == 1 then
					local varNameWithIndex = mw.ustring.sub(argN, 1 + nlEnd, mw.ustring.len(argN))
					local indexLocation = mw.ustring.find(varNameWithIndex, "%d+") or (1 + #varNameWithIndex)
					local variableName = mw.ustring.sub(varNameWithIndex, 1, indexLocation - 1)
					local variableIndexStr = mw.ustring.sub(varNameWithIndex, indexLocation, #varNameWithIndex)
					local variableIndex
					if variableIndexStr == nil or variableIndexStr == "" then variableIndex = 1 else variableIndex = 1 + tonumber(variableIndexStr) end
					if args['nume_limba'][i][variableName] == nil then args['nume_limba'][i][variableName] = {} end
					args['nume_limba'][i][variableName][variableIndex] = mw.text.trim(argV)
				end
			end
		end
	end
	if table.maxn(args['infratiri']) == 0 then
		local infratiri = wikidata.getEntityIdsList(nil, 'P190')
		if infratiri then
			if #infratiri > 12 then
				args['infratiri'][1] = {}
				args['infratiri'][1]['oras'] = tostring(#infratiri) .. ' orașe înfrățite'
				args['infratiri'][1]['tara'] = '[[:d:' .. wikidata.getEntityId() .. '#P190|listă]]'
			else
				for infrIdx = 1,#infratiri do
					args['infratiri'][infrIdx] = {}
					args['infratiri'][infrIdx]['oras'] = wikidata.findLinkToItem(infratiri[infrIdx])
					local sisterCityCountry = wikidata.loadOneValueInChain({'Q' .. infratiri[infrIdx], 'P17'})
					if not isNilOrEmpty(sisterCityCountry) then
						args['infratiri'][infrIdx]['tara'] = sisterCityCountry
					end
				end
			end
		end
	end
	if table.maxn(args['pushpin']) == 0 then
		local countryName = wikidata.loadOneValueInChain({'P17', 'label'})
		if countryName then
			local defaultPushpin = {}
			defaultPushpin.map = countryName
			defaultPushpin.size = 290
			defaultPushpin.caption = 'Poziția geografică în ' .. countryName
			defaultPushpin.label_position = args['pushpin_label_position'] or 'left'
			defaultPushpin.mapframe = true
			table.insert(args['pushpin'], defaultPushpin)
		end
	end

	if args['suprafata']['totala'] == nil then
		local areaClaims = wikidata.findBestClaimsForProperty(nil, 'P2046') -- area
		if areaClaims then for _,eachAreaClaim in pairs(areaClaims) do
			if eachAreaClaim.type == 'statement' and eachAreaClaim.mainsnak.snaktype == 'value' and eachAreaClaim.mainsnak.datavalue.value.unit ~= '1' then
				local areaQty = eachAreaClaim.mainsnak.datavalue.value.amount
				local areaUnitURL = eachAreaClaim.mainsnak.datavalue.value.unit
				local areaUnitId = StringUtils._removeStart({areaUnitURL, 'http://www.wikidata.org/entity/'})
				-- TODO maybe other units should be supported here?
				if areaQty ~= nil and areaUnitId == 'Q712226' then
					if args['suprafata']['totala'] == nil then args['suprafata']['totala'] = {} end
					args['suprafata']['totala']['km2'] = lang:formatNum(tonumber(areaQty))
					args['note_subsol_suprafata'] = wikidata.outputReferences(eachAreaClaim)
				end
			end
		end end
	end
	
	local wikidataImage, wikidataImageCaption = wikidata.findImageAndCaption()
	if origArgs['imagine'] then
		args['imagine'] = origArgs['imagine']
		args['imagine_descriere'] = origArgs['imagine_descriere'] or ''
	elseif wikidataImage then
		args['imagine'] = wikidataImage
		args['imagine_descriere'] = wikidataImageCaption
	end
			
	if not isNilOrEmpty(origArgs['imagine_dimensiune']) then
		args['imagine_dimensiune'] = origArgs['imagine_dimensiune']
	else
		args['imagine_dimensiune'] = "290x290px"
	end

	args['drapel'] = origArgs['drapel'] or origArgs['steag'] or origArgs['steag_imagine'] or wikidata.findOneValueNoRef('P41', nil)
	args['image_seal'] = origArgs['image_seal'] or wikidata.findOneValueNoRef('P158', nil)
	args['emblemă_imagine'] = origArgs['emblemă_imagine'] or origArgs['emblema_imagine']
	args['stemă'] = origArgs['stemă'] or origArgs['stema'] or wikidata.findOneValueNoRef('P94', nil)
	args['drapel_dimensiune'] = origArgs['drapel_dimensiune'] or origArgs['steag_dimensiune'] or '100x100px'
	args['link_drapel'] = origArgs['link_drapel'] or origArgs['steag_link'] or returnIfPageExists('Drapelul orașului ' .. mw.title.getCurrentTitle().text) or wikidata.findOneValueNoRef('P162', nil)
	args['seal_size'] = origArgs['seal_size'] or '100px'
	args['seal_link'] = origArgs['seal_link'] or returnIfPageExists('Sigiliul orașului ' .. mw.title.getCurrentTitle().text) or ((not isNilOrEmpty(args['nume_oficial']) and returnIfPageExists('Sigiliul orașului ' .. args['nume_oficial']) or ''))
	args['link_stemă'] = origArgs['link_stemă'] or origArgs['stemă_link'] or returnIfPageExists('Stema ' .. mw.title.getCurrentTitle().text) or ((not isNilOrEmpty(args['nume_oficial']) and returnIfPageExists('Stema ' .. args['nume_oficial']) or ''))
	args['stemă_dimensiune'] = origArgs['stemă_dimensiune'] or '100x100px'
	args['emblemă_link'] = origArgs['emblemă_link'] or origArgs['emblema_link'] or returnIfPageExists('Logo-ul ' .. mw.title.getCurrentTitle().text) or ((not isNilOrEmpty(args['nume_oficial']) and returnIfPageExists('Logo-ul ' .. args['nume_oficial']) or ''))
	args['emblemă_dimensiune'] = origArgs['emblemă_dimensiune'] or origArgs['emblema_dimensiune'] or '100x100px'
	args['emblemă_tip'] = origArgs['emblemă_tip'] or origArgs['emblema_tip'] or 'Logo'
	
	args['poreclă'] = origArgs['porecla'] or origArgs['poreclă'] or ""
	args['motto'] = origArgs['motto'] or ""
	if not isNilOrEmpty(origArgs['hartă_punct_imagine']) then
		args['hartă_punct'] = {}
		args['hartă_punct'].imagine = origArgs['hartă_punct_imagine']
		args['hartă_punct'].dimensiune = origArgs['hartă_punct_dimensiune'] or '180px'
		args['hartă_punct'].descriere = origArgs['hartă_punct_descriere'] or ''
		args['hartă_punct'].x = origArgs['dot_x'] or ''
		args['hartă_punct'].y = origArgs['dot_y'] or ''
	end
	args['latd'] = origArgs['latd'] or origArgs['lat_d'] or ''
	args['latm'] = origArgs['latm'] or origArgs['lat_m'] or ''
	args['lats'] = origArgs['lats'] or origArgs['lat_s'] or ''
	args['latNS'] = origArgs['lat_NS'] or origArgs['latNS']
	args['longd'] = origArgs['longd'] or origArgs['long_d'] or ''
	args['longm'] = origArgs['longm'] or origArgs['long_m'] or ''
	args['longs'] = origArgs['longs'] or origArgs['long_s'] or ''
	args['longEV'] = origArgs['longEV'] or origArgs['long_EV'] or origArgs['longEW'] or origArgs['long_EW']
	args['coords_in_title'] = 'yes'
	if isNilOrEmpty(args['latd']) then
		local wikidataCoords = wikidata.findDataValueObjects(nil, 'P625')
		if wikidataCoords[1] then
			args['latd'] = tostring(math.abs(wikidataCoords[1].latitude))
			if wikidataCoords[1].latitude < 0 then args['latNS'] = 'S' else args['latNS'] = 'N' end
			args['longd'] = tostring(math.abs(wikidataCoords[1].longitude))
			if wikidataCoords[1].longitude < 0 then args['longEV'] = 'V' else args['longEV'] = 'E' end
			args['coords_in_title'] = ''
		end
	end
	args['background'] = origArgs['background'] or ''
	args['tip_coordonate'] = origArgs['tip_coordonate'] or ''
	args['coordinates_type'] = origArgs['coordinates_type'] or 'type:city'
	args['coordonate'] = origArgs['coordonate'] or ''
	args['fondator'] = origArgs['fondator'] or ''
	args['numit_dupa'] = origArgs['numit_dupa'] or origArgs['numit_după'] or wikidata.findOneValue('P138', nil)
	
	args['resedinta'] = origArgs['reședință'] or origArgs['resedinta'] or origArgs['reședința'] or wikidata.findOneValue('P36', nil)
	args['tip_resedinta'] = origArgs['tip_resedinta'] or origArgs['tip_reședință'] or 'Reședință'
	args['componenta'] = origArgs['componenta'] or ''
	args['tip_componenta'] = mw.text.trim(origArgs['componenta_tip'] or origArgs['tip_componenta'] or origArgs['tip_componență'] or origArgs['componență_tip'] or 'Componență')
	args['stil_componenta'] = mw.text.trim(origArgs['componenta_stil'] or '')
	
	args['tip_guvernare'] = mw.text.trim(origArgs['guvernare_tip'] or origArgs['tip_guvernare'] or '')
	args['guvernare_note_subsol'] = mw.text.trim(origArgs['guvernare_note_subsol'] or '')
	
	local tipuriSuprafata = { 'totală', 'metropolitană', 'urbană', 'apă', 'pământ' }
	local unitatiSuprafata = { 'km2', 'dunam', 'sqmi', 'ha', 'procent' }
	for tipK, tipV in pairs(tipuriSuprafata) do
		for unitK, unitV in pairs(unitatiSuprafata) do
			local argument = 'suprafață_' .. tipV .. '_' .. unitV
			if not isNilOrEmpty(origArgs[argument] or origArgs[removeDiacritics(argument)]) then
				if args['suprafata'][removeDiacritics(tipV)] == nil then args['suprafata'][removeDiacritics(tipV)] = {} end
				local crtArg = origArgs[argument] or origArgs[removeDiacritics(argument)]
				args['suprafata'][removeDiacritics(tipV)][unitV] = crtArg
				if args['suprafata'][removeDiacritics(tipV)]['km2'] == nil then
					if unitV == 'dunam' then args['suprafata'][removeDiacritics(tipV)]['km2'] = tostring(round(.001 * tonumber(crtArg), 2))
					elseif unitV == 'sqmi' then args['suprafata'][removeDiacritics(tipV)]['km2'] = tostring(round(convertSqMiToKm2(tonumber(crtArg)), 2))
					elseif unitV == 'ha' then args['suprafata'][removeDiacritics(tipV)]['km2'] = tostring(round(.01 * tonumber(crtArg), 2)) end
				end
			end
		end
	end
	args['note_subsol_suprafata'] = mw.text.trim(args['note_subsol_suprafata'] or origArgs['note_subsol_suprafata'] or origArgs['suprafata_note_subsol'] or '')
	args['tip_total'] = mw.text.trim(origArgs['tip_total'] or '')
	args['note_subsol_altitudine'] = mw.text.trim(args['note_subsol_altitudine'] or origArgs['note_subsol_altitudine'] or origArgs['altitudine_note_subsol'] or '')
	local unitatiAltitudine = { 'm', 'ft' }
	local tipuriAltitudine = { '', 'max', 'min' }
	for tipK, tipV in pairs(tipuriAltitudine) do
		for unitK, unitV in pairs(unitatiAltitudine) do
			local crtArg = 'altitudine' .. (tipV ~= '' and '_' or '') .. tipV .. '_' .. unitV
			local translatedArg = 'altitudine' .. (tipV ~= '' and '_' or '') .. tipV .. (unitV ~= '' and ('_' .. unitV) or '')
			local translatedArgM = 'altitudine' .. (tipV ~= '' and '_' or '') .. tipV .. (tipV ~= '' and '_m' or '')
			if not isNilOrEmpty(origArgs[crtArg]) or not isNilOrEmpty(origArgs[translatedArg]) then
				args[translatedArg] = mw.text.trim(origArgs[crtArg] or origArgs[translatedArg])
				if unitV == 'ft' and args[translatedArgM] == nil and tonumber(args[translatedArg]) then 
					args[translatedArgM] = tostring(round(convertFtToM(tonumber(mw.text.trim(args[translatedArg]))), 0))
				end
			end
		end
	end
	

	args['populatie_urbana'] = origArgs['populatie_urbana'] or origArgs['populație_urbană'] or origArgs['populație_urbana']
	args['densitate_pop_urbana'] = origArgs['densitate_populație_urbana_km2']
	args['populatie_metropolitana'] = origArgs['populatie_metropolitana'] or origArgs['populație_metropolitană'] or origArgs['populație_metropolitana']
	args['densitate_pop_metro'] = origArgs['densitate_populație_metro_km2']
	args['recensamant'] = origArgs['recensamant'] or origArgs['recensământ']
	args['populatie'] = origArgs['populatie'] or origArgs['populație']
	if args['populatie'] == nil or mw.text.trim(args['populatie']) == '' then
		extractPopulationFromWikidata(args)
	end
	args['note_subsol_populatie'] = origArgs['note_subsol_populatie'] or origArgs['populatie_note_subsol'] or origArgs['populație_note_subsol'] or ''
	args['densitate'] = origArgs['densitate']
	args['populatie_note'] = origArgs['populatie_note'] or origArgs['populație_note']
	
	args['fus_orar'] = origArgs['fus_orar'] or origArgs['timezone'] or wikidata.findOneValue('P421', nil)
	args['utc_offset'] = origArgs['utc_offset']
	args['fus_orar_DST'] = origArgs['fus_orar_DST'] or origArgs['timezone_DST']
	args['utc_offset_DST'] = origArgs['utc_offset_DST']
	args['cod_postal'] = origArgs['codpoștal'] or origArgs['codpostal'] or origArgs['cod_poștal'] or origArgs['cod_postal'] or origArgs['postal_code'] or wikidata.findOneValue('P281', nil)
	args['tip_cod_postal'] = mw.text.trim(origArgs['tip_cod_postal'] or '[[Cod poștal]]')
	args['prefix_tel'] = origArgs['prefix_telefonic'] or origArgs['area_code'] or wikidata.findOneValue('P473', nil)
	args['cod'] = origArgs['cod']
	args['tip_cod'] = mw.text.trim(origArgs['tip_cod'] or '[[Cod]]')
	
	args['note'] = origArgs['note']
	
	args['webaddr'] = origArgs['sit-adresă'] or origArgs['website'] or origArgs['web']
	args['webname'] = origArgs['sit-nume']
	if args['webaddr'] and args['webname'] then
		args['website'] = '[' .. args['webaddr'] .. ' ' .. args['webname'] .. ']'
	elseif args['webaddr'] then
		args['website'] = args['webaddr']
	else
		args['website'] = origArgs['website']
	end
	args['infodoc'] = origArgs['infodoc'] or 'Infocaseta Așezare'

	if args['harti'][1] == nil then
		local wikidataMap = wikidata.findOneValueNoRef('P242', nil)
		if not isNilOrEmpty(wikidataMap) then
			args['harti'][1] = {}
			args['harti'][1]['harta'] = wikidataMap
		end
	end
	if args['harti'][1] ~= nil and isNilOrEmpty(args['harti'][1]['descriere']) then
		args['harti'][1]['descriere'] = 'Poziția ' .. args['tip_asezare_genitiv'] .. ' ' .. args['nume']
	end
	if args['harti'][1] ~= nil and isNilOrEmpty(args['harti'][1]['size']) then
		args['harti'][1]['size'] = '290x290px'
	end
	if args['subdiviziuni'][1] == nil or isNilOrEmpty(args['subdiviziuni'][1]['nume']) then
		local wikidataCountryIds = wikidata.getBestEntityIdsList(nil, 'P17')
		if wikidataCountryIds and wikidataCountryIds[1] then
			local wikidataCountry = NameAndImage._nameAndImage(StringUtils._prependIfMissing({tostring(wikidataCountryIds[1]), 'Q'}), 'P41')
			if not isNilOrEmpty(wikidataCountry) then
				if args['subdiviziuni'][1] == nil then args['subdiviziuni'][1] = {} end
				args['subdiviziuni'][1]['nume'] = wikidataCountry
				args['subdiviziuni'][1]['tip'] = '[[Țările lumii|Țară]]'
			end
		end
	end
	if args['subdiviziuni'][2] == nil or isNilOrEmpty(args['subdiviziuni'][2]['nume']) then
		local claims = wikidata.findSortedClaimsForProperty(nil, 'P131')
		if claims and #claims > 0 then
			local subdivs = {}
			while table.maxn(claims) > 0 do
				local eachSubdivClaim = table.remove(claims, 1)
				if wikidata.hasBetterRank(eachSubdivClaim, 'preferred') or eachSubdivClaim.qualifiers == nil or eachSubdivClaim.qualifiers['P582'] == nil then
					local eachSubdiv = nil
					if wikidata.hasValueSnak(eachSubdivClaim) and wikidata.isClaimTrue(eachSubdivClaim) then
						eachSubdiv = eachSubdivClaim.mainsnak.datavalue.value['numeric-id']
					end
					if not isNilOrEmpty(eachSubdiv) then
						if not wikidata.isA('Q' .. eachSubdiv, { 'Q6256' }) then -- is country
							local subdivAlreadyPresent = false
							for subdivIdx,eachExistingSubdiv in pairs(subdivs) do
								if eachExistingSubdiv == eachSubdiv then
									subdivAlreadyPresent = true
								end
							end
							if not subdivAlreadyPresent then
								table.insert(subdivs, 1, eachSubdiv)
								local recurrentClaims = wikidata.findSortedClaimsForProperty('Q' .. eachSubdiv, 'P131')
								while table.maxn(recurrentClaims) > 0 do
									table.insert(claims, 1, table.remove(recurrentClaims, 1))
								end
							end --if not subdivAlreadyPresent
						end --if not isCountry
					end --if not isNilOrEmpty(eachSubdiv)
				end --if isNilOrEmpty(eachSubdivClaim['qualifiers']['P582'])
			end --while table.maxn(claims)
			for subdivIdx = 1,#subdivs do
				if args['subdiviziuni'][1 + subdivIdx] == nil then args['subdiviziuni'][1 + subdivIdx] = {} end
				args['subdiviziuni'][1 + subdivIdx]['nume'] = NameAndImage._nameAndImageFromOneOfProps('Q' .. tostring(subdivs[subdivIdx]), { 'P41', 'P94' })
				local divisionTypes = wikidata.getEntityIdsList('Q' .. subdivs[subdivIdx], 'P31')
				if divisionTypes and divisionTypes[1] then
					args['subdiviziuni'][1 + subdivIdx]['tip'] = wikidata.findLinkToItem(divisionTypes[1], true)
				else
					args['subdiviziuni'][1 + subdivIdx]['tip'] = '&nbsp;'
				end
			end
		end
	end

	if #(args['clasificari']) == 0 then
		local classificationPs = {'P843', 'P3990', 'P1077', 'P374', 'P2586', 'P2585', 'P3423', 'P635'}
		for _,eachClassificationP in ipairs(classificationPs) do
			local classificationValue = wikidata.findOneValueNoRef(eachClassificationP)
			if classificationValue then
				local crtClassificationFormatter = wikidata.findOneValueNoRef('P1630', eachClassificationP)
				local classificationLink = nil
				if crtClassificationFormatter then
					local classificationValueForLinkFormatting = mw.ustring.gsub(classificationValue, '%%', '%%%%')
					classificationLink = mw.ustring.gsub(crtClassificationFormatter, '$1', classificationValueForLinkFormatting)
				end
				local crtClassification = {}
				crtClassification.cod = classificationLink and ('[' .. classificationLink .. ' ' .. classificationValue .. ']') or classificationValue
				crtClassification.tip = wikidata.findOneValueNoRef('P1629', eachClassificationP)
				
				table.insert(args['clasificari'], crtClassification)
				
			end
		end
	end

	if isNilOrEmpty(args['altitudine']) and isNilOrEmpty(args['altitudine_m']) then
		args['altitudine'] = nil
		local altClaims = wikidata.findBestClaimsForProperty(nil, 'P2044') -- elevation above sea level
		if altClaims then for _,eachAltClaim in pairs(altClaims) do
			if eachAltClaim.type == 'statement' and eachAltClaim.mainsnak.snaktype == 'value' and eachAltClaim.mainsnak.datavalue.value.unit ~= '1' then
				local altQty = eachAltClaim.mainsnak.datavalue.value.amount
				if altQty ~= nil then
					local altUnitURL = eachAltClaim.mainsnak.datavalue.value.unit
					local altUnitId = StringUtils._removeStart({altUnitURL, 'http://www.wikidata.org/entity/'})
					local maxAlt = eachAltClaim.mainsnak.datavalue.value.upperBound or altQty
					local minAlt = eachAltClaim.mainsnak.datavalue.value.lowerBound or altQty
					if altUnitId == 'Q3710' then -- if unit is ft
						if altQty then altQty = round(convertFtToM(altQty), 0) end
						if maxAlt then maxAlt = round(convertFtToM(maxAlt), 0) end
						if minAlt then minAlt = round(convertFtToM(minAlt), 0) end
					end
					if maxAlt - altQty > 1 or altQty - minAlt > 1 then
						args['altitudine_min_m'] = lang:formatNum(tonumber(minAlt))
						args['altitudine_max_m'] = lang:formatNum(tonumber(maxAlt))
					else
						args['altitudine'] = lang:formatNum(tonumber(altQty))
					end
					args['note_subsol_altitudine'] = wikidata.outputReferences(eachAltClaim)
				end
			end
		end end
	end
	
	return _generate()
end
return p