יחידה:PropertyLink: הבדלים בין גרסאות בדף

מ פורמט למספרים כך שיכיל יחידות
מאין תקציר עריכה
שורה 12: שורה 12:
end
end
return ''
return ''
end
local function formatQuantity(property)
local propValue = property.mainsnak and property.mainsnak.datavalue
    local lang = mw.getContentLanguage()
local asOfDate = asOfDateQualifier(property)
local localAmount = lang:formatNum( tonumber(propValue.value.amount) )
local unit = ''
if propValue.value.unit and string.match( propValue.value.unit, 'http://www.wikidata.org/entity/' ) then
local unitEntityId = string.gsub( propValue.value.unit, 'http://www.wikidata.org/entity/', '' );
local unitEntity = mw.wikibase.getEntity( unitEntityId );
if unitEntity then
-- name from label
unit =  unitEntity:getLabel();
--  name from properties
if unitEntity.claims and unitEntity.claims.P558 then
local writingSystemElementId = 'Q33513'; -- hebrew writing system
local langElementId = 'Q9288'; -- hebrew
local labelFilter = 'P558[P282:' .. writingSystemElementId .. ', P407:' .. langElementId .. ']';
local WDS = require( 'Module:WikidataSelectors' );
local labelClaims = WDS.filter( unitEntity.claims, labelFilter );
for r, claim in pairs( labelClaims ) do
if claim.mainsnak
and claim.mainsnak.datavalue
and claim.mainsnak.datavalue.type == 'string'
and claim.mainsnak.datavalue.value ~= '' then
unit = claim.mainsnak.datavalue.value;
break;
end
end
end
unit = ' ' .. unit;
end
    end
return localAmount .. unit .. asOfDate
end
end


שורה 88: שורה 125:
     table.insert(resTable, propValue.value.text)
     table.insert(resTable, propValue.value.text)
    elseif propValue['type'] == 'quantity' then
    elseif propValue['type'] == 'quantity' then
    local lang = mw.getContentLanguage()
    table.insert(resTable, formatQuantity(property))
    local asOfDate = asOfDateQualifier(property)
    local formattedValue = mw.wikibase.formatValue(property.mainsnak) .. asOfDate
    table.insert(resTable, formattedValue)
    elseif propValue['type'] == 'time' then
    elseif propValue['type'] == 'time' then
    local timeValue = entity:formatPropertyValues( propertyName ).value
    local timeValue = entity:formatPropertyValues( propertyName ).value