Modul:Populasyon
Seba na module şıma şenê yû pela dokumani vırazê Modul:Populasyon/dok
local p = {}
local getArgs = require('Modul:Arguments').getArgs
local wd -- lazily loaded Module:Wikidata
local entityId -- manually given entity id
local entity -- entity object
local function getNum(str)
if tonumber(str) then
return tonumber(str)
end
if type(str) ~= 'string' then
return nil
end
str = string.gsub(str, ' ', '')
str = string.gsub(str, ' ', '')
local lang = mw.language.getContentLanguage()
if lang:parseFormattedNumber(str) then
return lang:parseFormattedNumber(str)
end
return nil
end
local function getWd(args)
if not wd then
wd = require('Modul:Wikidata')
end
if not entity then
entity = mw.wikibase.getEntity(entityId)
end
args.first = true
return getNum( wd.formatStatements(nil, args, entity) )
end
local function getPop()
local wd = getWd{ property = 'P1082', format = 'raw' }
if wd then
return wd
end
if entity and entity.sitelinks.huwiki then
local title = 'Népesség/' .. entity.sitelinks.huwiki.title
if mw.title.new(title, 'Sablon').exists then
local templ = mw.getCurrentFrame():expandTemplate{ title = title, args = { 'szám' } }
return tonumber(templ)
end
end
return nil
end
local function getTer()
return getWd{ property = 'P2046', unit = 'km2' }
end
function p.main(frame)
local args = getArgs(frame)
local pop, ter, dens = args[1], args[2], args[3]
if dens then
return (dens ~= '-' and dens) or nil
end
if args.entityId and args.entityId ~= '' then
entityId = args.entityId
end
if pop == '-' or ter == '-' then
return nil
else
pop = getNum(pop)
ter = getNum(ter)
end
if not pop then
pop = getPop()
end
if not ter then
ter = getTer()
end
if pop and ter and ter ~= 0 then
dens = tonumber( mw.ext.ParserFunctions.expr( pop / ter .. ' round 2' ) )
return mw.language.getContentLanguage():formatNum( dens )
end
return nil
end
return p