Modul:Wikidata/Formatters/wikibase-entityid
Vzhled
require 'Modul:No globals'
local p = {}
local lib = require 'Modul:Wikidata/lib'
-- @const
local default_langs = { 'cs', 'en', 'sk' }
local function constructLink(label, link, entityId, lang)
if link then
if label then
if lang ~= 'cs' then
return mw.ustring.format('<span lang="%s">[[%s|%s]]</span>', lang, link, label)
else
return '[[' .. link .. '|' .. label .. ']]'
end
else
return '[[' .. link .. ']]'
end
end
if label then
if lang ~= 'cs' then
return mw.ustring.format('<span lang="%s">%s</span>', lang, label)
else
return label
end
else
return p.getLinkWhenNonexistingLabel(entityId)
end
end
function p.getLinkWhenNonexistingLabel(entityId)
local i18n = mw.loadData('Modul:Wikidata/i18n')
local ImageFormatter = require 'Modul:ImageFormatter'
return ImageFormatter.makeImage('Wikidata-edit.svg', {
description = i18n['missing-label'],
link = 'd:' .. entityId,
size = '27x17px'
}) .. '<code>[[d:' .. entityId .. '|' .. entityId .. ']]</code>' .. lib.category('missing-label')
end
function p.formatEntityWithGender(value, options)
local entityId = lib.getEntityIdFromValue(value)
local Module = require 'Modul:Wikidata'
local gender = Module.getRawValueFromLua{
entity = options.entity,
property = 'P21'
}
local label, lang
if gender == 'Q6581072' then
label = Module.formatStatementsFromLua{
id = entityId,
limit = 1,
property = 'P2521',
rank = 'valid',
sort = 'rank',
withlang = 'cs' -- TODO: options.withlang or default_langs
}
end
if not label then
label, lang = lib.getLabelInLanguage(entityId, default_langs)
end
local link = mw.wikibase.sitelink(entityId)
return constructLink(label, link, entityId, lang or 'cs')
end
function p.formatEntityId(entityId, options)
local label, lang = lib.getLabelInLanguage(entityId, options.withlang or default_langs)
local link = mw.wikibase.sitelink(entityId)
return constructLink(label, link, entityId, lang or 'cs')
end
return p