Dokumentation [visa] [redigera] [historik] [rensa sidcachen]


Detta är en modul för att visa information om idrottare (för närvarande främst använd för volleybollspelare ), som spelposition och under vilken tid de spelat för olika klubbar och landslag. Modulen hämtar datauppgifter från Wikidata och lägger in det i Mall:Faktamall. Modulen används av Mall:Sportperson WD. För tips om användning se där. Nedan är dokumentation om själva modulen.

Funktioner redigera

Modulen anropas genom att lägga in {{#Invoke:Sportperson WD | person}} i artikeln (eller som nämnt ovan genom att använda mallen Sportperson WD). Den tar följande argument:

  • id: "Q-ID" för en person (t.ex. Q22338719 för Isabelle Haak (Q22338719), Isabelle Haak). I normalfallet behöver detta inte anges då funktionen använder det wikidataobjekt som är länkar till artikeln.
  • lastchecked: Datum på formatet ÅÅÅÅMMDD. Denna används för att skriva när uppgifterna i Wikidata senast kontrollerades av en användare på den lokala wikipedian.
  • showgames: ja/nej. Om ja visas informationen på samma sätt som för t.ex. Mall:Infobox fotbollsspelare, d.v.s. med årtal till vänster och spelade matcher och gjorda mål till höger. Annars visas lagets till vänster och årtal till höger.

Beskrivning redigera

Modulen består av följande delar:

  • Personlig data (bild (P18), födelsedatum (P569), födelseplats (P19) och spelarposition (P413)). Uppgifterna hämtas från motsvarande uppgifter i Wikidata.
  • Uppgifter om klubbar som personen spelat för. Detta omfattar dels:
    • Klubbarna personen har spelat för med start och slutår. Uppgifterna hämtas från motsvarande uppgifter i Wikidata (medlem i idrottslag (P54)), med årtalen som bestämning.
    • Resultat för klubbarna som personen har spelat för (placering, typ av tävling och tid för tävlingsupplagan). Uppgifter från dess hämtas från uppgiften deltog i (P1344) från Wikidata. Koden läser av klubbens placering i tävlingen antingen direkt från posten eller genom att hitta spelaren lag från tävlingens deltagande lag (P1923). Den läser av tiden för tävlingen genom att läsa av uppgifter från tävlingens wikidata-objekt, antingen direkt genom (startdatum (P580) eller slutdatum (P582)) eller indirekt genom att först läsa tidsperiod (P2348) och sedan läsa motsvarande uppgifter därifrån. Om relevanta uppgifter inte finns anpassas visningen så att infoboxen blir så lättläst som möjligt.
  • Uppgifter om landslag som personen spelat för fylls i på samma sätt. Dessa fungerar på samma sätt som för klubbarna, med enda skillnaden är att de är landslag. Ett lag räknas som landslag om deras instans av (P31) är landslag (Q1194951). Klubblag har istället instans av (P31) som är antingen idrottsförening (Q847017), idrottslag (Q12973014) eller volleybollklubb (Q108395614) eller är instans av något som i sin tur är instans av någon av de tre listade typerna.
  • Uppgifter om lag (klubblag eller landslag) som personen tränat. Detta fungerar på samma sätt som klubblag eller landslag som personen spelat för, men tas istället från tränare för idrottslag (P6087).
  • Individuella utmärkelser (utmärkelse (P166)). Uppgifterna hämtas från motsvarande uppgifter i Wikidata.

För alla delar gäller att de bara visas i infoboxen om det finns några inlagda uppgifter (t.ex. visas inte individuella utmärkelser om det inte finns några inlagda).

Felsökning redigera

Modulen försöker visa ett meddelande direkt i sidan om information saknas på wikidata som gör att den inte kan visa informationen på det sätt som det är tänkt. Vanligen kan fel åtgärdas genom att lägga in rätt uppgifter i wikidata. Om du får ett meddelande som börjar Luafel i Modul:Sportklubb_WD skriv gärna ett meddelande på modulens diskussionssida.

Exempel på fel och åtgärder:

  • Tävling sorteras fel (i början istället för längre ner i tabellen) - Tävlingar sorteras i första hand på när de avslutats och i andra hand efter när de börjat. Om det inte finns någon datum hamnar de först. Gå till den aktuella tävlingen i wikidata och lägg in startdatum (P580) eller slutdatum (P582) (eller tidsperiod (P2348), men då måste den i sin tur ha startdatum (P580) och/eller slutdatum (P582)).
  • "Tävling ej satt" - Detta felet beror på att det aktuella tävlingstillfället saknar en sportsäsong av serie eller tävling (P3450). Ett mycket vanligt exempel på detta är att någon är satt som att den har deltagit i ett olympiskt spel (hela arrangemanget, t.ex. Olympiska sommarspelen 1972 (Q8438)) istället för den enskilda tävlingen vid det olympiska spelet, t.ex. Herrarnas turnering i volleyboll vid olympiska sommarspelen 1972 (Q1005689).
  • Tävlingsresultat visas inte. För att ett tävlingsresultat där personen deltagit som del av ett lag (angett med bestämningen medlem i idrottslag (P54)) ska visas måste det också vara inlagt att personen varit medlem i laget. Du behöver alltså lägga in medlem i idrottslag (P54) som uttalande direkt för personen.
  • Resultat med en klubb eller ett landslag hamnar inte under de rubrikerna. Detta felet beror på att resultatet inte är inlagt med bestämningen medlem i idrottslag (P54). Det är alltså inte i Wikidata angivet i vilket lag personen spelade. I detta fallet antar modulen att detta beror på att det är för att tävlingen var en individuell tävling (a la. 100 meter i friidrott eller singel i bordtennis) och då hamnar resultat överst.
p = {}

local wd = require( 'Modul:Referenshantering' )
local sd = require( 'Modul:Sportdata')

p.iRefcounter=0
txtLabelandWikilinkMissing='Etikett och wikilänk saknas'
txtPlayedGamesScoreGoalsShort='SM (GM)'
txtPlayedGamesScoreGoals='Spelade matcher/Gjorda mål'
txtToAdd="för att lägga till"
txtClickHere="Klicka här"
txtReserveLabel="reservlag"

p.person = function(frame)
	-- Shows information about an athlete
	--
	-- In order to make sure that the information is shown correctly in the infobox a counter is used
	-- If adding functionaly, increase the counter before the information rather than after, otherwise information might not be shown
	
    -- Get correct entityid, directly from page or if set by parameter 'id' (usually for testing purposes)
	local entityid
	if (frame.args['id']) then
		entityid=frame.args['id']
		else
		entityid=mw.wikibase.getEntityIdForCurrentPage()
	end
	
	-- Only show infobox if an entity is set
	if not (entityid==nil) then
		frame['id']=entityid
		local txtTitle=getLabelByEntity( entityid )
		if (frame.args['txtWidth_px']) then
			txtWidth_px=frame.args['txtWidth_px']
		end
	    myArgs={titel=txtTitle}
	    myArgs[txtBodyStyle]="width:"..txtWidth_px
	    myArgs[txtLabelStyle]="width:" .. iLabelWidth
	    myArgs[txtDataStyle]="width:" .. iDataWidth

		--Initiate counter, used for keeping track of the element numbers used to fill the infobox (header1, header2 etc.)
	    iCounter=0
	    
	    --Fill in general personal data (image, birth & death) - relevant for any person, no matter if they have anything to do with sports or not
		myArgs,iCounter=tblGeneralPersonalData(frame,myArgs,iCounter,entityid)
		myArgs,iCounter=tblSportPersonalData(frame,myArgs,iCounter,entityid)


		bHasResults,txtIndividualresults=individualresults(frame,entityid)
		if (bHasResults) then
			iCounter=iCounter+1
		    myArgs[txtHeader .. iCounter]=txtCompetitionResultHeader
		    myArgs[txtHeader .. iCounter .. txtStyle]=txtStyleLevel2
			iCounter=iCounter+1
		    myArgs[txtContent .. iCounter]=txtIndividualresults
			end

	    --get teams information for whether the person has been a member of a team
	    tblClubTeam,tblNationalTeam=tblTeam(frame,entityid,'P54')
	    --get coaching information if the person has been a coach of a team (club or national)
	    tblClubTeamCoach,tblNationalTeamCoach=tblTeam(frame,entityid,'P6087')

--			iCounter=iCounter+1
--		    myArgs[txtContent .. iCounter]=tprint(tblClubTeam)


	    --show team information if the person has been a member of a team
	    if next(tblClubTeam) then
			iCounter=iCounter+1
		    myArgs[txtHeader .. iCounter]=txtClubTeamHeader
			if (frame.args['showgames']==txtYes) then
				txtShowGames='<table width="100%" style="text-align:left;"><tr><th width="26%">' .. txtSeasonHeader .. '</th><th width="55%">' .. txtClubTeamHeader .. '</th><th width="19%" style="text-align:right;">' .. frame:expandTemplate{title='Tooltip',args={txtPlayedGamesScoreGoalsShort,txtPlayedGamesScoreGoals}} .. '</th></tr>'
	    		iCounter=iCounter+1
				for key, value in pairs( tblClubTeam ) do
		    		txtNameClub=value.txtName
		    		if (txtNameClub:sub(1,8)=='(saknas)') then
		    			qId=txtNameClub:sub( 13,-4)
		    			txtNameClub='(saknas)' .. frame:extensionTag("ref", txtLabelandWikilinkMissing .. ", [https://www.wikidata.org/wiki/" .. qId .. " " .. txtClickHere .. "] " .. txtToAdd) 
		    			end
			    	txtShowGames=txtShowGames..'<tr><td>'.. txtYears(value.yearfrom,value.yearto) .. '</td><td>' .. txtNameClub  .. txtUnpackReference(frame,value.hasref,value.ref) .. value.edit.. '</td><td style="text-align:right;">'
			    	if (value.games) then
			    		txtShowGames=txtShowGames..value.games
			    	end
		    		if (value.goals) then
		    			txtShowGames=txtShowGames..' (' .. value.goals .. ')'
		    		end
		    		txtShowGames=txtShowGames..'</td></tr>'
				end
		    	txtShowGames=txtShowGames..'</table>'
				myArgs[txtContent .. iCounter]=txtShowGames
				else
					-- Only show each sport if (1) there is more than one sport (2) the argument is set that sports should be shown
					bShowEachSport=(not allsame(tblClubTeam,'iSport'))  and (frame.args[txtMultipleSports]==txtYes)
					iOldSport=0
					for key, value in pairs( tblClubTeam ) do
		    		txtNameClub=value.txtName
		    		if (txtNameClub:sub(1,8)=='(saknas)') then
		    			qId=txtNameClub:sub( 13,-4)
		    			txtNameClub='(saknas)' .. frame:extensionTag("ref", txtLabelandWikilinkMissing .. ", [https://www.wikidata.org/wiki/" .. qId .. " " .. txtClickHere .. "] " .. txtToAdd) 
			    		end
	    			if (bShowEachSport) then
	    				if (not (value.iSport==iOldSport)) then
	    					iCounter=iCounter+1
			    			myArgs[txtHeader .. iCounter]=firstToUpper(getLabelByEntity(value.iSport))  -- [txtMultipleSports] .. '::' .. txtYes
						    myArgs[txtHeader .. iCounter .. txtStyle]='background:#cce0f9;' --#b0c4de;
			    			iOldSport=value.iSport
			    			end
						end
		    		iCounter=iCounter+1
			    	myArgs[txtLabel .. iCounter]=txtNameClub
				    myArgs[txtContent .. iCounter]=txtYears(value.yearfrom,value.yearto) .. ' ' .. txtUnpackReference(frame,value.hasref,value.ref).. value.edit
			    	end
		    	end
			bHasResults,txtTeamresults=teamresults(frame,entityid)
			if (bHasResults) then
				iCounter=iCounter+1
			    myArgs[txtHeader .. iCounter]=txtClubTeamResultHeader
			    myArgs[txtHeader .. iCounter .. txtStyle]=txtStyleLevel2
				iCounter=iCounter+1
			    myArgs[txtContent .. iCounter]=txtTeamresults
				end
		    end
	    --show national teams information if the person has been a member of a national team
	    if next(tblNationalTeam) then
			iCounter=iCounter+1
		    myArgs[txtHeader .. iCounter]=txtNationalTeamHeader
			if (frame.args['showgames']==txtYes) then
				txtShowGames='<table width="100%" style="text-align:left;"><tr><th width="26%">' .. txtSeasonHeader .. '</th><th width="55%">' .. txtNationalTeamHeader .. '</th><th width="19%" style="text-align:right;">' .. frame:expandTemplate{title='Tooltip',args={txtPlayedGamesScoreGoalsShort,txtPlayedGamesScoreGoals}} .. '</th></tr>'
	    		iCounter=iCounter+1
				for key, value in pairs( tblNationalTeam ) do
			    	txtShowGames=txtShowGames..'<tr><td>'.. txtYears(value.yearfrom,value.yearto) .. '</td><td>' .. value.txtNationalTeam  .. txtUnpackReference(frame,value.hasref,value.ref) .. value.edit.. '</td><td style="text-align:right;">'
			    	if (value.appearances) then
			    		txtShowGames=txtShowGames..value.appearances
			    		else 
			    			if (value.games) then
				    		txtShowGames=txtShowGames..value.games
				    		end
						end
		    		if (value.goals) then
		    			txtShowGames=txtShowGames..' (' .. value.goals .. ')'
		    		end
		    		txtShowGames=txtShowGames..'</td></tr>'
				end
		    	txtShowGames=txtShowGames..'</table>'
				myArgs[txtContent .. iCounter]=txtShowGames
				else

		    local key,value
	    	for key, value in pairs( tblNationalTeam ) do
	    		iCounter=iCounter+1
			    myArgs[txtLabel .. iCounter]=value.txtNationalTeam
			    txtTmp=txtYears(value.yearfrom,value.yearto)
			    if (value.appearances~=nil) then
			    	if (value.appearances == '1') then
			    		txtTmp = txtTmp .. ' (' .. value.appearances .. ' ' .. txtAppearance .. ')'  .. ' ' 
			    	else
			    		txtTmp = txtTmp .. ' (' .. value.appearances .. ' ' .. txtAppearances .. ')'  .. ' ' 			    		
			    	end
			    end
			    myArgs[txtContent .. iCounter]=txtTmp .. txtUnpackReference(frame,value.hasref,value.ref) .. value.edit
			    end
			end
			bHasResults,txtNationalTeamresults=nationalteamresults(frame,entityid)
			if (bHasResults) then
				iCounter=iCounter+1
			    myArgs[txtHeader .. iCounter]=txtNationalTeamResultHeader;
			    myArgs[txtHeader .. iCounter .. txtStyle]=txtStyleLevel2;
				iCounter=iCounter+1
			    myArgs[txtContent .. iCounter]=txtNationalTeamresults
				end
	    end

	    if next(tblClubTeamCoach) then
			iCounter=iCounter+1
		    myArgs[txtHeader .. iCounter]=txtCoachHeader;
			if (frame.args['showgames']==txtYes) then
				txtShowGames='<table width="100%" style="text-align:left;"><tr><th width="26%">' .. txtSeasonHeader .. '</th><th width="55%">' .. txtClubTeamHeader .. '</th><th width="19%"></th></tr>'
	    		iCounter=iCounter+1
				for key, value in pairs( tblClubTeamCoach ) do
		    		txtNameClub=value.txtName
		    		if (txtNameClub:sub(1,8)=='(saknas)') then
		    			qId=txtNameClub:sub( 13,-4)
		    			txtNameClub='(saknas)' .. frame:extensionTag("ref", txtLabelandWikilinkMissing .. ", [https://www.wikidata.org/wiki/" .. qId .. " " .. txtClickHere .. "] " .. txtToAdd) 
		    		end
			    	txtShowGames=txtShowGames..'<tr><td>'.. txtYears(value.yearfrom,value.yearto) .. '</td><td>' .. txtNameClub  .. txtUnpackReference(frame,value.hasref,value.ref) .. value.edit.. '</td><td style="text-align:right;">'
		    		txtShowGames=txtShowGames..'</td></tr>'
				end
		    	txtShowGames=txtShowGames..'</table>'
				myArgs[txtContent .. iCounter]=txtShowGames
				else
		    for key, value in pairs( tblClubTeamCoach ) do
	    		iCounter=iCounter+1
		    	myArgs[txtLabel .. iCounter]=value.txtName
			    myArgs[txtContent .. iCounter]=txtYears(value.yearfrom,value.yearto)   .. ' ' .. txtUnpackReference(frame,value.hasref,value.ref) .. value.edit
		    end
		    end
    		end
	    if next(tblNationalTeamCoach) then
    		iCounter=iCounter+1
		    myArgs[txtHeader .. iCounter]=txtNationalTeamCoachHeader;
		    	if (frame.args['showgames']==txtYes) then
				txtShowGames='<table width="100%" style="text-align:left;"><tr><th width="24%">' .. txtSeasonHeader .. '</th><th width="57%">' .. txtNationalTeamHeader .. '</th><th width="19%" style="text-align:right;">' .. frame:expandTemplate{title='Tooltip',args={txtPlayedGamesScoreGoalsShort,txtPlayedGamesScoreGoals}} .. '</th></tr>'
	    		iCounter=iCounter+1
				for key, value in pairs( tblNationalTeam ) do
			    	txtShowGames=txtShowGames..'<tr><td>'.. txtYears(value.yearfrom,value.yearto) .. '</td><td>' .. value.txtNationalTeam  .. txtUnpackReference(frame,value.hasref,value.ref) .. value.edit.. '</td><td></td></tr>'
				end
		    	txtShowGames=txtShowGames..'</table>'
				myArgs[txtContent .. iCounter]=txtShowGames
				else

			    for key, value in pairs( tblNationalTeamCoach ) do
		    		iCounter=iCounter+1
			    	myArgs[txtLabel .. iCounter]=value.txtNationalTeam
				    myArgs[txtContent .. iCounter]=txtYears(value.yearfrom,value.yearto)   .. ' ' .. txtUnpackReference(frame,value.hasref,value.ref) .. value.edit
			    end
			    end
	    	end
		
	    if next(tblClubTeamCoach) or next(tblNationalTeamCoach) then
			bHasResults,txtCoachingresults=coachingresults(frame,entityid)
			if (bHasResults) then
				iCounter=iCounter+1
			    myArgs[txtHeader .. iCounter]=txtCoachingResultHeader;
			    myArgs[txtHeader .. iCounter .. txtStyle]=txtStyleLevel2;
				iCounter=iCounter+1
			    myArgs[txtContent .. iCounter]=txtCoachingresults
				end
			end

	    --show awards if the person has received any
	    tbl=awards(frame,entityid)
	    if next(tbl) then
			iCounter=iCounter+1
		    myArgs[txtHeader .. iCounter]=txtIndividualAwards;
		    txtLastAward=''
	    	for key, value in pairs( tbl) do
	    		if (value.awardedby==nil) then
					iCounter=iCounter+1
				    myArgs[txtContent .. iCounter]=value.award  .. txtUnpackReference(frame,value.hasref,value.ref) .. value.edit
	    			else
		    		if (value.award~=txtLastAward) then
			    		iCounter=iCounter+1
					    myArgs[txtHeader .. iCounter]='[[' .. value.award .. ']] '
					    myArgs[txtHeader .. iCounter .. txtStyle]='background:#eaecf0' --txtStyleLevel2
					    txtLastAward=value.award
					    end
					iCounter=iCounter+1
				    myArgs[txtContent .. iCounter]=value.awardedby  .. txtUnpackReference(frame,value.hasref,value.ref) .. value.edit
				    end
			    end
			end
	iDataItems=iCounter
	local txtLastChecked=frame.args['lastchecked']
	if ((not isempty(txtLastChecked)) and (#txtLastChecked==8)) then
		local yearLastChecked=tonumber(string.sub(txtLastChecked,1,4))
		local monthLastChecked=tonumber(string.sub(txtLastChecked,5,6))
		local dayLastChecked=tonumber(string.sub(txtLastChecked,7,8))
		local argsLastChecked={dayLastChecked,monthLastChecked,yearLastChecked}
		local argsUpdateAfter={yearLastChecked+3,monthLastChecked,dayLastChecked,"","[[" .. txtCategory .. ":" .. txtNotUpdatedCategory .. "]]"}
		--Empty row added for esthetic reasons, to separate the date from the rest of the infobox
		iCounter=iCounter+1
		myArgs[txtContent .. iCounter]="  &nbsp;"
		iCounter=iCounter+1
		--Write out the data, include a note about what is meant by the date
		myArgs[txtLabel .. iCounter]=txtLastCheckedLabel .. frame:extensionTag("ref", txtLastCheckedLabel_Clarification)
		myArgs[txtContent .. iCounter]=frame:expandTemplate{title=txtDMYtemplate,args=argsLastChecked} .. frame:expandTemplate{title=txtShowAftertemplate,args=argsUpdateAfter}
		end

		--Finish with link to wikidata entity with information about that you can edit there
	    myArgs['under']='<br>[https://www.wikidata.org/wiki/' .. entityid .. ' '.. txtEditComment .. ']'
	    if (iDataItems<2) then
	    	myArgs['under']=myArgs['under']..'[['..txtCategory .. ':' .. txtFewItems .. ']]'
	    	end
	    --Fill the infobox template
		tmp = frame:expandTemplate{ title = txtInfoboxTemplate , args =myArgs}
		return tmp
		else
		return '' --Return nothing if no connected wikidata entity
		end
	end

function tblGeneralPersonalData(frame,myArgs,iCounter,entityid)
		--Image
		img=mw.wikibase.getBestStatements(entityid, 'P18' )
		myArgs=addImage(entityid,'P18',img,myArgs)
	    myArgs[txtHeaderStyle] = txtStyleMain
	    

		claimNickName=mw.wikibase.getBestStatements(entityid, 'P1449' )
		bNoNick=true;
		txtNick=""
		for key, value in pairs( claimNickName ) do
			if (bNoNick) then
				bNoNick=false
				else
				txtNick=txtNick..','
				end
			txtNick=txtNick..mw.wikibase.formatValue(value.mainsnak) .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,value.references,entityid,'P1449'))
		end
	    if (bNoNick==false) then
		    iCounter=iCounter+1
		    myArgs[txtLabel .. iCounter]=txtNickNameLabel
	    	myArgs[txtContent  .. iCounter]=txtNick
	    	end
		--Birth date
		claimBirthDate=mw.wikibase.getBestStatements(entityid, 'P569' )
		--Death date
		claimDeathDate=mw.wikibase.getBestStatements(entityid, 'P570' )
		--Only show if set 
		bHasBirthDate=next(claimBirthDate)
		bDead=next(claimDeathDate)
		--Only show birth date if set 
		if bHasBirthDate then
	    	iCounter=iCounter+1
			txtBirthData = read(claimBirthDate[1],'time')
			txtBirthYear = tonumber(string.sub(txtBirthData,2,5))
			txtBirthMonth = tonumber(string.sub(txtBirthData,7,8))
			txtBirthDay = tonumber(string.sub(txtBirthData,10,11))
		    myArgs[txtLabel .. iCounter]=txtBirthDateLabel
		    if (bDead) then 
			    myArgs[txtContent  .. iCounter]=txtDate(txtBirthYear,txtBirthMonth,txtBirthDay) .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,claimBirthDate[1].references,entityid,'P569')) .. txtEditPen(entityid,'P569')
		    	else
		    		if txtBirthDay>0 then -- använd bara mallen "Ålder" om födelsedatum är angivet med precision på dagnivå
			    		myArgs[txtContent  .. iCounter]=frame:expandTemplate{ title = txtAgeTemplate, args = { txtBirthYear, txtBirthMonth, txtBirthDay }} .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,claimBirthDate[1].references,entityid,'P569')) .. txtEditPen(entityid,'P569')
			    	end
			    end
			end
	
		--Birth place
		entityBirthPlace=mw.wikibase.getBestStatements(entityid, 'P19' )
		--Only show if set 
	    if next(entityBirthPlace) then
		    idPlace=read(entityBirthPlace[1],'id')
			wdBirthCountry = readFirstStatement(idPlace,'P17')
			wdBirthPlace = txtWikilink(idPlace)
			if wdBirthCountry then 
				wdBirthPlace = wdBirthPlace .. ', ' .. '[[' .. wdBirthCountry .. ']]' .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,entityBirthPlace[1].references,entityid,'P19')) ..  txtEditPen(entityid,'P19')
		    end
	    	iCounter=iCounter+1
		    myArgs[txtLabel .. iCounter]=txtBirthPlaceLabel
	    	myArgs[txtContent  .. iCounter]=wdBirthPlace
	    	end

	    if (bDead) then 
			txtDeathData = read(claimDeathDate[1],'time')
	    	iCounter=iCounter+1
		    myArgs[txtLabel .. iCounter]=txtDeathDateLabel
			if (txtDeathData) then
				txtDeathYear = tonumber(string.sub(txtDeathData,2,5))
				txtDeathMonth = tonumber(string.sub(txtDeathData,7,8))
				txtDeathDay = tonumber(string.sub(txtDeathData,10,11))
			    if (bHasBirthDate) then
			    	if (txtDeathDay>0 and txtBirthDay>0) then  --använd bara mallen "Död datum och ålder" om såväl födelsedatum som dödsdatum har precision på dagnivå
				    	myArgs[txtContent  .. iCounter]=frame:expandTemplate{ title = txtAgeDeadTemplate, args = { txtDeathYear, txtDeathMonth, txtDeathDay,txtBirthYear, txtBirthMonth, txtBirthDay }} .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,claimDeathDate[1].references,entityid,'P570')) .. txtEditPen(entityid,'P570')
			        else
		    			myArgs[txtContent  .. iCounter]=txtDate(txtDeathYear, txtDeathMonth, txtDeathDay) .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,claimDeathDate[1].references,entityid,'P570')) .. txtEditPen(entityid,'P570')
			    	end
				end
			    else
				txtDeathYear = 0
				txtDeathMonth = 0
				txtDeathDay = 0
			    myArgs[txtContent  .. iCounter]=txtUnknown
				end
	    end

		--Death place
		entityDeathPlace=mw.wikibase.getBestStatements(entityid, 'P20' )
		--Only show if set 
	    if next(entityDeathPlace) then
		    idPlace=read(entityDeathPlace[1],'id')
			wdDeathCountry =readFirstStatement(idPlace,'P17')
			wdDeathPlace = txtWikilink(idPlace) 
			if wdDeathCountry then
				wdDeathPlace = wdDeathPlace .. ', '  .. '[[' .. wdDeathCountry .. ']]' .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,entityDeathPlace[1].references,entityid,'P20')) ..  txtEditPen(entityid,'P20')
			end
	    	iCounter=iCounter+1
		    myArgs[txtLabel .. iCounter]=txtDeathPlaceLabel
	    	myArgs[txtContent  .. iCounter]=wdDeathPlace
	    	end
	return myArgs,iCounter
end

function tblSportPersonalData(frame,myArgs,iCounter,entityid)
		--Player position
		wdPosition=mw.wikibase.getBestStatements(entityid, 'P413' )
		--Only show if set 
		local txtPosition
		if next(wdPosition) then
			iCounter=iCounter+1
		    myArgs[txtLabel .. iCounter]=txtPlayerPositionLabel;
		    txtPosition=mw.wikibase.getLabel(read(wdPosition[1],'id'))
		    myArgs[txtContent .. iCounter]=firstToUpper(txtPosition)  .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,wdPosition[1].references,entityid,'P413')) ..  txtEditPen(entityid,'P413');
		end

		--Height
		wdHeight=mw.wikibase.getBestStatements(entityid, 'P2048' )
		--Only show if set 
		if next(wdHeight) then
			fHeight = string.sub(read(wdHeight[1],'amount'),2,-1)
			txtUnitWithInsaneURL= read(wdHeight[1],'unit') 
			indexSlash = txtUnitWithInsaneURL:match'^.*()/' -- Find last slash
			idUnitentity=string.sub(txtUnitWithInsaneURL,indexSlash+1) -- Just read after the last slash
			-- The code can currently only handle centimeters (Q174728) and meters (Q11573)
			-- It will show the height in centimeters. If the height is stored in meters it will be converted to centimeters.
			bUnitok=false
			-- If unit is centimeter
			if (idUnitentity=="Q174728") then
				bUnitok=true
				end
			-- If unit is meter
			if (idUnitentity=="Q11573") then				
				fHeight = fHeight * 100
				bUnitok=true
			end
			-- If unit neither centimeter nor meter
			if (not bUnitok) then
				fHeight = txtCannotConvertToCM
				end
			iCounter=iCounter+1
		    myArgs[txtLabel .. iCounter]=txtHeightLabel
		    myArgs[txtContent .. iCounter]=fHeight  .. ' cm' .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,wdHeight[1].references,entityid,'P2048')) ..  txtEditPen(entityid,'P2048');
		end
	return myArgs,iCounter
end

--Fill tables with information about the teams (club & national) that the person has played with or coached
function tblTeam(frame,entityid,txtRole)
	local outTeam = {}
	local outNationalTeam = {}
    local claimClubs = mw.wikibase.getBestStatements(entityid, txtRole)
    local key, value
    --Loop through all teams (clubs,national,other)
    for key, value in pairs( claimClubs ) do
    	local idTeam = read(value,'id')
    	local tmp
    	bIsClub=isClub( idTeam,'P31' )
    	bIsNationalTeam=isNationalTeam( idTeam,'P31')
    	-- If a sports club or a national team
		if (bIsClub or bIsNationalTeam) then
			tmp=tblTeamInfo(frame,value,entityid,txtRole)
			tmp.iTeam=idTeam
			txtGenderSymbol=''
			if (txtRole=='P6087') then					-- Only check for different genders if coaching
				txtGenderSymbol = txtGender(idTeam)
			end			
			if value['qualifiers'] then
				if value['qualifiers']['P1350'] then
					tmp.games=string.sub(readQualifier(value.qualifiers.P1350[1],'amount'),2,-1)
				end
				if value['qualifiers']['P1351'] then
					tmp.goals=string.sub(readQualifier(value.qualifiers.P1351[1],'amount'),2,-1)
				end
			end
			if value['qualifiers'] then
				if value['qualifiers']['P641'] then
					tmp.iSport=readQualifier(value.qualifiers.P641[1],'id')
					end
			end
			if (tmp.iSport==nil) then
				local p641=mw.wikibase.getAllStatements(idTeam, 'P641' )
				tmp.iSport=read(p641[1],'id')
			end
		end

		if bIsClub then    
			tmp.txtName=txtTeamname(idTeam,tmp.yearfrom) .. txtGenderSymbol
			table.insert(outTeam, tmp)
		end
		if bIsNationalTeam then
			wdCountry = txtSportsCountry(idTeam)
			txtSitelink=mw.wikibase.getSitelink(idTeam)
			if not (txtSitelink) then
				txtSitelink=getLabelByEntity(idTeam)
				end
			-- Check if the national team has a set max age (i.e. if it is a junior team)
			-- If so there will be added an "(UXX)" after the nation, where XX is the max age
--			claimsAge = mw.wikibase.getBestStatements(idTeam, 'P4135' )
--			if next(claimsAge) then
--				wdAge = string.sub(read(claimsAge[1],'amount'),2,-1)
--				tmp.age=wdAge
--				tmp.nationalteam=frame:expandTemplate{ title = txtFlagIconTemplate , args={wdCountry}} .. ' [[' ..  txtSitelink .. '|' .. wdCountry .. ' (U' .. wdAge .. ')]]' .. txtGenderSymbol
--				else
--				tmp.age=''
--				tmp.nationalteam=frame:expandTemplate{ title = txtFlagIconTemplate , args={wdCountry}} .. ' [[' ..  txtSitelink .. '|' .. wdCountry .. ']]' .. txtGenderSymbol
--			end
			tmp=addNationalTeamwithAgeandReserve(tmp,txtGenderSymbol)
			if value['qualifiers'] then
				--Set number of appearances (if available) from P1129 (first priority) or P1350
				if value['qualifiers']['P1129'] then
					tmp.appearances=string.sub(readQualifier(value.qualifiers.P1129[1],'amount'),2,-1)
					else
					if value['qualifiers']['P1350'] then
						tmp.appearances=string.sub(readQualifier(value.qualifiers.P1350[1],'amount'),2,-1)
						else
						tmp.appearances=nil
						end
					end
				end
			table.insert(outNationalTeam, tmp)
			end
	    end

	    -- Sort after join date
	    outTeam=sortActivityLog(outTeam)
		if (frame.args[txtMultipleSports]==txtYes) then
			table.sort(outTeam, function(a, b) return 
				(compareUP(a.iSport,b.iSport))
				end)
	    end
	    table.sort(outNationalTeam, function(a, b) 
	    	return
	    	(a.age < b.age) or  
	    	(a.age == b.age and a.yearfrom < b.yearfrom) or  
	    	(a.age == b.age and a.yearfrom == b.yearfrom and a.yearto < b.yearto) 
	    	end)
	return outTeam,outNationalTeam
end

function coachingresults (frame,entityid)
	local txt='<table style="class: biography vcard" width="100%"><tr><th width="25px">'.. txtPositionHeader .. '</th><th>' .. txtTeamHeader .. '</th><th>' .. txtSeasonHeader .. '</th></tr>'
	local all=tblResults(frame,entityid,'both','P6087')
    table.sort(all, function(a, b) return 
		a.iCompetionRank < b.iCompetionRank or 
    	(a.iCompetionRank == b.iCompetionRank and a.txtLeague < b.txtLeague) or 
    	(a.iCompetionRank == b.iCompetionRank and a.txtLeague==b.txtLeague and a.txtDateFrom < b.txtDateFrom)
    end)

	txtCompetitionOld=''
	for i = 1,#all do
		if (all[i].txtLeague~=txtCompetitionOld) then
			txtGenderSymbol=txtGender(all[i].iLeague)

			txt=txt .. '<tr ' .. txtTeamHeaderStyle .. '><td colspan="3"><b>' .. all[i].txtLeague .. '</b>' .. 	txtGenderSymbol .. '</td></tr>'
			txtCompetitionOld=all[i].txtLeague
			end
		if (all[i].bNationalTeam) then
			txtTeam=all[i].txtNationalTeam
			else
			txtTeam=txtWikilink(all[i].iTeam)
			end
		txt=txt .. '<tr>' .. txtPosition(all[i].iPosition) .. '<td>' .. txtTeam  .. '</td>'
		txtTmp=mw.wikibase.getSitelink(all[i].iSeason )
		if not (txtTmp) then
			txtTmp=all[i].txtSeason
			else
			txtTmp='[['..txtTmp .. '|' .. all[i].txtSeason  .. ']] ' 
		end			
		txt=txt .. '<td>' .. txtTmp   .. txtUnpackReference(frame,all[i].hasref,all[i].ref) .. all[i].edit .. '</td>' .. '</tr>'
    end
	txt=txt .. '</table>'
	return #all>0,txt
end

--Fill table with information about awards won by the person
function awards(frame,entityid)
	local out = {}
    local claimAwards = mw.wikibase.getAllStatements(entityid, 'P166' )
    for key, value in pairs( claimAwards ) do
		local tmp={}
    	local idAward = read(value,'id')
		tmp.award=getLabelByEntity( idAward )
		tmp.awardedby ="-"
		if value['qualifiers'] then
			if value['qualifiers']['P585'] then
				tmp.awardedby =string.sub(readQualifier(value['qualifiers']['P585'][1],'time'),2,5)
				else
  				if value['qualifiers']['P1027'] then
					tmp.awardedby =txtWikilink(readQualifier(value['qualifiers']['P1027'][1],'id'))
					end
				end
		end
		tmp.hasref,tmp.ref=tblProcessAllRefsForItemWD(frame,value['references'],entityid,'P166')
		tmp.edit=txtEditPen(entityid,value.id)
		table.insert(out, tmp)
    	end
    table.sort(out, function(a, b) return a.awardedby < b.awardedby end)
	return out
end

function tblResults(frame,entityid,txtTypeofTeam,txtActivityType)
-- Function that shows sport results for entityid.
-- Arguments:
--   frame - the usual frame
--   entityid - the entityid for which to show the result
--   txtTypeofTeam - can be 'individual', 'team', 'nationalteam' or 'both'
--      'individual' - individual results rather than for a team/as a member of a team (individual can also be if the sports is played in pairs etc., i.e. as long as it is not a named team)
--      'team' - club of any type, anything that is not a national team
--      'nationalteam' - national team
--      'both' - show results for any type of team (national or not)
--   txtActivityType
--	    'P54' - looks for results for teams the person has played for 
--      'P6087' - looks for results for teams the person has managed

	local all={}

	--Find all statements for P1344 ("participant in") that has the correct txtActivityType
	local claimsCompetition
	if (txtActivityType=='none') then
	    claimsCompetition = mw.wikibase.getBestStatements(entityid, 'P1344') 
	    else
	    claimsCompetition = mw.wikibase.getBestStatements(entityid, 'P1344',txtActivityType) 
		end
    
    -- Loop through all statements that were found
    local key,value
    for key, value in pairs( claimsCompetition ) do
		--Check if has determination (if it needs to have one, which is the case for team sports)
		if txtActivityType=='none' or (value['qualifiers'] and value['qualifiers'][txtActivityType]) then -- has a determination like P54 "medlem i idrottslag" for players or P6087  "tränare för idrottslag" for coaches
			local tmp={}
			--read id for the season
			tmp.iSeason = read(value,'id')
			if (txtTypeofTeam=='individual') then
				local checkInTeam=false
				iTeamPlay=getPropertyId(value,'P54')
				if (iTeamPlay and (isClub(iTeamPlay,'P31') or isNationalTeam(iTeamPlay,'P31'))) then
					checkInTeam=true
					end
				iTeamManage=getPropertyId(value,'P6087')
				if (iTeamManage and (isClub(iTeamManage,'P31') or isNationalTeam(iTeamManage,'P31'))) then 
					checkInTeam=true
					end
				if (checkInTeam==false) then
					tmp.iPlayer=entityid
					tmp.txtTeam=""
					tmp=tblSeasonData(frame,tmp,value,tmp.iPlayer,true)
					
					if (not (tmp.iStatus==99)) then
						table.insert(all,tmp)
						end
					end
				else
				tmp.iTeam=getPropertyId(value,txtActivityType)
				tmp=tblSeasonData(frame,tmp,value,entityid)
				tmp.txtCountry = txtSportsCountry(tmp.iTeam)
				tmp.txtTeam=txtTeamname(tmp.iTeam,tmp.txtYearFrom)
				if (txtTypeofTeam=='club' and isClub(tmp.iTeam,'P31')) then
					table.insert(all,tmp)
					end
				if ((txtTypeofTeam=='nationalteam') and isNationalTeam(tmp.iTeam,'P31')) then
					tmp.txtNationalTeam='[[' ..  getLabelByEntity( tmp.iTeam ) .. '|' .. tmp.txtCountry .. ']]'
					tmp=addNationalTeamwithAgeandReserve(tmp,'')
					table.insert(all,tmp)
					end
				if (txtTypeofTeam=='both') then
					tmp=tblSeasonData(frame,tmp,value,entityid)
					if isNationalTeam(tmp.iTeam,'P31') then
						tmp=addNationalTeamwithAgeandReserve(tmp,'')
						tmp.bNationalTeam=true
						else
						tmp.bNationalTeam=false
					end
					-- Add if is a sports result (tblSeasonData will set iStatus to 99 if it is not a sportsresult, as described in its documentation in module "sportdata")
					if (not (tmp.iStatus==99)) then
						table.insert(all,tmp)
						end
					end
				end
			end
	    end 
	return all
end

-- Fills in the country/state an athlete competes for.
-- A reasonably large number of regions compete in international competitons without
-- being independent states (such as England, Scotland, Wales, Northern Ireland, Puerto Rico etc.)
-- Wikidata has a special property (P1532, country for sport) to handle such cases
-- This function therefore first read from there and if nothing is found use P17 (country)
function txtSportsCountry(iTeam)
	txtSportcountry=readFirstStatement(iTeam,'P1532')
	if (txtSportcountry==nil) then
		txtSportcountry=readFirstStatement(iTeam,'P17')
	end
	return txtSportcountry
end

function individualresults (frame,entityid)
	-- get all teams the person has played with (according to P54)
	local all=tblResults(frame,entityid,'individual','none')
	--Sort them based on date
    table.sort(all, function(a, b) return 
    	(a.txtDateTo < b.txtDateTo) or
    	(a.txtDateTo == b.txtDateTo and a.txtDateFrom < b.txtDateFrom)
    end)
	--Start creaing a table
	local txt='<table style="class: biography vcard" width="100%"><tr><th width="20px">' .. txtPositionHeader .. '</th><th>' .. txtCompetitionHeader .. '</th><th width="100px">' .. txtSeasonHeader .. '</th></tr>'
	txtTeamOld=''
	for i = 1,#all do
		if (all[i].txtTeam~=txtTeamOld) then
			local txtTeam=all[i].txtTeam
			if (all[i].txtCountry) then
				txtTeam=frame:expandTemplate{ title = txtFlagIconTemplate , args={all[i].txtCountry,storlek='16px'}} .. ' ' .. txtTeam
				end
			txt=txt .. '<tr ' .. txtTeamHeaderStyle .. '><td colspan="3"><b>' .. txtTeam .. '</b></td></tr>'
			txtTeamOld=all[i].txtTeam
			end
		txt=txt .. "<tr>" .. txtPosition(all[i].iPosition)
		txtTmp=mw.wikibase.getSitelink(all[i].iSeason )
		if not (txtTmp) then
			txtTmp=all[i].txtSeason
			else
			txtTmp='[['..txtTmp .. '|' .. all[i].txtSeason  .. ']] ' 
		end			
		txtSeasonTxt= txtTmp  .. txtUnpackReference(frame,all[i].hasref,all[i].ref) .. all[i].edit
		if (all[i].iStatus==1) then
			txt=txt .. '<td>' .. all[i].txtLeague  .. '</td>'
			txt=txt .. '<td>' .. txtSeasonTxt .. '</td>' 
			end
		if (all[i].iStatus==2) then
			txt=txt .. '<td colspan="2">' .. all[i].txtLeague  ..  txtSeasonTxt .. '</td>' 
			end
		if (all[i].iStatus==3) then
			txt=txt .. '<td colspan="2">' .. txtSeasonTxt .. '</td>' 
			end
		txt=txt .. '</tr>'
    end
	txt=txt .. '</table>'
	return #all>0,txt
end


function teamresults (frame,entityid)
	-- get all teams the person has played with (according to P54)
	local all=tblResults(frame,entityid,'club','P54')
	--Sort them based on date
    table.sort(all, function(a, b) return 
    	(a.txtDateTo < b.txtDateTo) or
    	(a.txtDateTo == b.txtDateTo and a.txtDateFrom < b.txtDateFrom) or
    	(a.txtDateTo == b.txtDateTo and a.txtDateFrom == b.txtDateFrom and a.iLeague < b.iLeague)
    end)
    -- The following piece of code loops through the results and checks it for cases where the player has played for more than one club the same season
    -- If so it moves results for the team it played for the last season first (that is the plan, so far the code is much simpler)
	for i = 2,#all-1 do
		-- Two results for the same season?
		if (all[i].txtSeason==all[i+1].txtSeason) then
			-- Different teams and the latter one is the same as the player played for the season before?
			if ((all[i-1].iTeam==all[i+1].iTeam) and not (all[i-1].txtSeason==all[i+1].txtSeason)) then
				-- Let them change place
				tmp=all[i];
				all[i]=all[i+1];
				all[i+1]=tmp;
				end
			end
		end

	--Start creaing a table
	local txt='<table style="class: biography vcard" width="100%"><tr><th width="20px">' .. txtPositionHeader .. '</th><th>' .. txtCompetitionHeader .. '</th><th width="100px">' .. txtSeasonHeader .. '</th></tr>'
	txtTeamOld=''
	for i = 1,#all do
		if (all[i].txtTeam~=txtTeamOld) then
			local txtTeam=all[i].txtTeam
			if (all[i].txtCountry) then
				txtTeam=frame:expandTemplate{ title = txtFlagIconTemplate , args={all[i].txtCountry,storlek='16px'}} .. ' ' .. txtTeam
				end
			txt=txt .. '<tr ' .. txtTeamHeaderStyle .. '><td colspan="3"><b>' .. txtTeam .. '</b></td></tr>'
			txtTeamOld=all[i].txtTeam
			end
		txt=txt .. "<tr>" .. txtPosition(all[i].iPosition)
		txtTmp=mw.wikibase.getSitelink(all[i].iSeason )
		if not (txtTmp) then
			txtTmp=all[i].txtSeason
			else
			txtTmp='[['..txtTmp .. '|' .. all[i].txtSeason  .. ']] ' 
		end			
		txtSeasonTxt= txtTmp  .. txtUnpackReference(frame,all[i].hasref,all[i].ref) .. all[i].edit
		if (all[i].iStatus==1) then
			txt=txt .. '<td>' .. all[i].txtLeague  .. '</td>'
			txt=txt .. '<td>' .. txtSeasonTxt .. '</td>' 
			end
		if (all[i].iStatus==2) then
			txt=txt .. '<td colspan="2">' .. all[i].txtLeague  ..  txtSeasonTxt .. '</td>' 
			end
		if (all[i].iStatus==3) then
			txt=txt .. '<td colspan="2">' .. txtSeasonTxt .. '</td>' 
			end
		txt=txt .. '</tr>'
    end
	txt=txt .. '</table>'
	return #all>0,txt
end

function nationalteamresults (frame,entityid)
	local all=tblResults(frame,entityid,'nationalteam','P54')
    table.sort(all, function(a, b) return 
		a.iCompetionRank < b.iCompetionRank or 
    	(a.iCompetionRank == b.iCompetionRank and a.txtLeague < b.txtLeague) or 
    	(a.iCompetionRank == b.iCompetionRank and a.txtLeague==b.txtLeague and a.txtDateTo < b.txtDateTo) or 
    	(a.iCompetionRank == b.iCompetionRank and a.txtLeague==b.txtLeague and a.txtDateTo == b.txtDateTo and a.txtDateFrom < b.txtDateFrom) 
    	end)
	local txt='<table style="class: biography vcard" width="100%"><tr><th width="30px">' .. txtPositionHeader .. '</th><th>'..txtNationalTeamHeader..'</th><th>' .. txtSeasonHeader .. '</th></tr>'
	txtCompetitionOld=''
	for i = 1,#all do
		if (all[i].txtLeague~=txtCompetitionOld) then
			txt=txt .. '<tr ' .. txtTeamHeaderStyle .. '><td colspan="3"><b>' .. all[i].txtLeague .. '</b></td></tr>'
			txtCompetitionOld=all[i].txtLeague
			end
		txt=txt .. '<tr>' .. txtPosition(all[i].iPosition) .. '<td>' .. all[i].txtNationalTeam  .. '</td>'
		txtTmp=mw.wikibase.getSitelink(all[i].iSeason )
		if not (txtTmp) then
			txtTmp=all[i].txtSeason
			else
			txtTmp='[['..txtTmp .. '|' .. all[i].txtSeason  .. ']] ' 
		end			
		txt=txt .. '<td>'..txtTmp  .. txtUnpackReference(frame,all[i].hasref,all[i].ref) .. all[i].edit .. '</td>' .. '</tr>'
    end
	txt=txt .. '</table>'
	return #all>0,txt
end

function txtGender(idTeam)
	-- Read property 'competition class'
	claimsCompetitionClass = mw.wikibase.getBestStatements(idTeam, 'P2094' )
	-- If had value ..
	if next(claimsCompetitionClass) then
		-- .. read the value
    	local idCompetitionClass = read(claimsCompetitionClass[1],'id')
    	-- for the competition class check what it is underclass to
		claimsGender = mw.wikibase.getBestStatements(idCompetitionClass, 'P279' ) -- Subclass
		-- loop through the claims to check if it is either women's or men's sport.
	    for key, value in pairs( claimsGender ) do
    		idGender = read(value,'id')
    		-- Is it women's sport?
			if (idGender=='Q920057') then
				return '[[' .. txtImage .. ':Venus symbol (heavy pink).svg]]'
				end
    		-- Is it men's sport?
			if (idGender=='Q35555522') then
				return '[[' .. txtImage .. ':Male symbol (heavy blue).svg]]'
			end
	    end
	end
	return ''		-- If nothing found return empty text (no symbol will be shown)
end

-- Fill in age group for (junior) national teams
function addNationalTeamwithAgeandReserve(tbl,txtGenderSymbol)
	claimsInstanceOf = mw.wikibase.getBestStatements(tbl.iTeam, 'P31' )
	bIsReserve=false
    for key, value in pairs( claimsInstanceOf ) do
		if (read(value,'id') == 'Q45053817') then bIsReserve=true end
	end

	tbl.txtCountry = txtSportsCountry(tbl.iTeam)
	txtSitelink=mw.wikibase.getSitelink(tbl.iTeam)
	if not (txtSitelink) then
		txtSitelink=getLabelByEntity(tbl.iTeam)
		end

	claimsAge = mw.wikibase.getBestStatements(tbl.iTeam, 'P4135' )
	--If P4135 (max age) set
	if next(claimsAge) then
		-- Read first value (should only have one value)
		tbl.age= string.sub(read(claimsAge[1],'amount'),2,-1)
		tbl.txtNationalTeam='[[' ..  txtSitelink .. '|' .. tbl.txtCountry .. ' (U' .. tbl.age .. ')]]' .. txtGenderSymbol
--		tbl.txtNationalTeam='[[' ..  getLabelByEntity( tbl.iTeam ) .. '|' .. tbl.txtCountry .. ' (U' .. wdAge .. ')]]' .. txtGenderSymbol
		else
		-- If no max age assume it is the senior national team
		tbl.age='9999'
		if (bIsReserve) then
			tbl.txtNationalTeam='[[' ..  txtSitelink .. '|' .. tbl.txtCountry .. ' (' .. txtReserveLabel .. ')]]' .. txtGenderSymbol
			else
			tbl.txtNationalTeam='[[' ..  txtSitelink .. '|' .. tbl.txtCountry .. ']]'.. txtGenderSymbol
			end
--		tbl.txtNationalTeam='[[' ..  getLabelByEntity( tbl.iTeam ) .. '|' .. tbl.txtCountry .. ']]'.. txtGenderSymbol
	end
	return tbl
end

-- from: https://stackoverflow.com/questions/2421695/first-character-uppercase-lua
-- Works only for letters in the standard laatin alphabet
function firstToUpper(str)
	if (str) then
	    return (str:gsub("^%l", string.upper))
	    else
	    return ''
	    end
end

return p