Jarekt added a comment.

Ok, lets look at the whole code for fetching label:

	-- try easy way to get label (visible part of the link)
	if not entity then
		label, language = mw.wikibase.getLabelWithLang( item )
		if lang~=language then
			label = nil -- does not match desired language so lets nuke it
		end
	end
	
	-- hard way to get label
	if not label then
		entity = entity or mw.wikibase.getEntity(item); 
		for i, language in ipairs(langList) do 
			label = entity:getLabel(language)
			if label then break end -- label found and we are done
		end
	end
	if not label then -- no labels found so just show the q-code
		label = item
	end



  1. The function can be called either with item (from templates) or with entity (possibly from other lua codes). If we already have entity than we skip the 1st IF block and go directly to 2nd one as there is no need to call Wikidata again.
  2. In the 2nd block we have the loop over languages in the fallback list so if you ask for "zh" but we do not have it than you will get "en", or other label in the language on the fallback list. I assume that is equivalent to what you would find in getLabelWithLang
  3. If everything else fails the label will be the q-code
  4. 1st IF block can be done better as instead of lang~=language we should check if language is on the langList fallback list. That should result in fewer cases going to the 2nd IF block. I will fix that.

If there are other improvements one can make, please let me know.


TASK DETAIL
https://phabricator.wikimedia.org/T173194

EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Jarekt
Cc: Izno, daniel, Multichill, Aklapper, Ricordisamoa, JeanFred, Jarekt, ValterVB, Elitre, Jheald, Daniel_Mietchen, Nemo_bis, Aschroet, zhuyifei1999, Steinsplitter, Matanya, RP88, El_Grafo, Revent, Sjoerddebruin, Jane023, Susannaanas, Mike_Peel, Lydia_Pintscher, Micru, intracer, Poyekhali, Nizil, PokestarFan, hoo, E1presidente, Ramsey-WMF, Jmmuguerza, SandraF_WMF, GoranSMilovanovic, QZanden, Acer, Vali.matei, Volker_E, Wong128hk, Wikidata-bugs, PKM, Base, matthiasmullie, aude, GWicke, Fabrice_Florin, Raymond, Mbch331, Jay8g
_______________________________________________
Wikidata-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs

Reply via email to