Module:LanguageMatrix

Module documentation

This is a "flexible" language matrix based on Module:WikimediaCEETable. The module has multiple functions with different sets of languages so that the entire module doesn't need to be copy-pasted for each use case. Feel free to add new functions!

The current functions are:

  • {{#invoke:LanguageMatrix|Top20|...}} — Top 20 languages by number of speakers
  • {{#invoke:LanguageMatrix|CEE|...}} — Central and Eastern European languages
  • {{#invoke:LanguageMatrix|Nordic|...}} — Nordic languages and languages of neighboring countries; arranged by pageviews
  • {{#invoke:LanguageMatrix|African|...}} — Top 20 African languages, plus European languages spoken in Africa; arranged by pageviews [1]
  • {{#invoke:LanguageMatrix|Celtic|...}} — All 6 Celtic languages

Adding new varieties

edit

To add a new set of languages, you need to create a new function that defines langTable and resultTable. This should look like the following if you want a "generic" header row listing the language codes.

function p.Example(frame)
	langTable = {'en','zh','hi','es','fr','ar','ru','bn','pt','id'}
	resultTable = buildTableHeader(langTable)
	return p.table(frame, langTable, resultTable)
end

If you want a custom header row, for example including flags, you can do that by assigning resultTable directly.

-- Based on WikimediaCEETable: builds a list of articles based on information from Wikidata
-- Sample use: {{#invoke:LanguageMatrix|Top20|Q1|Q2|Q3|Q4|Q5}}
-- Can be used to list 400+ articles on 1 page
-- by User:Voll, with additions by Halibutt, Braveheart, Jura1, Iketsi, rewrite by John P. Sadowski (NIOSH)
-- Original at https://meta.wikimedia.org/wiki/Module:LanguageMatrix . Please contribute amendments there and keep copies in sync with that version.
--

local p = {}

function p.Top20(frame)
	langTable = {'en','zh','hi','es','fr','ar','ru','bn','pt','id','ur','de','ja','sw','pnb','jv','wuu','te','tr','ko'}
	resultTable = buildTableHeader(langTable)
	doautolist = "yes"
	rowstart = ""
	return p.table(frame, langTable, resultTable, doautolist, rowstart)
end

function p.Top20STEM(frame)
	langTable = {'en','zh','hi','es','fr','ar','ru','bn','pt','id','ur','de','ja','sw','pnb','jv','wuu','te','tr','ko'}
	resultTable = buildTableHeader(langTable)
	doautolist = ""
	rowstart = "Wikidata"
	return p.table(frame, langTable, resultTable, doautolist, rowstart)
end


function p.CEE(frame)
	langTable = { 'az','ba','be','be_x_old','bs','bg','crh','de','el','eo','et','hr', 'hsb', 'hu','hy','ka', 'kk', 'lt', 'lv','mk','myv','pl','ro','ru','sh','sq','sr','tr','tt','uk','fiu_vro',}
	resultTable = '{| class="wikitable sortable" width=100%\n|-\n! № !! style="width:18%"|Article !! class="unsortable"|[[File:Flag orb Azerbaijan.svg|15px]] az !! class="unsortable"|[[File:Flag orb Bashkortostan.svg|15px]] ba !! class="unsortable"|[[File:Flag orb Belarus.svg|15px]] be !! class="unsortable"|[[File:Belarus flag (1918, 1991-1995) icon.png|15px]]<br>be-t !! class="unsortable"|[[File:Flag orb Bosnia and Herzegovina.svg|15px]] bs !! class="unsortable"|[[File:Flag orb Bulgaria.svg|15px]] bg !! class="unsortable"|[[File:Gerae-tamga.svg|15px]] crh !! class="unsortable"|[[File:Flag orb Austria.svg|15px]] de !! class="unsortable"|[[File:Flag orb Greece.svg|15px]] el !! class="unsortable"| <br> eo !! class="unsortable"|[[File:Flag orb Estonia.svg|15px]] et !! class="unsortable"|[[File:Flag orb Croatia.svg|15px]] hr !! class="unsortable"|[[File:Flag of Sorbs.svg|15px]] hsb !! class="unsortable"|[[File:Flag orb Hungary.svg|15px]] hu !! class="unsortable"|[[File:Flag orb Armenia.svg|15px]] hy !! class="unsortable"|[[File:Flag orb Georgia.svg|15px]] ka !! class="unsortable"|[[File:Flag orb Kazakhstan.svg|15px]] kk !! class="unsortable"|[[File:Flag orb Lithuania.svg|15px]] lt !! class="unsortable"|[[File:Flag orb Latvia.svg|15px]] lv !! class="unsortable"|[[File:Flag orb Macedonia.svg|15px]] mk !! class="unsortable"|[[File:Erzya Flag.svg|15px]] myv !! class="unsortable"|[[File:Flag orb Poland.svg|15px]] pl !! class="unsortable"|[[File:Flag orb Romania.svg|15px]] ro !! class="unsortable"|[[File:Flag orb Russia.svg|15px]] ru !! class="unsortable"| <br> sh !! class="unsortable"|[[File:Flag orb Albania.svg|15px]] sq !! class="unsortable"|[[File:Flag orb Serbia.svg|15px]] sr !! class="unsortable"|[[File:Flag orb Turkey.svg|15px]] tr !! class="unsortable"|[[File:Flag of Tatarstan.svg|15px]] tt !! class="unsortable"|[[File:Flag orb Ukraine.svg|15px]] uk !! class="unsortable"|[[File:Flag of Võro.svg|15px]] vro !! Σ <br> !! Wikidata !! <span title="number of main statements on item">st.</span> !! \n|-'
	doautolist = "yes"
	rowstart = ""
	return p.table(frame, langTable, resultTable, doautolist, rowstart)
end

function p.African(frame)
	local langTable = { 'ar','af','arz','sw','ig','so','mg','am','yo','zu','sn','rw','ln','ha','kab','nso','xh','ts','st','tn','en','fr','pt','es','de','nl'}
	resultTable = '{| class="wikitable sortable" width=100%\n|-\n! rowspan=2|№ !! style="width:18%" rowspan=2|Article !! class="unsortable" colspan=20 | African languages !! class="unsortable" colspan=6 | European languages !! rowspan=2|Σ <br> !! rowspan=2|Wikidata !! rowspan=2|<span title="number of main statements on item">st.</span> !! rowspan=2| \n|- \n!class="unsortable"|<span title="{{language|ar}}">ar</span> !! class="unsortable"|<span title="{{language|af}}">af</span>!! class="unsortable"|<span title="{{language|arz}}">arz</span>!! class="unsortable"|<span title="{{language|sw}}">sw</span>!! class="unsortable"|<span title="{{language|ig}}">ig</span> !! class="unsortable"|<span title="{{language|so}}">so</span> !! class="unsortable"|<span title="{{language|mg}}">mg</span> !! class="unsortable"|<span title="{{language|am}}">am</span>  !! class="unsortable"|<span title="{{language|yo}}">yo</span> !! class="unsortable"|<span title="{{language|zu}}">zu</span> !! class="unsortable"|<span title="{{language|sn}}">sn</span> !! class="unsortable"|<span title="{{language|rw}}">rw</span> !! class="unsortable"|<span title="{{language|ln}}">ln</span> !! class="unsortable"|<span title="{{language|ha}}">ha</span> !! class="unsortable"|<span title="{{language|kab}}">kab</span> !! class="unsortable"|<span title="{{language|nso}}">nso</span> !! class="unsortable"|<span title="{{language|xh}}">xh</span> !! class="unsortable"|<span title="{{language|ts}}">ts</span> !! class="unsortable"|<span title="{{language|st}}">st</span> !! class="unsortable"|<span title="{{language|tn}}">tn</span> !! class="unsortable"|<span title="{{language|en}}">en</span> !! class="unsortable"|<span title="{{language|fr}}">fr</span> !! class="unsortable"|<span title="{{language|pt}}">pt</span> !! class="unsortable"|<span title="{{language|es}}">es</span> !! class="unsortable"|<span title="{{language|de}}">de</span> !! class="unsortable"|<span title="{{language|nl}}">nl</span> \n|-'
	doautolist = "yes"
	rowstart = ""
	return p.table(frame, langTable, resultTable, doautolist, rowstart)
end

function p.Nordic(frame)
	langTable = {'sv','fi','no','da','nn','is','fo','se','kl','en','de','ru','fr','pl','nl','lt','et','lv'}
	resultTable = '{| class="wikitable sortable" width=100%\n|-\n! rowspan=2|№ !! style="width:18%" rowspan=2|Article !! class="unsortable" colspan=9 | Nordic languages !! class="unsortable" colspan=9 | Neighboring languages !! rowspan=2|Σ <br> !! rowspan=2|Wikidata !! rowspan=2|<span title="number of main statements on item">st.</span> !! rowspan=2| \n|- \n'
	.. '!class="unsortable"|[[File:Flag orb Sweden.svg|15px]] <span title="{{language|sv}}">sv</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Finland.svg|15px]] <span title="{{language|fi}}">fi</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Norway.svg|15px]] <span title="{{language|no}}">no</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Denmark.svg|15px]] <span title="{{language|da}}">da</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Norway.svg|15px]] <span title="{{language|nn}}">nn</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Iceland.svg|15px]] <span title="{{language|is}}">is</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Faroe Islands.svg|15px]] <span title="{{language|fo}}">fo</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Sami.svg|15px]] <span title="{{language|se}}">se</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Greenland.svg|15px]] <span title="{{language|kl}}">kl</span>'
	.. ' !! class="unsortable"|[[File:Flag orb United Kingdom.svg|15px]] <span title="{{language|en}}">en</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Germany.svg|15px]] <span title="{{language|de}}">de</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Russia.svg|15px]] <span title="{{language|ru}}">ru</span>'
	.. ' !! class="unsortable"|[[File:Flag orb France.svg|15px]] <span title="{{language|fr}}">fr</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Poland.svg|15px]] <span title="{{language|pl}}">pl</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Luxembourg.svg|15px]] <span title="{{language|nl}}">nl</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Lithuania.svg|15px]] <span title="{{language|lt}}">lt</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Estonia.svg|15px]] <span title="{{language|et}}">et</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Latvia.svg|15px]] <span title="{{language|lv}}">lv</span> \n|-'
	doautolist = ""
	rowstart = ""
	return p.table(frame, langTable, resultTable, doautolist, rowstart)
end
	
function p.Antony(frame)
	langTable = {'af','an','ar','arz','ast','azb','ba','be','bg','bh','bn','bs','ca','ceb','co','cs','da','de','el','en','eo','es','et','eu','fa','fi','fr','frr','ga','gd','gl','hak','he','ht','hu','hy','hyw','id','io','is','it','ja','ka','ko','la','lt','mg','ml','mr','ms','nds','nl','no','oc','pa','pl','pnb','pt','ro','ru','sc','sco','sh','si','sim','sk','sr','sv','sw','ta','th','tl','tr','tt','ug','uk','ur','vi','yo','zh','zh_min_nan'}
	resultTable = buildTableHeader(langTable)
	return p.table(frame, langTable, resultTable)
end

function p.Celtic(frame)
	langTable = {'br','cy','gd','ga','gv','kw'} 
	resultTable = '{| class="wikitable sortable" width=100%\n|-\n! rowspan=2 | № !! style="width:18%" rowspan=2|Article !! class="unsortable" colspan=6 | Celtic languages !! rowspan=2|Σ <br> !! rowspan=2|Wikidata !! rowspan=2|<span title="nifer y statements ar yr eitem"># of statements</span> !! rowspan=2| \n|- \n'
	.. ' !! class="unsortable"|[[File:Flag of Brittany (Gwenn ha du).svg|15px]] <span title="{{language|br}}">br</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Wales.svg|15px]] <span title="{{language|cy}}">cy</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Ireland.svg|15px]] <span title="{{language|ga}}">ga</span>'
		.. ' !! class="unsortable"|[[File:Flag orb Scotland.svg|15px]] <span title="{{language|gd}}">gd</span>'
	.. ' !! class="unsortable"|[[File:Flag orb Isle of Man.svg|15px]] <span title="{{language|gv}}">gv</span>'
	.. ' !! class="unsortable"|[[File:Flag of Cornwall.svg|15px]] <span title="{{language|kw}}">kw</span>'
	resultTable = buildTableHeader(langTable)
	return p.table(frame, langTable, resultTable)
end

-- CUSTOM FUNCTIONS END HERE!
	
function buildTableHeader(langTable)
	resultTable = '{| class="wikitable sortable" width=100%\n|-\n! № !! style="width:18%"|Article'
	for i = 1, #langTable do
		resultTable = resultTable .. ' !! class="unsortable"|<span title="{{language|'..langTable[i]..'}}">'..langTable[i]..'</span>'
	end
	resultTable = resultTable .. ' !!Σ !! Wikidata !! <span title="number of main statements on Wikidata item">s</span> !! <span title="Wikimedia Commons category">C</span>\n|- \n'
	return resultTable
end

local function def(bla)
  local zdef = {}
  for _, l in ipairs(bla) do zdef[l] = true end
  return zdef
end

function p.table(frame, langTable, resultTable, doautolist, rowstart)
	-- header/init
	index = 1
	ctt = {}
	statementst = 0
	coords = 0
	images = 0
	wqsitems = ""
	qids = ""
	timeline = 0
	mylang = frame:preprocess('{{int:lang}}')
	for langCount = 1, #langTable do
		ctt[langCount] = 0
	end
	
	-- rows
	while frame.args[index] do
		Id = frame.args[index]
		local entity = mw.wikibase.getEntityObject(Id)
		-- if not entity or not entity.sitelinks then
		if not entity then
			return '<b>Entity ' .. Id .. ' not found</b>'
		end
		uselang = frame:preprocess('{{Uselang}}')
		Label = entity:getLabel( uselang )
		if not Label then
			Label = ''
		end
   		local sitelink = entity:getSitelink( uselang .. 'wiki' )
		if sitelink then
			if Label == '' then
				Label = sitelink
			end
		end
    	result2 = ''
    	ct = 0
    	wqsitems = wqsitems .. "wd%3A" .. Id .. "%20"
    	qids = qids .. string.sub(Id, 2) .. ","
    	idinternal = def { "P373", "P948", "P935", "P460", "P856", "P910", "P213", "P1343", "P973", "P345", "P227", "P244","P1612", "P1472", "P1325" }
    	commonsp = def {'P18','P10','P14','P15','P41','P51','P94','P109','P117','P154','P158','P181','P207','P242','P367', 'P373','P443','P491','P692','P935','P948','P989','P990','P996','P1442','P1472','P1543','P1612','P1621','P1766','P1801','P1846','P1943','P1944'}
    	
    	-- columns per row
    	for langCount = 1, #langTable do
	   		local sitelink = entity:getSitelink( langTable[langCount] .. 'wiki' )
			if sitelink then
				iw = langTable[langCount]
				if iw == "be_x_old" then iw = "be-tarask" end
				if iw == "fiu_vro" then iw = "fiu-vro" end
				result2 = result2 .. '\n| style="background:#cfc;text-align:center;font-weight:bold;"|' .. '[[:' .. iw .. ':' .. sitelink .. '| W]]'
				ct = ct + 1
				ctt[langCount] = ctt[langCount] + 1
				if Label == '' then
					Label = sitelink
				end
			else
				result2 = result2 .. '\n| '
			end
		end
	
		-- first cells of row
    	result1 = '|-\n|align=right|' .. index .. '\n|'
    	if rowstart == "Wikidata" then
			result1 = result1 .. "[[d:" .. Id .. "|" .. Label ..']]'      			
    	else	
    		if sitelink then
    			result1 = result1 .. '[[:'..uselang..':' .. sitelink .. '|' .. Label ..']]'
    		else
    			result1 = result1 .. Label
    		end
		end
		-- icon for females (Q6581072)
		local claims
		if entity.claims then
			claims = entity.claims["P21"]
		end
		if (claims and claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid" and claims[1].mainsnak.datavalue.value["numeric-id"] and claims[1].mainsnak.datavalue.value["numeric-id"] == 6581072) then
			result1 = result1 .. ' [[File:Female Icon.svg|18px]]'
		end    	

		-- years for humans (Q5)
		local claims
		if entity.claims then
			claims = entity.claims["P31"]
		end
		if (claims and claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid" and claims[1].mainsnak.datavalue.value["numeric-id"] and claims[1].mainsnak.datavalue.value["numeric-id"] == 5) then
				local yr = "%d%d%d%d$"
				local p569 = entity:formatPropertyValues( 'P569' ).value
				if p569 ~= "" then
					if p569:match(yr) ~= nil then
						p569 = p569:match(yr)
					end
					local p570 = entity:formatPropertyValues( 'P570' ).value
					if p570 ~= "" then
						if p570:match(yr) ~= nil then
							p570 = p570:match(yr)
						end
						result1 = result1 .. ' <span style="font-size:smaller;font-weight:100">(' .. p569 .. '-' .. p570 .. ')</span> '
					else
						result1 = result1 .. ' <span style="font-size:smaller;font-weight:100">(b. ' .. p569 .. ')</span>'
					end
				else
					result1 = result1 .. ' <span style="font-size:smaller;font-weight:100">(?)</span>'
				end
		end
		local tl = ""
		tl = tl .. entity:formatPropertyValues( 'P580' ).value
		tl = tl .. entity:formatPropertyValues( 'P569' ).value
		tl = tl .. entity:formatPropertyValues( 'P571' ).value
		tl = tl .. entity:formatPropertyValues( 'P582' ).value
		tl = tl .. entity:formatPropertyValues( 'P576' ).value
		tl = tl .. entity:formatPropertyValues( 'P577' ).value
		if tl ~= "" then
			timeline = timeline + 1
		end 

		local p625 = entity:formatPropertyValues( 'P625' ).value
 		if p625 ~= "" then
				result1 = result1 .. "&nbsp;[[File:Geographylogo.svg|18px|view on maps|link=https://tools.wmflabs.org/geohack/geohack.php?language=en&pagename=" .. mw.uri.encode( Label, "PATH" ) .. "&params=" .. entity.claims.P625[1].mainsnak.datavalue.value.latitude .. "_N_" .. entity.claims.P625[1].mainsnak.datavalue.value.longitude .. "_E]]"
				coords = coords + 1
		end
		local p18 = entity:formatPropertyValues( 'P18' ).value
 		if p18 ~= "" then
				images = images + 1
		end
		
		-- last cells of row
		index = index + 1

		local commons = false
		local statements = 0
		if entity.claims then
			for i, statement in pairs( entity.claims ) do
				if statement then
					if statement[1].mainsnak then
						if not idinternal[i] then
							if statement[1].mainsnak.datatype ~= 'external-id' then
                   				statements = statements+1
                   			end
               			end
               			if commonsp[i] then 
               				commons = true
               			end
					end
				end
			end
		end
		-- local statements = #entity:getProperties()

		-- todo : check for Commons sitelinks
		local commonsstr = ""
		local commonslink = entity:getSitelink( 'commonswiki' )
		if commonslink then
			-- commonsstr = '<span title="Wikidata item includes Commons resources">+</span>'
			commonsstr = "[[commons:".. commonslink .. "|'''C''']]"
		end
		statementst = statementst + statements
		if statements == 0 then
			bgcolor = ''
		else
			bgcolor = 'background:#cfc;'
		end
		resultTable = resultTable .. result1 .. result2 ..'\n| align=right style="font-size:smaller;"| ' .. ct .. '\n| style="background:#cfc;" data-sort-value="' .. string.sub(Id, 2) .. '"|[[d:' .. Id .. '|' .. Id .. ']] \n|style="' .. bgcolor .. 'font-size:smaller;" align=right title="number of main statements on Wikidata item"|'.. statements .. '\n|style="background:#cfc;"|' .. commonsstr .. '\n'
	end
	
	-- footer
	tline = ""
	if timeline > 2 then
		tline = "[https://tools.wmflabs.org/wikidata-timeline/#/timeline?query=" .. mw.uri.encode("items[" .. qids .. "]", "PATH" ) .. " →&nbsp;timeline]"
	end	
	mapme = ""
	if coords > 0 or images > 0 then
		mapme = "[https://query.wikidata.org/#%23%20click%20%22Execute%22%20to%20run%20the%20query%2C%20then%20%28on%20the%20right%20side%29%20below%20%22Display%22%20select%20the%20link%20%22Map%22%20or%20%22Image%20Grid%22%0ASELECT%20%0A%09%3Fitem%20%0A%09%3FitemLabel%20%0A%09%28GROUP_CONCAT%28DISTINCT%28%3FinstanceLabel%29%3B%20separator%3D%22%2C%20%22%29%20as%20%3Finstance_of%29%0A%09%28SAMPLE%28%3Fcoord%29%20as%20%3Fcoordinates%29%0A%09%28SAMPLE%28%3Fimg%29%20as%20%3Fimage%29%0AWHERE%0A{%0A%09VALUES%20%3Fitem%20{%20" .. wqsitems .. "%20}%09OPTIONAL%20{%3Fitem%20wdt%3AP625%20%3Fcoord1%20}%20.%0A%20%20%09OPTIONAL%20{%3Fitem%20wdt%3AP131%2Fwdt%3AP625%20%3Fcoord2%20}%20.%0A%20%20%09OPTIONAL%20{%3Fitem%20wdt%3AP276%2Fwdt%3AP625%20%3Fcoord3%20}%20.%0A%09BIND%28IF%28!BOUND%28%3Fcoord1%29%2C%28IF%28!BOUND%28%3Fcoord2%29%2C%3Fcoord3%2C%3Fcoord2%29%29%2C%3Fcoord1%29%20as%20%3Fcoord%29%0A%20.%20%20%0A%09OPTIONAL%20{%3Fitem%20wdt%3AP31%20%3Finstance%20}%20.%20%20%20%0A%20%20%09OPTIONAL%20{%3Fitem%20wdt%3AP18%20%3Fimg%20}%20.%20%20%20%0A%09SERVICE%20wikibase%3Alabel%20{%20bd%3AserviceParam%20wikibase%3Alanguage%20%22" .. mylang .. "%2Cen%22%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.%20%3Fitem%20rdfs%3Alabel%20%3FitemLabel%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.%20%3Finstance%20rdfs%3Alabel%20%3FinstanceLabel%20}%0A}%0AGROUP%20BY%20%3Fitem%20%3FitemLabel%20 →"
		if coords > 0 then
			mapme = mapme .. "&nbsp;map"
		end
		if images > 0 then
			mapme = mapme .. "&nbsp;gallery"
		end
		mapme = mapme .. "]"
	end
	local autolist = ""
	if doautolist == "yes" then
		 autolist = "[https://tools.wmflabs.org/autolist/?language=" .. mylang .. "&project=wikipedia&wdq=" .. mw.uri.encode("items[" .. qids .. "]", "PATH" ) .. "&run=Run&mode_manual=or&mode_cat=or&mode_wdq=not&mode_wdqs=or&mode_find=or&chunk_size=10000 →&nbsp;Autolist]"
	end
	result1 = '|- align=right style="font-size:smaller" class="sortbottom"\n! Σ \n|'  .. autolist .. mapme .. tline
	result2 = ''
	ct = 0
    for langCount = 1, #langTable do
			result2 = result2 .. '\n |' .. ctt[langCount]
			ct = ct + ctt[langCount]
	end
	resultTable = resultTable .. result1 .. result2 ..'\n| ' .. ct .. '\n| data-sort-value="999999999999"| avg:&nbsp;<span title="average number of language versions (of ' .. #langTable .. ') per article">' .. math.floor(ct/(index-1)+0.5) .. '</span>\\<span title="average number of articles (of ' .. (index-1) .. ') per language">' .. math.floor(ct / #langTable + 0.5) .. '</span>\\<span title="overall in percent (all: '..  (#langTable * (index-1)) .. ')">' .. math.floor( ct / #langTable / (index-1)*100 + 0.5) .. '%</span>\n|' .. statementst .. '\n| [[File:Commons-logo.svg|16px|Wikimedia Commons]]'

	resultTable = resultTable .. '\n|}\n'
	return resultTable
end

-- WikimediaCEETable.count: counts articles from the list in certain wiki
-- Sample use: {{#invoke:WikimediaCEETable|count|lang|Q1|Q2|Q3|Q4|Q5}}
-- based on previous "table" function stripped from all the table formatting.

function p.count(frame)
        resultText = ''
	anum = 2
        wikianum = 0
	ctt = {}

	for langCount = 1, #langTable do
		ctt[langCount] = 0          
	end
	
	while frame.args[anum] do          
		Id = frame.args[anum]
                anum = anum + 1
		local entity = mw.wikibase.getEntityObject(Id)

		-- if not entity or not entity.sitelinks then   
		if not entity then
			return '<b>Entity ' .. Id .. ' not found</b>'
		end

    	for langCount = 1, #langTable do
	   		local sitelink = entity:getSitelink( langTable[langCount] .. 'wiki' )
			if sitelink then
				iw = langTable[langCount]
				if iw == "be_x_old" then iw = "be-tarask" end
				if iw == "fiu_vro" then iw = "fiu-vro" end
				ctt[langCount] = ctt[langCount] + 1
			end
		end
        end

        anum = anum - 2                        

        -- number of articles in certain wiki. Straight...
        for langCount = 1, #langTable do
                if langTable[langCount] == frame.args[1] then wikianum = ctt[langCount] end
        end

	resultText = wikianum .. '/' .. anum              -- result is two numbers with '/' separator

	return resultText
end

return p