模組:WikidataDescription

-- Simple wrapper for mw.wikibase.description
local p = {}

function p._fromQID(qid, prefix)
	local prefix = prefix or ''
	local result, lang = mw.wikibase.getDescriptionWithLang(qid)
	-- don't get english fallback results
	if result and string.sub(lang,0,2) == 'zh' then
		return prefix .. result
	else
		return ''
	end
end

function p.fromQID(frame)
	return p._fromQID(frame.args[1], frame.args[2])
end

-- {{#Invoke:WikidataDescription|fromTitle|络丝蛋白}} => "人类大脑糖蛋白" 
-- {{#Invoke:WikidataDescription|fromTitle|络丝蛋白|,}} => ",人类大脑糖蛋白"
function p.fromTitle(frame)
	return p._fromQID(mw.wikibase.getEntityIdForTitle(frame.args[1]), frame.args[2])
end

return p