Modul:Befolkningsdata
Utseende
Moduldokumentasjon
[opprett]
local p = {}
local wikidata = require('Module:Wikidata')
function p.populationTable(frame)
local entity = mw.wikibase.getEntityObject() -- get entity for current page
if not entity then return "Ingen Wikidata-element funnet." end
local statements = entity.claims and entity.claims.P1082
if not statements then return "Ingen befolkningsdata funnet på Wikidata." end
local rows = {}
table.insert(rows, '{| class="wikitable"\n! År !! Befolkning')
for _, statement in ipairs(statements) do
local time = statement.qualifiers and statement.qualifiers.P585 and statement.qualifiers.P585[1].datavalue.value.time
local year = time and string.match(time, "+(%d+)-")
local population = statement.mainsnak.datavalue and statement.mainsnak.datavalue.value.amount
if year and population then
local pop_number = tonumber(population)
if pop_number then
pop_number = mw.language.getContentLanguage():formatNum(pop_number)
table.insert(rows, string.format("\n|-\n| %s || %s", year, pop_number))
end
end
end
table.insert(rows, '\n|}')
return table.concat(rows)
end
return p