Modulo:Wikidata/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
aggiornato all'uso della nuova mw.wikibase.getLabelByLang
spostato filtro lingua in getClaims
Riga 100:
 
local function formatMonolingualtext(value, args)
local ret = ''value.text
if args.showlang then
if not args.includelang or args.includelang:match('%f[a-z]' .. value.language .. '%f[^a-z]') then
ifret not= argsmLanguages.excludelang or not args.excludelang:matchlingue('%f[a-z]' ..{ value.language }) .. '%f[^a-z] ') then.. ret
ret = value.text
if args.showlang then
ret = mLanguages.lingue({ value.language }) .. ' ' .. ret
end
end
end
return ret
Line 413 ⟶ 408:
if claim.rank == rank then
table.insert(ret, claim)
end
end
return ret
end
 
-- Restituisce i claim con la lingua richiesta
local function filterByLanguage(claims, args)
local ret = {}
for i, claim in pairs(claims) do
if claim.mainsnak.snaktype == 'value' and claim.mainsnak.datavalue.type == 'monolingualtext' then
local value = claim.mainsnak.datavalue.value
if not args.includelang or args.includelang:match('%f[a-z]' .. value.language .. '%f[^a-z]') then
if not args.excludelang or not args.excludelang:match('%f[a-z]' .. value.language .. '%f[^a-z]') then
table.insert(ret, claim)
end
end
end
end
Line 438 ⟶ 449:
claims = mw.wikibase.getAllStatements(entityId, propertyId)
claims = filterRankValue(claims, args.rank)
end
-- statements filtrati per lingua con args.includelang/excludelang
if args.includelang or args.excludelang then
claims = filterByLanguage(claims, args)
end