Modul:Wikidata utilities: Unterschied zwischen den Versionen
getLabel: noFallback
(some ipairs replaced) |
(getLabel: noFallback) |
||
| Zeile 4: | Zeile 4: | ||
local WikidataUtilities = { | local WikidataUtilities = { | ||
suite = 'WikidataUtilities', | suite = 'WikidataUtilities', | ||
serial = '2022-05- | serial = '2022-05-26', | ||
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 | ||