Modul:Folkmängd WD

Från Wikipedia

Dokumentation [visa] [redigera] [historik] [rensa sidcachen]


local wikidata = require('Modul:Wikidata2').formatStatementsFromLua

p = {}

	function p.inv(frame)
	
		local args = frame:getParent().args
		local qid = args.qid
		local entity = {}
		if qid and qid ~= '' then
			entity = mw.wikibase.getEntityObject( qid )
		else
			entity = mw.wikibase.getEntityObject()
		end
		local s = wikidata({entity = entity, property = 'P1082', raw = 'true', sortbytime = 'chronological', enbarten = 'ja' , noref = 'ja', modifyqualifiertime = 'Y', noformatera = 'ja'})
		if not s or #s < 1 then 
			return '<span class="error">Data saknas</span>'
		end
		local folk = tonumber(plus(s[1].amount))
		if folk > 1000 then
			local folklog = math.floor(math.log10( folk )) -2
			folk = mw.getCurrentFrame():preprocess('{{#expr:' .. folk .. ' round ' .. -folklog .. '}}')
		end
		folk = mw.getCurrentFrame():preprocess('{{formatnum:' .. folk .. '}}')
		
		if s[1].datum then
			return folk .. ' invånare (' .. s[1].datum .. ')'
		else
			return folk .. ' invånare'
		end
	end

	function plus(a)
		if string.sub(a, 1, 1) == '+' then
			return string.sub(a, 2)
		end
		return a
	end
		
return p