Jump to content

Module:AfricanWomenJournalistsLangs

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ibjaja055 (talk | contribs) at 23:32, 18 April 2025 (Created page with 'local p = {} local languages = { { code = "ha", label = "Hausa" }, { code = "ig", label = "Igbo" }, { code = "yo", label = "Yoruba" }, { code = "tw", label = "Twi" }, { code = "fat", label = "Fante" }, -- Fante does not yet have its own Wikipedia, this will always show "-" { code = "sw", label = "Swahili" }, { code = "rw", label = "Kinyarwanda" } } function makeLangCell(code, sitelinks) if sitelinks[code] then return '<span style="color:green; f...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
local p = {}

local languages = {
	{ code = "ha", label = "Hausa" },
	{ code = "ig", label = "Igbo" },
	{ code = "yo", label = "Yoruba" },
	{ code = "tw", label = "Twi" },
	{ code = "fat", label = "Fante" }, -- Fante does not yet have its own Wikipedia, this will always show "-"
	{ code = "sw", label = "Swahili" },
	{ code = "rw", label = "Kinyarwanda" }
}

function makeLangCell(code, sitelinks)
	if sitelinks[code] then
		return '<span style="color:green; font-weight:bold;">+</span>'
	else
		return '<span>-</span>'
	end
end

function p.table(frame)
	local items = {}
	for i = 1, #frame.args do
		local qid = frame.args[i]
		if mw.wikibase.isValidEntityId(qid) then
			table.insert(items, qid)
		end
	end

	local rows = {'{| class="wikitable sortable" style="text-align:left;"'}
	table.insert(rows, '! No. !! Image !! Name !! Description !! ' ..
		table.concat(
			mw.clone(languages):map(function(lang) return lang.label end),
			' !! '
		)
	)

	for i, qid in ipairs(items) do
		local label = mw.wikibase.getLabel(qid) or qid
		local description = mw.wikibase.getDescription(qid) or ''
		local img = mw.wikibase.getBestStatements(qid, 'P18')
		local image = ''

		if img and img[1] and img[1].mainsnak and img[1].mainsnak.datavalue then
			local filename = img[1].mainsnak.datavalue.value
			image = '[[File:' .. filename .. '|80x80px]]'
		end

		local sitelinks = {}
		for _, lang in ipairs(languages) do
			local title = mw.wikibase.getSitelink(qid, lang.code .. 'wiki')
			if title then sitelinks[lang.code] = true end
		end

		local cells = {}
		for _, lang in ipairs(languages) do
			table.insert(cells, makeLangCell(lang.code, sitelinks))
		end

		table.insert(rows,
			string.format('|-\n| %d || %s || [[%s]] || %s || %s',
				i, image, label, description, table.concat(cells, ' || ')
			)
		)
	end

	table.insert(rows, '|}')
	return table.concat(rows, '\n')
end

return p