Moduuli:WBDictionary

PartioWikistä
Siirry navigaatioon Siirry hakuun

Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:WBDictionary/ohje

local p = {}
local lang = mw.language.getContentLanguage()
local i18n =
{
	["errors"] =
	{
		["entity-not-found"] = "Wikidata entity not found.",
    }
}

-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Public functions
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getAllLabels fetches the set of labels and formats it for display as tabel rows.
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getAllLabels = function(frame)
	local args = frame.args or frame:getParent().args or {}

	local qid = args.qid or ""
	if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
	if not qid or not mw.wikibase.entityExists(qid) then return i18n["entity-not-found"] end

	local labels = mw.wikibase.getEntity(qid).labels
	if not labels then return i18n["labels-not-found"] end

	local out = {}
	for k, v in pairs(labels) do
		out[#out+1] = "<tr><td>" .. lang:ucfirst( mw.language.fetchLanguageName(v.language, lang:getCode() ) ).. "</td><td>" .. v.value .. "</td></tr>"
	end
	table.sort(out)
	return table.concat(out)
end

return p


-------------------------------------------------------------------------------
-- List of exported functions
-------------------------------------------------------------------------------
--[[
getAllLabels
--]]
-------------------------------------------------------------------------------