Modul:Wikidata utilities: Unterschied zwischen den Versionen

K
89 Versionen von wikivoyage:Modul:Wikidata_utilities importiert
(some ipairs replaced)
K (89 Versionen von wikivoyage:Modul:Wikidata_utilities importiert)
 
(5 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 4: Zeile 4:
local WikidataUtilities = {
local WikidataUtilities = {
suite  = 'WikidataUtilities',
suite  = 'WikidataUtilities',
serial = '2022-05-04',
serial = '2022-09-04',
item  = 65439025
item  = 65439025
}
}
Zeile 68: Zeile 68:
end
end


function wu.getLabel( entity, lang )
function wu.getLabel( entity, lang, noFallback )
if not isSet( entity ) then
if not isSet( entity ) then
return nil
return nil
Zeile 75: Zeile 75:
if tp == 'string' and mw.wikibase.isValidEntityId( entity ) then
if tp == 'string' and mw.wikibase.isValidEntityId( entity ) then
return isSet( lang ) and mw.wikibase.getLabelByLang( entity, lang )
return isSet( lang ) and mw.wikibase.getLabelByLang( entity, lang )
or mw.wikibase.getLabel( entity )
or ( not noFallback and mw.wikibase.getLabel( entity ) )
elseif tp == 'table' and entity.labels then
elseif tp == 'table' and entity.labels then
return isSet( lang ) and entity:getLabel( lang ) or entity:getLabel()
return isSet( lang ) and entity:getLabel( lang )
or ( not noFallback and entity:getLabel() )
else
else
return nil
return nil
Zeile 214: Zeile 215:
function wu.getValuesByLang( entity, p, count, lang )
function wu.getValuesByLang( entity, p, count, lang )
local ar = {}
local ar = {}
local statements = wu.getStatements( entity, p, count )
local statements = wu.getStatements( entity, p )
if #statements > 0 then
if #statements > 0 then
local value
local value
Zeile 221: Zeile 222:
if value.language and lang == value.language then
if value.language and lang == value.language then
table.insert( ar, value.text )
table.insert( ar, value.text )
end
if count and #ar >= count then
break
end
end
end
end